Showing posts with label WebDriver. Show all posts
Showing posts with label WebDriver. Show all posts

Tuesday, March 12, 2019

Data provider in TestNG

 package muttu.test;  
 import org.testng.annotations.DataProvider;  
 import org.testng.annotations.Test;  
 public class DataProviderDemo {  
      @DataProvider(name = "LoginDeatls")  
      public Object[][] getUserDetails() {  
           return new Object[][] { { "uName1", "pwd1" }, { "uName2", "pwd2" } };  
      }  
      @Test(dataProvider = "LoginDeatls")  
      public void Login(String name, String password) {  
           System.out.println(name);  
           System.out.println(password);  
      }  
 }  

Run failed test cases in Java


Create a class that fails test case


 package testNG;  
 import org.testng.Assert;  
 import org.testng.annotations.Test;  
 public class TestFailClass {  
      @Test(retryAnalyzer=MyRetry.class)  
      public void failMethod(){  
           System.out.println("FAILED CLASS");  
           Assert.assertTrue(false);  
      }  
 }  

Create a class that re-runs the failed test cases

 package testNG;  
 import java.util.ArrayList;  
 import java.util.List;  
 import org.testng.TestNG;  
 public class RunFailed {  
      public static void main(String[] args) {  
           TestNG testRunner = new TestNG();  
           List<String> failedXmls = new ArrayList<String>();  
           //Enter the full path for the 'test-faailed.xml' file  
           failedXmls.add("C:/Users/Mutturaj.h/workspace/hulagabal/test-output/testng-failed.xml");  
           testRunner.setTestSuites(failedXmls);  
           testRunner.run();  
      }  
 }