我的目标:
由于有许多功能文件将使用一些常见步骤,我想为所有功能文件创建可重用的公共步骤定义类。
我的代码:
Common Step Class
public class CommonStep {
static WebDriver driver;
public CommonStep(WebDriver driver) {
CommonStep.driver = driver;
}
@Given("^I login to XXXXXX window title \"([^\"]*)\"$")
public boolean cadLogin(String winTitle){
return driver.getTitle().contains(winTitle);
}
@When("^I enter \"([^\"]*)\" into search box$")
public void search_Screen(String cntrl){
driver.findElement(By.id("idNEXT_SCRN")).clear();
driver.findElement(By.id("idNEXT_SCRN")).sendKeys(cntrl);
}
@And("^I click Go button for search MERCH screen$")
public void btnGo(){
driver.findElement(By.id("idGO_IND_1")).click();
}
@Then("^I navigate to a new window with window title \"([^\"]*)\"$")
public boolean navToScreen(String winTitle) {
return driver.getTitle().contains(winTitle);
}
public static void setDriver(WebDriver driver) {
CommonStep.driver = driver;
}
特定步骤类
public class MerchCreationStep {
static WebDriver driver;
private CommonStep commonStep;
private MerchPage merchPage;
private Merc2Page merc2Page;
private Merc3Page merc3Page;
private Merc4Page merc4Page;
private LoginPage loginPage;
@And("^I enter \"(\\d)\" letters of DBA Name$")
public void inpDBA_NAME(int num) {
merchPage.inpDBA_NAMEStr(num);
}
......
@When("^I click New Button$")
public void clickNew(){
merchPage.clickNew();
}
@Before
public void startUp() {
System.setProperty("webdriver.chrome.bin", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver();
commonStep = new CommonStep(driver);
loginPage = new LoginPage(driver);
merchPage = new MerchPage(driver);
merc2Page = new Merc2Page(driver);
merc3Page = new Merc3Page(driver);
merc4Page = new Merc4Page(driver);
driver.get("http://172.16.1.68:8080/XXXXXX/servlet/app");
try {
Thread.sleep(1000);
} catch(InterruptedException e){
// TO DO Auto-generated catch block
e.printStackTrace();
}
Utility.switchToWindow("XXXXXXX- User Logon [LOGON]", driver);
try{
Thread.sleep(2000);
} catch(InterruptedException e){
// TO DO Auto-generated catch block
e.printStackTrace();
}
loginPage.inpBankStr("01");
loginPage.inpEmpStr("200006");
loginPage.inpPwdStr("Ajay123456");
loginPage.clickResetBtn();
loginPage.inpPwdStr("Ajay123456");
loginPage.clickLoginBtn();
}
@After
public void shutDown() {
driver.quit();
}
功能文件: @Merch_Creation
@Merch_Creation
Feature: Merchant Creation
Scenario: Merchant Creation
**Given I login to XXXXXXX window title "XXXXXX- Main System Menu [MENU]"
When I enter "MERCH" into search box
And I click Go button for search MERCH screen
Then I navigate to a new window with window title "XXXXXX- Merchant Details Screen 1 [MERCH]"**
And I enter "5" letters of DBA Name
And I enter "8" letters of DBA Address Line 1
And I enter "8" letters of DBA Address Line 2
And I enter "BRISBANE" in DBA City
And I select the option "NSW " as State Code
And I enter "1010" in Post Code
And I enter "AU" in Country Code
And I enter "9" digits Phone Number
And I select the option "1 " option as Statement
And I select the option "I " option as H.O./Individual
And I enter "V222233339" in Customer Number
And I enter 4 digits number "5499" in MCC
And I select the option "0300" as Branch
And I enter "MCMDVCVD" in Card Plans/Styles
And I tick the check box of Data Entry Mode
When I click New Button
**Then Navigated to window "XXXXXXX- Merchant Details Screen 2 [MERC2]"**
And I select the option "D " as Service Fee Freq
And I enter "1.9900" in Service Fee Rate
And I select the option "1 " as Payment Method
And I select the option "T " as Payment Aggregation
And I enter "15" digit as Settlement Acct
And I select the option "A " as Settlement Acct Link Code
And I enter "5" letters in Settlement Acct Name
And I select the option "A " as Min. Service Fee Code
And I tick the check box of Data Entry Mode on MERC2
And I click Update button
**Then I navigate to a new window with window title "XXXXXX- Merchant Details Screen 3 [MERC3]"**
**之前的功能是常见功能。
如何在特定定义类中使用这些公共步骤定义?有人可以给我一个关于这个的想法吗?当我给普通的stepdef一个构造函数。它给我一个关于Bean创建失败的错误。如果我不给普通的stepdef一个构造函数。它出现了关于NullPointerException
的错误
非常感谢你。