Selenium 我在通过XML运行testng代码时遇到空指针异常。但直接运行代码时工作正常

Selenium 我在通过XML运行testng代码时遇到空指针异常。但直接运行代码时工作正常,selenium,automation,testng,Selenium,Automation,Testng,代码正在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");

代码正在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 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>
suite.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>

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

  <?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>
<!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>

在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>
     <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

您的组标记的拼写错误。更改拼写并再次运行

  <?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>
<groups>
   <run>
      <include name="Car"/>
   </run>
</groups>


更改组的拼写。这可能是您出错的原因。请参考此问题,它将解决您的问题。组标记拼写错误。因此testng无法获取该类文件。请更改它,然后重试