TestNG

  • 26
    Mar

    Setting TestNG properties via Properties file

    Step 1: Create utility to read property file ——————————————— import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class PropertyFileExample { public static Properties myfunction() { Properties prop =...

    Read More
  • 26
    Mar

    Sample IMethodInterceptor implementation in TestNG

    import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import org.testng.IMethodInstance; import org.testng.IMethodInterceptor; import org.testng.ITestContext; import org.testng.annotations.Test; public class PriorityInterceptor implements IMethodInterceptor { @Override public List intercept(List methods,...

    Read More
  • 26
    Mar

    How to modify the TestNG annotation’s value at run-time

    Following code will never get executed import org.testng.annotations.Test; public class ExampleTestNG { @Test(enabled = false) public void invoke() { System.out.println(“Function invoked…..”); } } Output: ——- =============================================== Default suite Total...

    Read More
  • 26
    Mar

    Executing all tests of priority = 1 with TestNG

    TestNG allows to execute a specific priority function by means of custom implementation of “IMethodInterceptor” interface. Steps involved are: Step 1: Custom implementation of intercept method of IMethodInterceptor interface:...

    Read More
  • 25
    Mar

    Define testname in TestNG

    Following code snippet demonstrates how to name a test in TestNG import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; import org.testng.annotations.Test; public class TestNGClass { private static final Logger LOGGER =...

    Read More
  • 25
    Mar

    Difference between SkipException and timedSkipException in TestNG

    TestNG methods canbe marked as skipped by following code: @Test public void genericSkipException() { throw new SkipException(“This is to raise generic SkipException during TestNG execution”); } Output: ——- SKIPPED:...

    Read More
  • 25
    Mar

    TestNG test status codes

    TestNG test status codes are: int CREATED = -1; int SUCCESS = 1; int FAILURE = 2; int SKIP = 3; int SUCCESS_PERCENTAGE_FAILURE = 4; int STARTED= 16;

    Read More
  • 25
    Mar

    Generic function to read CSV file as an Array of Object[][] for TestNG

    Step 1: Create a csvUtilities library with following functions : —————————————————————- public class csvUtilities { public static String getCSVLineText(String fileName, int rowNo) { String csvRowData = null; int row...

    Read More
  • 19
    Mar

    TestNG methods parameterization by function returning object array

    Following code snippet demonstrate Dataprovider function returning Object. import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class MultipleGroups { // You must need to mention data provider method name in Test method...

    Read More
  • 19
    Mar

    How to pass parameter values of different primitive data types in testng.xml

    Following code snippet demonstrates how to pass primitive data type arguments to testng.xml Step 1: create TestNG methods, which accepts different primitive data types: —————————————————————————— import org.testng.annotations.Optional; import org.testng.annotations.Parameters;...

    Read More