为什么我的Cucumber步骤类没有打开Firefox浏览器?

时间:2017-04-12 14:41:53

标签: java selenium selenium-webdriver junit cucumber

为什么我的步骤文件没有打开Firefox浏览器?我已将步骤文件指向相关的geckdriver.exe

请参阅下面列出的步骤文件的代码:

public static WebDriver driver;

@Before
public void setUp() {
    driver = new FirefoxDriver();
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\userx\\Desktop\\CucumberFramework\\CucumberFramework\\src\\test\\java\\resources\\geckodriver.exe");
}

@After
public void tearDown() {
    driver.quit();
}

@Given("^I am on the home page https://www\\.carsguide\\.com\\.auof carguide website$")
public void i_am_on_the_home_page_https_www_carsguide_com_auof_carguide_website() throws Throwable {
    driver.get("https://www.carsguide.com.au/");
}

@When("^I move to Car For Sale Menu$")
public void i_move_to_Car_For_Sale_Menu() throws Throwable {
}

调用步骤文件的功能文件:

Feature File
 Feature: validation of car search page

 Scenario: Searching for a new car

 Given I am on the home page https://www.carsguide.com.auof carguide website
 When I move to Car For Sale Menu
 Then I click on Search Cars
 And I select Make as "BMW"
 And I select Model as "1SERIES"
 And I select location as "Australia"
 And I select price as "$10000"
 And I click on Find My Next Car button
 Then I should see list of searched cars
 And the page title be "Bmw 1 Series Cars Under 10000 for Sale | CarsGuide"

例外:

java.lang.NullPointerException
    at steps.CarSearchSteps.i_am_on_the_home_page_https_www_carsguide_com_auof_carguide_website(CarSearchSteps.java:30)
    at ✽.Given I am on the home page https://www.carsguide.com.auof carguide website(carSearch.feature:8)

2 个答案:

答案 0 :(得分:1)

你的@Before方法应该是

System.setProperty("webdriver.gecko.driver", "C:\\Users\\userx\\Desktop\\CucumberFramework\\CucumberFramework\\src\\test\\java\\resources\\geckodriver.exe");
driver = new FirefoxDriver();

如果问题没有解决,请告诉我。

答案 1 :(得分:1)

我现在已经解决了这个问题,我正在导入jUnit After和Before而不是以下内容:import cucumber.api.java.After; import cucumber.api.java.Before;