我正在尝试在两个不同的文件中执行步骤定义的黄瓜功能文件。第一步定义中的所有方法都被执行,当执行第二步时,它会启动一个新的浏览器实例,而不是继续现有的。
黄瓜功能文件场景:假设我打开 Firefox 并导航到 Guru 当我输入用户名和密码并登录到 guru 然后我点击新客户然后显示新客户页面我点击主页然后显示主页
第一步定义
package stepDefination;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import Pages.HomePage;
import Pages.NewCustomerPage;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class GuruStepDef {
WebDriver Driver;
NewCustomerPage customerPage;
HomePage homePage = new HomePage(Driver);
@When("^I enter UserName and Password and login to guru$")
public void I_enter_and_and_login_to_guru() {
homePage=homePage.setup();
homePage.navigateToWebApp();
}
@Then("^HomePage is displayed$")
public void Homepage_is_displayed() {
//assert
}
@Then("^I click on New Customer$")
public void I_click_on_New_Customer() {
customerPage= homePage.NavigateToCustomerPage();
}
@Then("^New Customer Page is displayed$")
public void New_Customer_Page_is_displayed() {
//assert
}
}
第二步定义
package stepDefination;
import org.openqa.selenium.WebDriver;
import Pages.HomePage;
import Pages.NewCustomerPage;
import cucumber.api.java.en.Then;
public class SmokeTest {
WebDriver Driver;
NewCustomerPage customerPage;
HomePage homePage = new HomePage(Driver);
@Then("^I click on HomePage$")
public void I_click_on_HomePage() {
homePage=customerPage.Manager();
}
}