多重测试 TestNG.xml 文件导致 java.lang.NullPointerException

发布于 2024-09-24 09:00:05 字数 1537 浏览 2 评论 0原文

多重测试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡绿茶香 2024-10-01 09:00:05

我没有看到任何实际初始化您的硒字段的代码,这是在哪里发生的?

无论它在哪里,请确保它在 @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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文