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{

   }

}
Emily
  • 3
  • 3
  • What error is thrown? – Bala Apr 01 '14 at 08: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 "" in the Keywords textbox And I enter "" 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 – Emily Apr 01 '14 at 19:25

1 Answers1

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);
}
nilesh
  • 14,131
  • 7
  • 65
  • 79
  • 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. – Emily Apr 04 '14 at 06:08