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