Javaでキュウリの工程のうち共有状態の実装

QAAuto:

私はと呼ばれる2つのページのオブジェクト持っているOrderSelectionとしますOrderDetailsまた、私が持っているSharedStateクラスとするOrderSelectionStepDefOrderDetailsStepDef私はのための2つの変数を宣言OrderSelectionしてOrderDetailsSharedStateしかし、彼らはのコンストラクタで初期化されませんSharedStateOrderSelectionStepDefOrderDetailsStepDefクラス、私は彼らのコンストラクタとパス宣言したSharedStateオブジェクトを。

public OrderSelectionStepDef(SharedState sharedState) {
  this.sharedState = sharedState;
}    
public OrderDetailsStepDef(SharedState sharedState) {
  this.sharedState = sharedState;
}

私は呼び出すとsharedState.orderDetailsOrderDetailsStepDefまたはスローされました。OrderSelectionStepDefNullPointerException

その後、私は初期化OrderSelectionOrderDetailsクラスが内のオブジェクトSharedStateのコンストラクタ。その後、問題が解決されました。しかし、キュウリピココンテナのコンセプトを持つこの実装のokがあります?。

社会 :

ステップ1. OrderSelectionStepDef&OrderDetailsS​​tepDefは、以下のようになります(実装ごとに名前を変更してください)

/**
 * 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>

お役に立てれば。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=203976&siteId=1