0

我試圖與webdriver一起工作,看看黃瓜是否會用junit打開瀏覽器。除了打開網頁瀏覽器,甚至做我要求做的事情之外,它都認識到一切。以下是代碼片段:黃瓜Junit測試代碼

public class JobSearch { 
    WebDriver driver; 
     @Test 
     public void JobSearchSteps() 
     { 
     driver = new FirefoxDriver(); 
     driver.navigate().to("http://www.careerbuilder.com"); 
    } 
    @Given("^I am on the page Find Jobs$") 
    public void I_am_on_the_page_Find_Jobs()throws Throwable{ 
     System.out.println("******************************"); 
     System.out.println("@Given -- I am on the page Find Jobs"); 
    } 
    @When("^I enter \"([a-zA-Z]{1,})\" in the Keywords textbox$") 
    public void I_enter_QA_in_the_Keywords_textbox(String Job){ 
     driver.findElement(By.id("s_rawwords")).sendKeys(Job); 
     System.out.println("The search is "+Job); 

    } 
    @And("^I enter\"([a-zA-Z]{1,})\" in the Location textbox$") 
    public void I_enter_my_location_in_the_Location_textbox(String Loc)throws Throwable{ 
     System.out.println("The location is "+ Loc); 
     driver.findElement(By.id("s_freeloc")).sendKeys(Loc); 

    } 


    @And ("^I Select\"([a-zA-Z]{1,})\" from the Careers Category List$") 
    public void I_Select_from_the_Careers_Category_List(String Option)throws Throwable{ 
     WebElement ListBox =driver.findElement(By.id("s_jobtypes")); 
     List options = ListBox.findElements(By.tagName(Option)); 
    } 
    @And ("^I click the button Find Jobs$") 
    public void I_click_the_button_Find_Jobs()throws Throwable{ 
     driver.findElement(By.id("qsbButton")).click(); 

    } 
    @Then("^the page Jobs should be shown$") 
    public void the_page_Jos_should_be_shown()throws Throwable{ 

    } 

} 
+0

什麼引發錯誤? – Bala

+0

org.openqa.selenium.WebDriverException:f.QueryInterface不是一個函數。特點:職位搜索 爲了得到一份工作 作爲QA 我需要尋找它 場景:搜尋工作 鑑於我在頁面上搜索職位 當我在關鍵詞文本 我輸入「」在位置文本框中輸入「」 而我從職業類別列表中選擇「信息技術」 然後我單擊按鈕「查找職位」 然後頁面「職位」應該顯示 – Emily

回答

1

你不能Cucumber註釋結合Junit註解。我建議你刪除@Test註釋。你應該寫一個步驟來啓動網站並實施它。例如把這個在您的場景的頂部,

Given I navigate to "http://www.careerbuilder.com"

這將轉化爲一個步一樣,

@Given("^I navigate to \"([^\"]*)\"$") 
public void I_navigate_to_site(String url) throws Throwable { 
    driver = new FirefoxDriver(); 
    driver.navigate().to(url); 
} 
+0

感謝球員,我替換爲Nilesh聲明這是導航到網站,我做了其他更改,並得到它的工作。再一次,這真的很有幫助。 – Emily

+0

@ user3482797很高興幫助。那麼請你接受答案嗎? – nilesh