TestNG には非常に不快な問題が 1 つあります。割り当てたグループを使用していくつかのテストを起動しようとすると、NullPointerException が発生します。
テストの例:
public class DemonstrationTest01 extends FundamentalTest {
private static final String LOGIN = "Fruzenshtein";
private static final String PASSWORD = "111111";
@Test(priority=1, groups="foo")
public void test01() throws InterruptedException {
basePage.logIn(LOGIN, PASSWORD)
.checkTextPresent("Welcome, "+LOGIN+"!")
.clickSiteLogo()
.checkTextPresent("Welcome, "+LOGIN+"!")
.logOut();
}
}
2 番目のテスト:
public class DemonstrationTest03 extends FundamentalTest {
@Test(priority=1, groups="foo")
public void test03() throws InterruptedException {
ProductPage productPage = basePage.navToCategory("Homewear")
.checkCategoryTitle("Mugs")
.navToProductPage(2)
.checkTextPresent("0 items")
.addToCart()
.checkTextPresent("1 items");
Assert.assertEquals(basePage.getShoppingCartTotal(), productPage.getProductPrice());
productPage.addToCart()
.checkTextPresent("2 items");
Assert.assertEquals(basePage.getShoppingCartTotal(), 2*productPage.getProductPrice());
}
}
以下は FundamentalTest です。
public class FundamentalTest {
protected BasePage basePage;
@BeforeClass
@Parameters({ "testServer" })
public void init(String testServer) {
basePage = PageFactory.initElements(new FirefoxDriver(), BasePage.class);
basePage.driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
basePage.driver.get(testServer);
}
@AfterClass
public void destruct() throws InterruptedException {
Thread.sleep(5000);
basePage.driver.close();
}
}
そして最後に私のxmlランチャー:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SingleTestSuite" >
<parameter name="testServer" value="https://shop.shakhtar.com/en/"/>
<test name="StandAloneTest">
<groups>
<run>
<include name="foo"></include>
</run>
</groups>
<packages>
<package name="com.shakhtar.qa.tests" />
</packages>
</test>
</suite>
NullPointerException の原因は何ですか? どうすれば修正できますか?ここに私のプロジェクトへのリンクがあります。