0

Selenium webdriver と testng で Page オブジェクト パターンを使用しています。あるページ オブジェクト クラスのインスタンスに、複数の<test>.

例えば

 <test name="Login scenario">
    <classes>
        <class name="sanitytests.LoginTests">
         <methods>
            <include name="validLogin"/>
         </methods>
        </class>
    </classes>
</test> 

  <test name="scenario2" preserve-order="true" parallel="false">
            <classes>
                 <class name="sanitytests.HomePageTests">
                 <methods>
                    <include name="clickOnMyAccountFromHome"/>
                 </methods>
                </class>
            </classes>
  </test> 

LoginTests クラスで、homePage クラスのインスタンスを使用しています

@Test()
    public void validLogin(ITestContext context) throws Exception {

    loginPage.loginDetails(username,password);
    homePage = loginPage.loginAsValidUser();
    context.setAttribute("homePage",homePage);

    }

私の HomePageTests クラス

@Test()
    public void clickOnMyAccountFromHome(ITestContext context) throws Exception {
        homePage = (HomePage) context.getAttribute("homePage");
        myAccountPage = homePage.navigateToMyAccountPage();
        context.setAttribute("myAccountPage", myAccountPage);

    }

ItestContextテスト間ではなくメソッド間でパラメーターを共有するために使用されるため、null ポインター例外が発生しています。代替手段はありますか?

4

2 に答える 2

1

「ITestContext」について読んだことから、それはTestNGクラス/オブジェクト/メソッドに関連しています。HomePage を静的として作成すると、スイートの実行全体で使用できます。

于 2013-09-12T07:12:29.083 に答える
0

ページ オブジェクト パターンには、オブジェクトを一度しか作成できないとは記載されていません。各テストで新しいインスタンスを作成します。

于 2013-09-13T07:29:17.327 に答える