Мой файл функций - search.feature.И есть два файла с пошаговыми определениями: Backgroundstepdef и Searchstepdef.Я должен использовать статус Backgroundstepdef в Searchstepdef.Как я могу использовать статус шагов в Backgroundstepdef с помощью DI-инъекции?
Я написал класс SharedContext, который расширяет picofactory.
search.feature, как показано ниже:
Feature: Test Search page using search textbox also using filter and sort
@login
Background: User is Logged In
Given User navigate to the login page
When User submit username "tahashin.egp@outlook.com" and password "123456"
Then User will click Sign In button
And User will see Account menu
Then User will enter text "Honey"
Scenario: Searching with name of honey
Given User is Suceesfully loged in
Given User will enter text "honey"
And User will see press enter or click search button
Then User will see the list of honey
Scenario: Search with invalid data
Given User will enter invalid text
And User will press enter or click serach icon
Then User will see the message invalid search
==============================================================================
Backgroundstepdef ниже:
public class BackgroundStepDef {
WebDriver driver;
LoginPage loginPage;
String afterSignIn;
private SharedContext sharedContext;
//HelperClass helper;
//constructor for picocontainer DI Injection
public BackgroundStepDef(SharedContext sharedContext){
this.sharedContext=sharedContext;
}
@Given("^User navigate to the login page$")
public void userNavigateToTheLoginPage() throws Throwable {
// Write code here that turns the phrase above into concrete actions
//driver=HelperClass.initializeDriver();
//loginPage=new LoginPage();
driver=sharedContext.driver;
loginPage= PageGenerator.GetInstance(LoginPage.class,driver);
}
@When("^User submit username \"([^\"]*)\" and password \"([^\"]*)\"$")
public void userSubmitUsernameAndPassword(String username, String
password) throws Throwable {
// Write code here that turns the phrase above into concrete actions
loginPage.enterUserName(username);
loginPage.enterPassword(password);
}
@Then("^User will click Sign In button$")
public void userWillClickSignInButton() throws Throwable {
// Write code here that turns the phrase above into concrete actions
loginPage.enterSignIn();
Thread.sleep(3000);
}
@And("^User will see Account menu$")
public void userWillSeeAccountMenu() throws Throwable {
// Write code here that turns the phrase above into concrete actions
afterSignIn=loginPage.verifylinkText();
}
}
====================================================================== searchstepdef, как показано ниже:
public class SearchSteps {
WebDriver driver;
SearchPage serachPage;
String afterSignIn;
SharedContext sharedContext;
public SearchSteps(SharedContext sharedContext){
this.sharedContext=sharedContext;
}
@Given("^User is Suceesfully loged in$")
public void userIsSuceesfullyLogedIn() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Given("^User will enter text \"([^\"]*)\"$")
public void enterSearchText(String text){
//driver=HelperClass.initializeDriver();
//serachPage=new SearchPage();
serachPage=PageGenerator.GetInstance(SearchPage.class,driver);
serachPage.enterSearchtext("prubita");
}
@And("^User will see press enter or click search button$")
public void userWillSeePressEnterOrClickSearchButton() throws Throwable {
// Write code here that turns the phrase above into concrete actions
serachPage.pressEnter();
}
@Then("^User will see the list of honey$")
public void userWillSeeTheListOfHoney() throws Throwable {
// Write code here that turns the phrase above into concrete actions
}
@Given("^User will enter invalid text$")
public void userWillEnterInvalidText() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@And("^User will press enter or click serach icon$")
public void userWillPressEnterOrClickSerachIcon() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^User will see the message invalid search$")
public void userWillSeeTheMessageInvalidSearch() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
}
SharedContext как показано ниже:
package hgtest.utils;
public class SharedContext extends PicoFactory {
public WebDriver driver;
public Scenario scenario;
public String stepInfo;
public String scenarioName;
public String tagname;
public String getScenarioname(){
scenarioName=scenario.getName();
return scenarioName;
}
public SharedContext(){
addClass(BackgroundStepDef.class);
addClass(SearchSteps.class);
}
}
cuumber.properties cucumber.api.java.ObjectFactory = hgtest.utils.SharedContext
Как мое понимание Использование класса SharedContextя могу получить статус Backgroundstepsdef в Searchstepsdef