如何在testNG中使用组

时间:2019-05-19 16:51:43

标签: selenium testng

我正在testng测试套件中实现组。当我运行testng套件套件时,它仅运行'FireFox'测试,并且将标记放入'Firefox'测试中             它会运行“ IE”测试。请让我知道这可能是什么原因?

             

         <groups>
         <run>
         <include = "smoke"/>
         </run>
         </groups>
                  <classes>

                          <class name = "com.asw.beginner.tests.NewTest"/>
                 </classes>
         </test>

         <test name = "FireFox" allow-return-values = "true">
         <parameter name = "browser" value = "FF"/>


         <classes>
         <class name = "com.asw.beginner.tests.NewTest"/>
         </classes>
        </test>

2 个答案:

答案 0 :(得分:0)

定义您的测试,如下所示:

public class Test1 {
  @Test(groups = { "functest" })
  public void testMethod1() {
  }

  @Test(groups = {"functest", "checkintest"} )
  public void testMethod2() {
  }

  @Test(groups = { "checkintest" })
  public void testMethod3() {
  }
}

然后您可以按以下方式使用xml文件

<test name="Test1">
  <groups>
    <run>
      <include name="functest"/>
    </run>
  </groups>
  <classes>
    <class name="example1.Test1"/>
  </classes>
</test>
  

以上测试将仅在具有functest组的情况下运行该方法。

您可以从Official testng documatation

了解更多有关testng的信息。

答案 1 :(得分:0)

下面是示例Java代码

import org.testng.Assert; import org.testng.annotations.Test;

public class GroupTestExample {    String message = ".com";    MessageUtil messageUtil = new MessageUtil(message);

   @Test(groups = { "functest", "checkintest" })
       public void testPrintMessage() {
      System.out.println("Inside testPrintMessage()");
      message = ".com";
      Assert.assertEquals(message, messageUtil.printMessage());    }

   @Test(groups = { "checkintest" })
       public void testSalutationMessage() {
      System.out.println("Inside testSalutationMessage()");
      message = "tutorialspoint" + ".com";
      Assert.assertEquals(message, messageUtil.salutationMessage());    }

   @Test(groups = { "functest" })
       public void testingExitMessage() {
      System.out.println("Inside testExitMessage()");
      message = "www." + "tutorialspoint"+".com";
      Assert.assertEquals(message, messageUtil.exitMessage());    }   }

下面是Testng.xml文件

  

     

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

  <classes>
     <class name = "GroupTestExample" />
  </classes>
   </test> </suite>