Unable to skip passed test cases and test only failed test case in testNG

问题: I'm trying to automate a website testing using testNG. Let assume I have created 3 test cases one for each webpage(although there are more than 50 test cases in my case...

问题:

I'm trying to automate a website testing using testNG.

Let assume I have created 3 test cases one for each webpage(although there are more than 50 test cases in my case but just for simplifying the issue I have considered 3 only).

Now, my starting 2 test cases are passing but my 3rd test case is getting failed. I am making the code change to that 3rd page and I want just to run that 3rd test case but when I am running my code, everytime new IE driver instance is getting created and testing starts from beginning.

How to use existing driver instance and test the 3rd webpage only. I tried googling this out but couldn't find anything useful.

Any help would be appreciated.


回答1:

If you want to ignore particular test, you can use this snippet:

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");
   }
}

When you execute this class, it will be only second test executed. I don't know if you have stored all 50 tests in one class(hopefully not), but if yes, there is a possibility to group your tests. To be able to do this you can use this sample:

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()");
   }  
}

then xml file would be like this:

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

then after compiling your test classes, use this command:

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

More explained information you will get in this tutorials:

  • 发表于 2018-07-09 09:42
  • 阅读 ( 321 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除