【问题标题】:I am getting null pointer exception while running testng code through XML.But when running code directly its working fine我在通过 XML 运行 testng 代码时遇到空指针异常。但是当直接运行代码时它工作正常
【发布时间】:2017-03-22 03:27:09
【问题描述】:

代码在 TESTNG 中分组

 package testNG_annot;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; 

    public class TestNG_grp1
     {
      @BeforeMethod
      public void CarBM() {
                System.out.println("CarBM");
            }
        ***  // Created group car and Two wheeler//***
            @Test(groups = { "Car" })
            public void Sedan1() {
                System.out.println("Test1-Verna");
            }

            @Test(groups = { "Car" })
            public void Sedan2() {
                System.out.println("Test2-BMW");
            }

            @Test(groups = { "TwoWheeler" })
            public void Scooter1() {
                System.out.println("Test3-ScootyPep");
            }

            @Test(groups = { "TwoWheeler" })
            public void aScooter2() {
                System.out.println("Test4-TVS");
            }
           }

套件.xml

  <?xml version="1.0" encoding="UTF-8"?> 
  <suite name="grp11"> 
    <test name="group1"> 
      <gropus> 
        <run> 
          <include name="Car"/> 
        </run> 
      </gropus> 
      <classes> 
        <class name="testNG_annot.TestNG_grp1"/> 
      </classes> 
    </test> 
  </suite>

【问题讨论】:

标签: selenium automation testng


【解决方案1】:

groups 标签的拼写错误。更改拼写并再次运行。

<groups>
   <run>
      <include name="Car"/>
   </run>
</groups>

【讨论】:

    【解决方案2】:

    形成如下格式的 testng.xml 文件。将其作为 testng 测试运行,您将运行测试。

    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    <suite name="Suite1">
      <test name="Test" >
        <classes>
           <class name="testNG_annot.TestNG_grp1" />
        </classes>
      </test>
    </suite>
    

    【讨论】:

    • 组标签拼写错误。因此 testng 无法获取该类文件。更改并重试
    【解决方案3】:

    将此放在您的 xml 中的顶部

         <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-17
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      • 2012-03-01
      • 2016-01-01
      相关资源
      最近更新 更多