【问题标题】:Unable to skip passed test cases and test only failed test case in testNG无法跳过通过的测试用例并仅在 testNG 中测试失败的测试用例
【发布时间】:2018-07-07 05:56:25
【问题描述】:

我正在尝试使用 testNG 自动化网站测试。

假设我为每个网页创建了 3 个测试用例(虽然我的案例中有超过 50 个测试用例,但只是为了简化我只考虑 3 个的问题)。

现在,我开始的 2 个测试用例通过了,但我的第 3 个测试用例失败了。我正在对第 3 页进行代码更改,我只想运行第 3 个测试用例,但是当我运行我的代码时,每次创建新的 IE 驱动程序实例并从头开始测试。

如何使用现有的驱动程序实例并仅测试第三个网页。我试着用谷歌搜索,但找不到任何有用的东西。

任何帮助将不胜感激。

【问题讨论】:

  • 你能分享你的测试代码吗?
  • 嗨,请提供一些代码如何初始化 webdriver 和类正在使用它等等。所以帮助你

标签: java selenium selenium-webdriver automation testng


【解决方案1】:

如果你想忽略特定的测试,你可以使用这个 sn-p:

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

public class IgnoreTest {

   @Test(enabled = false) // this test will be ignored
   public void testPrintMessage() {
      System.out.println("This test is ignored");
   }

   @Test
   public void testSalutationMessage() { // this will be executed
      System.out.println("Test works");
   }
}

当你执行这个类时,它只会执行第二个测试。我不知道您是否已将所有 50 个测试存储在一个类中(希望没有),但如果是,则可以对您的测试进行分组。为了能够做到这一点,您可以使用此示例:

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

public class GroupTestExample {
   @Test(groups = { "functest", "checkintest" })
   public void testPrintMessage() {
      System.out.println("Inside testPrintMessage()");
   }

   @Test(groups = { "checkintest" })
   public void testSalutationMessage() {
      System.out.println("Inside testSalutationMessage()");
   }

   @Test(groups = { "functest" })
   public void testingExitMessage() {
      System.out.println("Inside testExitMessage()");
   }  
}

那么xml 文件会是这样的:

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

<suite name = "Suite1">
   <test name = "test1">

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

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

   </test>
</suite>

然后在编译你的测试类之后,使用这个命令:

C:\TestNG_WORKSPACE>java -cp "C:\TestNG_WORKSPACE" org.testng.TestNG testng.xml

您将在本教程中获得更多解释信息:

【讨论】:

    猜你喜欢
    • 2016-10-24
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    相关资源
    最近更新 更多