私はと呼ばれる2つのページのオブジェクト持っているOrderSelection
としますOrderDetails
。また、私が持っているSharedState
クラスとするOrderSelectionStepDef
とOrderDetailsStepDef
。私はのための2つの変数を宣言OrderSelection
してOrderDetails
でSharedState
。しかし、彼らはのコンストラクタで初期化されませんSharedState
。でOrderSelectionStepDef
とOrderDetailsStepDef
クラス、私は彼らのコンストラクタとパス宣言したSharedState
オブジェクトを。
public OrderSelectionStepDef(SharedState sharedState) {
this.sharedState = sharedState;
}
public OrderDetailsStepDef(SharedState sharedState) {
this.sharedState = sharedState;
}
私は呼び出すとsharedState.orderDetails
内OrderDetailsStepDef
またはスローされました。OrderSelectionStepDef
NullPointerException
その後、私は初期化OrderSelection
とOrderDetails
クラスが内のオブジェクトSharedState
のコンストラクタ。その後、問題が解決されました。しかし、キュウリピココンテナのコンセプトを持つこの実装のokがあります?。
ステップ1. OrderSelectionStepDef&OrderDetailsStepDefは、以下のようになります(実装ごとに名前を変更してください)
/**
* Step Definition implementation class for Cucumber Steps defined in Feature file
*/
public class HomePageSteps extends BaseSteps {
TestContext testContext;
public HomePageSteps(TestContext context) {
testContext = context;
}
@When("^User is on Brand Home Page (.+)$")
public void user_is_on_Brand_Home_Page(String siteName) throws InterruptedException {
homePage = new HomePage().launchBrandSite(siteName);
testContext.scenarioContext.setContext(Context.HOMEPAGE, homePage);
}
@Then("^Clicking on Sign In link shall take user to Sign In Page$")
public void clicking_on_Sign_In_link_shall_take_user_to_Sign_In_Page() {
homePage = (HomePage) testContext.scenarioContext.getContext(Context.HOMEPAGE);
signInPage = homePage.ecommSignInPageNavigation();
testContext.scenarioContext.setContext(Context.SIGNINPAGE, signInPage);
}
ご参考に
public class BaseSteps {
protected HomePage homePage;
protected PLPPage plpPage;
protected PDPPage pdpPage;
protected ShoppingBagPage shoppingBagPage;
protected ShippingPage shippingPage;
More implementation goes here.....
}
ステップ2.あなたの枠組みの下で2クラス下に追加してください -
まず、Javaファイル名- ScenarioContext.java
public class ScenarioContext {
private Map<String, Object> scenarioContext;
public ScenarioContext(){
scenarioContext = new HashMap<String, Object>();
}
public void setContext(Context key, Object value) {
scenarioContext.put(key.toString(), value);
}
public Object getContext(Context key){
return scenarioContext.get(key.toString());
}
public Boolean isContains(Context key){
return scenarioContext.containsKey(key.toString());
}
}
第二に、Javaファイル名- TestContext.java
public class TestContext {
public ScenarioContext scenarioContext;
public TestContext(){
scenarioContext = new ScenarioContext();
}
public ScenarioContext getScenarioContext() {
return scenarioContext;
}
}
ステップ3 POM依存関係 - picocontainerは、あなたのキュウリのバージョンごとにしなければなりません
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
</dependency>
お役に立てれば。