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{
}
}
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);
}