多重测试 TestNG.xml 文件导致 java.lang.NullPointerException
多重测试 TestNG.xml 文件导致 java.lang.NullPointerException
您好,质量团队,
我需要帮助让 TestNG 从一个 XML 文件运行多个测试。到目前为止,我所做的努力导致了 java.lang.NullPointerException 或测试 fake_execute="说它运行了...但是如果它没有启动 selenium,它如何运行?"
最后一点:所有测试都成功运行当使用独立的 XML 文件运行时,
下面是我的 XML 文件
<test name="Simple example">
<groups>
<run>
<include name="groupA" />
<include name="groupB" />
</run>
</groups>
<classes>
<class name="test.LoginPageTest"/>
<class name="test.PurchaseItemTest"/>
</classes>
</test>
</suite>
当 TestNG/Selenium 抛出空指针错误时,它总是在 selenium.open(URL)
、selenium.windowMaximize()
、selenium.windowFocus()
上失败。
我使用 SeleneseTestNGHelper 文件来启动 Selenium 并处理一些基本级别的 selenium 功能。
这是我的测试失败的测试命令
@Test (dataProvider = "Login_Test", groups = {"groupA"})
public void testLoginPage(String string1, String string2) throws Exception {
// Super-size & Focus on Selenium Test Window
//selenium.windowMaximize();
//selenium.windowFocus();
// Start your motors and get to testing
try { selenium.open("http://www.google.com"); }
catch(Throwable e)
{e.printStackTrace(); }
}
这是调用的方法
public void open(String string) {
selenium.open(string);
selenium.windowMaximize();
selenium.windowFocus();
}
Multi-Test TestNG.xml file results in java.lang.NullPointerException
Hello Quality Team,
I need help getting TestNG to run multiple tests from one XML file. So far my efforts to do this result in a java.lang.NullPointerException OR the test(s) fake_execute="says it ran...but how can it have run if it didn't start selenium?"
One final note: All of the tests run SUCCESSFULLY when run using a stand-alone XML file
Below is my XML file
<test name="Simple example">
<groups>
<run>
<include name="groupA" />
<include name="groupB" />
</run>
</groups>
<classes>
<class name="test.LoginPageTest"/>
<class name="test.PurchaseItemTest"/>
</classes>
</test>
</suite>
When TestNG/Selenium throws the Null Pointer Error it is always failing on a selenium.open(URL)
, selenium.windowMaximize()
, selenium.windowFocus()
.
I use a SeleneseTestNGHelper file that starts Selenium and handles some base-level selenium functionality.
Here is the command from the Test that my test is failing on
@Test (dataProvider = "Login_Test", groups = {"groupA"})
public void testLoginPage(String string1, String string2) throws Exception {
// Super-size & Focus on Selenium Test Window
//selenium.windowMaximize();
//selenium.windowFocus();
// Start your motors and get to testing
try { selenium.open("http://www.google.com"); }
catch(Throwable e)
{e.printStackTrace(); }
}
Here is the method called
public void open(String string) {
selenium.open(string);
selenium.windowMaximize();
selenium.windowFocus();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有看到任何实际初始化您的硒字段的代码,这是在哪里发生的?
无论它在哪里,请确保它在 @BeforeMethod 或 @BeforeClass 中初始化。
另外,这里还有一些相关文档:
http://testng.org/doc/selenium.html
I don't see any code that actually initializes your selenium field, where is this happening?
Wherever it is, make sure it's initialized in a @BeforeMethod or @BeforeClass.
Also, here is some relevant documentation:
http://testng.org/doc/selenium.html