Showing posts with label annotations. Show all posts
Showing posts with label annotations. 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);  
      }  
 }  

Retry failed test cases TestNG in Java


Create test cases which fails

 package testNG;  
 import org.testng.Assert;  
 import org.testng.annotations.Test;  
 public class TestFailClass {  
      @Test(retryAnalyzer=MyRetry.class)  
      public void failMethod(){  
           Assert.fail("Test failed");  
      }  
 }  

Create a retry class which implements IRetryAnalyzer interface like below which tries for 3 times

 package testNG;  
 import org.testng.IRetryAnalyzer;  
 import org.testng.ITestResult;  
 public class MyRetry implements IRetryAnalyzer {  
      private int retryCount = 0;  
      private static final int maxRetryCount = 3;  
      public boolean retry(ITestResult result) {  
           if (retryCount < maxRetryCount) {  
                retryCount++;  
                return true;  
           }  
           return false;  
      }  
 }