0

I tried to work with webdriver to see if the cucumber will open browser with junit. It is recognizing everything except for opening the web browser or even doing what I asked to do. Here is the code snippet:

    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{

   }

}
2
  • What error is thrown? Commented Apr 1, 2014 at 8:34
  • org.openqa.selenium.WebDriverException: f.QueryInterface is not a function. Feature: Job Search In order to get a job As a QA I need to search for it Scenario: Search Job Given I am on the page Find Jobs When I enter "<QA>" in the Keywords textbox And I enter "<NY>" in the Location textbox And I Select "Information Technology" from the Careers Category List And I click the button "Find Jobs" Then the page "Jobs" should be shown Commented Apr 1, 2014 at 19:25

1 Answer 1

2

You cannot combine Junit annotations with Cucumber annotations. I suggest you to remove @Test annotation. You should rather write a step to launch the site and implement it. For example put this at the top of your scenario,

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

This will translate to a step like,

@Given("^I navigate to \"([^\"]*)\"$")
public void I_navigate_to_site(String url) throws Throwable {
  driver = new FirefoxDriver();
  driver.navigate().to(url);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks guys, I replaced as Nilesh stated and it was navigating to site and I made other changes and got it to work. Once again, it was really helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.