Best Testng code snippet using org.testng.Interface IInvokedMethod
Source:InvokedMethodListenerInvoker.java
1package org.testng.internal.invokers;2import org.testng.IInvokedMethod;3import org.testng.IInvokedMethodListener;4import org.testng.IInvokedMethodListener2;5import org.testng.ITestContext;6import org.testng.ITestResult;7import org.testng.collections.Maps;8import java.util.Map;9import static org.testng.internal.invokers.InvokedMethodListenerMethod.AFTER_INVOCATION;10import static org.testng.internal.invokers.InvokedMethodListenerMethod.BEFORE_INVOCATION;11import static org.testng.internal.invokers.InvokedMethodListenerSubtype.EXTENDED_LISTENER;12import static org.testng.internal.invokers.InvokedMethodListenerSubtype.SIMPLE_LISTENER;13/**14 * Hides complexity of calling methods of {@link IInvokedMethodListener} and15 * {@link IInvokedMethodListener2}.16 *17 * @author Ansgar Konermann18 */19public class InvokedMethodListenerInvoker {20 private InvokedMethodListenerMethod m_listenerMethod;21 private ITestContext m_testContext;22 private ITestResult m_testResult;23 /**24 * Creates a new invoker instance which can be used to call the specified {@code listenerMethod}25 * on any number of {@link IInvokedMethodListener}s.26 *27 * @param listenerMethod method which should be called28 * @param testResult test result which should be passed to the listener method upon invocation29 * @param testContext test context which should be passed to the listener method upon invocation.30 * This parameter is only used when calling methods on an {@link IInvokedMethodListener2}.31 */32 public InvokedMethodListenerInvoker(InvokedMethodListenerMethod listenerMethod,33 ITestResult testResult, ITestContext testContext) {34 m_listenerMethod = listenerMethod;35 m_testContext = testContext;36 m_testResult = testResult;37 }38 /**39 * Invoke the given {@code listenerInstance}, calling the method specified in the constructor of40 * this {@link InvokedMethodListenerInvoker}.41 *42 * @param listenerInstance the listener instance which should be invoked.43 * @param invokedMethod the {@link IInvokedMethod} instance which should be passed to the44 * {@link IInvokedMethodListener#beforeInvocation(IInvokedMethod, ITestResult)},45 * {@link IInvokedMethodListener#afterInvocation(IInvokedMethod, ITestResult)},46 * {@link IInvokedMethodListener2#beforeInvocation(IInvokedMethod, ITestResult, ITestContext)}47 * or {@link IInvokedMethodListener2#afterInvocation(IInvokedMethod, ITestResult, ITestContext)}48 * method.49 */50 @SuppressWarnings("unchecked")51 public void invokeListener(IInvokedMethodListener listenerInstance,52 IInvokedMethod invokedMethod) {53 final InvocationStrategy strategy = obtainStrategyFor(listenerInstance, m_listenerMethod);54 strategy.callMethod(listenerInstance, invokedMethod, m_testResult, m_testContext);55 }56 private InvocationStrategy obtainStrategyFor(IInvokedMethodListener listenerInstance,57 InvokedMethodListenerMethod listenerMethod) {58 InvokedMethodListenerSubtype invokedMethodListenerSubtype = InvokedMethodListenerSubtype59 .fromListener(listenerInstance);60 Map<InvokedMethodListenerMethod, InvocationStrategy> strategiesForListenerType = strategies61 .get(invokedMethodListenerSubtype);62 InvocationStrategy invocationStrategy = strategiesForListenerType.get(listenerMethod);63 return invocationStrategy;64 }65 private static interface InvocationStrategy<LISTENER_TYPE extends IInvokedMethodListener> {66 void callMethod(LISTENER_TYPE listener, IInvokedMethod invokedMethod, ITestResult testResult,67 ITestContext testContext);68 }69 private static class InvokeBeforeInvocationWithoutContextStrategy implements70 InvocationStrategy<IInvokedMethodListener> {71 public void callMethod(IInvokedMethodListener listener, IInvokedMethod invokedMethod,72 ITestResult testResult, ITestContext testContext) {73 listener.beforeInvocation(invokedMethod, testResult);74 }75 }76 private static class InvokeBeforeInvocationWithContextStrategy implements77 InvocationStrategy<IInvokedMethodListener2> {78 public void callMethod(IInvokedMethodListener2 listener, IInvokedMethod invokedMethod,79 ITestResult testResult, ITestContext testContext) {80 listener.beforeInvocation(invokedMethod, testResult, testContext);81 }82 }83 private static class InvokeAfterInvocationWithoutContextStrategy implements84 InvocationStrategy<IInvokedMethodListener> {85 public void callMethod(IInvokedMethodListener listener, IInvokedMethod invokedMethod,86 ITestResult testResult, ITestContext testContext) {87 listener.afterInvocation(invokedMethod, testResult);88 }89 }90 private static class InvokeAfterInvocationWithContextStrategy implements91 InvocationStrategy<IInvokedMethodListener2> {92 public void callMethod(IInvokedMethodListener2 listener, IInvokedMethod invokedMethod,93 ITestResult testResult, ITestContext testContext) {94 listener.afterInvocation(invokedMethod, testResult, testContext);95 }96 }97 private static final Map<InvokedMethodListenerSubtype, Map<InvokedMethodListenerMethod,98 InvocationStrategy>> strategies = Maps.newHashMap();99 private static final Map<InvokedMethodListenerMethod, InvocationStrategy>100 INVOKE_WITH_CONTEXT_STRATEGIES = Maps.newHashMap();101 private static final Map<InvokedMethodListenerMethod, InvocationStrategy>102 INVOKE_WITHOUT_CONTEXT_STRATEGIES = Maps.newHashMap();103 static {104 INVOKE_WITH_CONTEXT_STRATEGIES.put(BEFORE_INVOCATION,105 new InvokeBeforeInvocationWithContextStrategy());106 INVOKE_WITH_CONTEXT_STRATEGIES.put(AFTER_INVOCATION,107 new InvokeAfterInvocationWithContextStrategy());108 INVOKE_WITHOUT_CONTEXT_STRATEGIES.put(BEFORE_INVOCATION,109 new InvokeBeforeInvocationWithoutContextStrategy());110 INVOKE_WITHOUT_CONTEXT_STRATEGIES.put(AFTER_INVOCATION,111 new InvokeAfterInvocationWithoutContextStrategy());112 strategies.put(EXTENDED_LISTENER, INVOKE_WITH_CONTEXT_STRATEGIES);113 strategies.put(SIMPLE_LISTENER, INVOKE_WITHOUT_CONTEXT_STRATEGIES);114 }115}...
Source:MyTestNGAnnotationListener.java
1package testnge2e.custanno;2import java.lang.reflect.Constructor;3import java.lang.reflect.InvocationTargetException;4import java.lang.reflect.Method;5import org.testng.IAnnotationTransformer;6import org.testng.IInvokedMethod;7import org.testng.IInvokedMethodListener;8import org.testng.ITestContext;9import org.testng.ITestListener;10import org.testng.ITestNGMethod;11import org.testng.ITestResult;12import org.testng.annotations.ITestAnnotation;13import testnge2e.TestCalc;14/**15 * The listener interface for receiving MyTestNGAnnotation events.16 * The Listener can be automatically invoked when TestNG tests are run by using ServiceLoader mechanism.17 * You can also add this listener to a TestNG Test class by adding18 * <code>@Listeners({com.amareshp.annotations.MyTestNGAnnotationListener.class})</code>19 * before the test class20 *21 * @see MyTestNGAnnotation22 */23public class MyTestNGAnnotationListener implements IInvokedMethodListener, ITestListener , IAnnotationTransformer {24 25 26 boolean testSuccess = true;27 28 29 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {30 if(method.isTestMethod() && annotationPresent(method, MyTestNGAnnotation.class) ) {31 //System.out.println("This gets invoked before every TestNG Test that has @MyTestNGAnnotation Annotation...");32 //System.out.println("Name: " + DataSet.name + " City: " + DataSet.city + " State: " + DataSet.state);33 }34 }35 36 private boolean annotationPresent(IInvokedMethod method, Class clazz) {37 boolean retVal = method.getTestMethod().getConstructorOrMethod().getMethod().isAnnotationPresent(clazz) ? true : false;38 return retVal;39 }40 41 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {42 if(method.isTestMethod()) {43 if(method.getClass().isAnnotationPresent(MyTestNGAnnotation.class)) {44 System.out.println("This gets invoked after every TestNG Test that has @MyTestNGAnnotation Annotation...");45 }46 if( !testSuccess ) {47 testResult.setStatus(ITestResult.FAILURE);48 }49 }50 }51 public void onTestStart(ITestResult result) {52 // TODO Auto-generated method stub53 54 }55 public void onTestSuccess(ITestResult result) {56 // TODO Auto-generated method stub57 58 }59 public void onTestFailure(ITestResult result) {60 // TODO Auto-generated method stub61 62 }63 public void onTestSkipped(ITestResult result) {64 // TODO Auto-generated method stub65 66 }67 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {68 // TODO Auto-generated method stub69 70 }71 public void onStart(ITestContext context) {try{72 // Method m = context.getCurrentXmlTest().getPackages().get(0).getXmlClasses().get(1).getClass().getDeclaredMethod("tMe", null);73 //System.out.println(context.getCurrentXmlTest().getPackages().get(0).getXmlClasses().get(1));74 for(ITestNGMethod m1 : context.getAllTestMethods()) {75 if(m1.getConstructorOrMethod().getMethod().isAnnotationPresent(MyTestNGAnnotation.class)) {76 //capture metadata information.77 DataSet.name = m1.getConstructorOrMethod().getMethod().getAnnotation(MyTestNGAnnotation.class).name();78 DataSet.city = m1.getConstructorOrMethod().getMethod().getAnnotation(MyTestNGAnnotation.class).city();79 DataSet.state = m1.getConstructorOrMethod().getMethod().getAnnotation(MyTestNGAnnotation.class).state();80 }81 // m.invoke(new TestCalc(), null);82 } 83 }catch(Exception e){e.printStackTrace();} 84 }85 public void onFinish(ITestContext context) {86 87 }88 89 public void transform(ITestAnnotation arg0, Class arg1, Constructor arg2,90 Method arg3) {91 92 }93}...
Source:XrayListener.java
1package components.reporting.xray;2import components.testbase.*;3import org.testng.*;4/**5 * The listener interface for receiving Xray events.6 * The Listener can be automatically invoked when TestNG tests are run by using ServiceLoader mechanism.7 * You can also add this listener to a TestNG Test class by adding8 * <code>@Listeners({com.xpand.java.XrayAnnotationListener.class})</code>9 * before the test class10 *11 * @see Xray12 */13public class XrayListener extends TestBase implements IInvokedMethodListener, ITestListener {14 boolean testSuccess = true;15 /* (non-Javadoc)16 * @see org.testng.IInvokedMethodListener#beforeInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)17 */18 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {19 if(method.isTestMethod() && annotationPresent(method, Xray.class) ) {20 testResult.setAttribute("requirement", method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Xray.class).requirement());21 testResult.setAttribute("test", method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Xray.class).test());22 testResult.setAttribute("labels", method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Xray.class).labels());23 }24 }25 private boolean annotationPresent(IInvokedMethod method, Class clazz) {26 boolean retVal = method.getTestMethod().getConstructorOrMethod().getMethod().isAnnotationPresent(clazz) ? true : false;27 return retVal;28 }29 /* (non-Javadoc)30 * @see org.testng.IInvokedMethodListener#afterInvocation(org.testng.IInvokedMethod, org.testng.ITestResult)31 */32 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {33 if(method.isTestMethod()) {34 if( !testSuccess ) {35 testResult.setStatus(ITestResult.FAILURE);36 testResult.setAttribute("env",System.getProperty("testedEnv"));37 testResult.setAttribute("version",System.getProperty("ActualVersion"));38 }39 }40 }41 public void onTestStart(ITestResult result) {42 // TODO Auto-generated method stub43 }44 public void onTestSuccess(ITestResult result) {45 // TODO Auto-generated method stub46 }47 public void onTestFailure(ITestResult result) {48 // TODO Auto-generated method stub49 }50 public void onTestSkipped(ITestResult result) {51 // TODO Auto-generated method stub52 }53 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {54 // TODO Auto-generated method stub55 }56 public void onStart(ITestContext context) {57 }58 public void onFinish(ITestContext context) {59 // TODO Auto-generated method stub60 }61}...
Source:SauceLabsIntegration.java
1package omelet.support.saucelabs;2import omelet.driver.Driver;3import org.apache.log4j.Logger;4import org.openqa.selenium.remote.RemoteWebDriver;5import org.testng.IInvokedMethod;6import org.testng.IInvokedMethodListener;7import org.testng.ITestResult;8import org.testng.Reporter;9public class SauceLabsIntegration implements IInvokedMethodListener {10 private static final Logger LOGGER = Logger11 .getLogger(SauceLabsIntegration.class);12 @Override13 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {14 try {15 // it will throw Null pointer exception for the method who are not16 // omelet driven , should be fixed as using try catch is a temporary17 // one!18 if (Driver.getBrowserConf().host().contains("sauce")19 && Driver.getBrowserConf().isRemoteFlag()) {20 RemoteWebDriver driver = (RemoteWebDriver) Driver.getDriver();21 LOGGER.debug("After in SL Integration driver Session ID: "22 + driver.getSessionId());23 WebInterface slWebInterface = new WebInterface();24 slWebInterface.updateSauceLabsJob(driver.getSessionId()25 .toString(), method.getTestMethod().getMethodName(),26 method.getTestResult().isSuccess());27 Reporter.setCurrentTestResult(testResult);28 Reporter.log("SauceLabs Report :: ");29 Reporter.log(slWebInterface.generateLinkForJob(driver30 .getSessionId().toString()));31 // Reporter.log(slWebInterface.generateLinkForEmbedScript(driver32 // .getSessionId().toString(), true));33 // Reporter.log("<br>");34 // Reporter.log("SauceLabs Video :: "35 // + slWebInterface.generateLinkForEmbedScript(driver36 // .getSessionId().toString(), false));37 Reporter.log("<br>");38 }39 } catch (Exception e) {40 LOGGER.error("Not to interfere in the test result!, but needs to be taken care!");41 }42 }43 @Override44 public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) {45 }46}...
Source:BaseListener.java
1package com.util;2import org.testng.IInvokedMethod;3import org.testng.IInvokedMethodListener;4import org.testng.ITestContext;5import org.testng.ITestListener;6import org.testng.ITestResult;7/**8 *9 * @author limit (Yurii Chukhrai)10 */11public class BaseListener implements ITestListener, IInvokedMethodListener {12 /* Methods of Interface 'ITestListener' */13 @Override14 public void onTestStart(ITestResult result) {15 // NOP16 }17 @Override18 public void onTestSuccess(ITestResult result) {19 // NOP20 }21 @Override22 public void onTestFailure(ITestResult result) {23 if(!BaseUtils.isWebDriverDead(ThreadStoreLocal.getWebDriver())) {24 BaseUtils.makeScreenAsShot("Test_FAIL_", false, ThreadStoreLocal.getWebDriver());25 }26 }27 @Override28 public void onTestSkipped(ITestResult result) {29 // NOP30 }31 @Override32 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {33 // NOP34 }35 @Override36 public void onStart(ITestContext context) {37 // NOP38 }39 @Override40 public void onFinish(ITestContext context) {41 // NOP42 }43 @Override44 public void afterInvocation(IInvokedMethod arg0, ITestResult arg1) {45 // NOP46 }47 @Override48 public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) {49 // NOP50 }51}...
Source:InvokedMethodListenerImpl.java
1package org.testng.training.testng.solution;2import org.testng.IInvokedMethod;3import org.testng.IInvokedMethodListener;4import org.testng.ITestResult;5import org.testng.training.testng.demo.LogUtils;6/**7 * <p>Implementation of the interface {@link IInvokedMethodListener} to show how to handle the business logic before8 * and after all <b>IInvokedMethod</b> execution. <b>IInvokedMethod</b> includes both test method and configuration9 * method.10 * </p>11 */12public class InvokedMethodListenerImpl implements IInvokedMethodListener {13 @Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {14 LogUtils.info('[' + getClass().getSimpleName() + " - beforeInvocation] - isTestMethod: " + method.isTestMethod()15 + " - ITestResult:" + testResult.getName());16 }17 @Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) {18 LogUtils.info('[' + getClass().getSimpleName() + " - afterInvocation] - isTestMethod: " + method.isTestMethod()19 + " - ITestResult:" + testResult.getName());20 }21}...
Source:IInvokedMethodListenerEx.java
1package com.nordstrom.automation.testng;23import org.testng.IInvokedMethod;4import org.testng.IInvokedMethodListener;5import org.testng.ITestResult;67/**8 * This interface extends {@link IInvokedMethodListener} without adding any new method signatures. While any class that9 * implements {@link IInvokedMethodListenerEx} can be activated as an invoked method listener, the intended target for10 * this interface is test classes whose execution will be orchestrated by {@link ExecutionFlowController}. During test11 * execution, the execution flow controller forwards calls received by its own {@link #beforeInvocation(IInvokedMethod,12 * ITestResult)} and {@link #afterInvocation(IInvokedMethod, ITestResult)} implementations to those of the test class.13 * 14 * @see ExecutionFlowController15 * @see IInvokedMethodListener16 */17public interface IInvokedMethodListenerEx extends IInvokedMethodListener {1819}
...
Source:IInvokedMethodListener.java
1package com.zendaimoney.Dokodemo.listener;23import org.testng.IInvokedMethod;4import org.testng.ITestNGListener;5import org.testng.ITestResult;67public interface IInvokedMethodListener extends ITestNGListener {89 void beforeInvocation(IInvokedMethod method, ITestResult testResult);1011 void afterInvocation(IInvokedMethod method, ITestResult testResult);1213}
...
Interface IInvokedMethod
Using AI Code Generation
1import org.testng.IInvokedMethod;2import org.testng.IInvokedMethodListener;3import org.testng.ITestResult;4public class MyInvokedMethodListener implements IInvokedMethodListener {5 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {6 System.out.println("About to begin executing following method : " + returnMethodName(method.getTestMethod().getMethodName()));7 }8 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {9 System.out.println("Completed executing following method : " + returnMethodName(method.getTestMethod().getMethodName()));10 }11 private String returnMethodName(String methodName) {12 return methodName;13 }14}15import org.testng.ITestContext;16import org.testng.ITestListener;17import org.testng.ITestResult;18public class MyTestListener implements ITestListener {19 public void onTestStart(ITestResult result) {20 System.out.println((result.getMethod().getMethodName()) + " test is starting.");21 }22 public void onTestSuccess(ITestResult result) {23 System.out.println((result.getMethod().getMethodName()) + " test is successful.");24 }25 public void onTestFailure(ITestResult result) {26 System.out.println((result.getMethod().getMethodName()) + " test is failed.");27 }28 public void onTestSkipped(ITestResult result) {29 System.out.println((result.getMethod().getMethodName()) + " test is skipped.");30 }31 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {32 }33 public void onStart(ITestContext context) {34 System.out.println("About to begin executing Test " + context.getName());35 }36 public void onFinish(ITestContext context) {37 System.out.println("Completed executing test
Interface IInvokedMethod
Using AI Code Generation
1public class InvokedMethodListener implements IInvokedMethodListener {2 private static final Logger logger = Logger.getLogger(InvokedMethodListener.class);3 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {4 logger.info("Method " + method.getTestMethod().getMethodName() + " started");5 }6 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {7 logger.info("Method " + method.getTestMethod().getMethodName() + " finished");8 }9}10public class TestListener implements ITestListener {11 private static final Logger logger = Logger.getLogger(TestListener.class);12 public void onStart(ITestContext context) {13 logger.info("Test started");14 }15 public void onFinish(ITestContext context) {16 logger.info("Test finished");17 }18 public void onTestStart(ITestResult result) {19 logger.info("Test " + result.getName() + " started");20 }21 public void onTestSuccess(ITestResult result) {22 logger.info("Test " + result.getName() + " passed");23 }24 public void onTestFailure(ITestResult result) {25 logger.info("Test " + result.getName() + " failed");26 }27 public void onTestSkipped(ITestResult result) {28 logger.info("Test " + result.getName() + " skipped");29 }30 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {31 }32}33public class Reporter implements IReporter {34 private static final Logger logger = Logger.getLogger(Reporter.class);35 public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {36 for (ISuite suite : suites) {37 Map<String, ISuiteResult> result = suite.getResults();38 for (ISuiteResult r : result.values()) {39 ITestContext context = r.getTestContext();40 logger.info("Passed tests for suite " + suite.getName() + " " + context.getPassedTests().getAllResults().size());41 logger.info("Failed tests for suite " + suite.getName()
Interface IInvokedMethod
Using AI Code Generation
1package com.mycompany.app;2import org.testng.IInvokedMethod;3import org.testng.IInvokedMethodListener;4import org.testng.ITestResult;5public class MyInvokedMethodListener implements IInvokedMethodListener {6 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {7 System.out.println("Before invocation of " + method.getTestMethod().getMethodName());8 }9 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {10 System.out.println("After invocation of " + method.getTestMethod().getMethodName());11 }12}13package com.mycompany.app;14import org.testng.IInvokedMethod;15import org.testng.IInvokedMethodListener;16import org.testng.ITestResult;17public class MyInvokedMethodListener implements IInvokedMethodListener {18 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {19 System.out.println("Before invocation of " + method.getTestMethod().getMethodName());20 }21 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {22 System.out.println("After invocation of " + method.getTestMethod().getMethodName());23 }24}25package com.mycompany.app;26import org.testng.ITestContext;27import org.testng.ITestListener;28import org.testng.ITestResult;29public class MyTestListener implements ITestListener {30 public void onTestStart(ITestResult result) {31 System.out.println("Test started: " + result.getName());32 }33 public void onTestSuccess(ITestResult result) {34 System.out.println("Test success: " + result.getName());35 }36 public void onTestFailure(ITestResult result) {37 System.out.println("Test failed: " + result.getName());38 }39 public void onTestSkipped(ITestResult result) {40 System.out.println("Test skipped: " + result.getName());41 }42 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {43 System.out.println("Test failed but within success percentage: " + result.getName());44 }45 public void onStart(ITestContext context)
Interface IInvokedMethod
Using AI Code Generation
1public class TestNGListener implements IInvokedMethodListener {2 public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {3 System.out.println("beforeInvocation: " + testResult.getTestClass().getName() + " => " + testResult.getName());4 }5 public void afterInvocation(IInvokedMethod method, ITestResult testResult) {6 System.out.println("afterInvocation: " + testResult.getTestClass().getName() + " => " + testResult.getName());7 }8}9public class TestNGListener implements ITestListener {10 public void onTestStart(ITestResult result) {11 System.out.println("onTestStart: " + result.getName());12 }13 public void onTestSuccess(ITestResult result) {14 System.out.println("onTestSuccess: " + result.getName());15 }16 public void onTestFailure(ITestResult result) {17 System.out.println("onTestFailure: " + result.getName());18 }19 public void onTestSkipped(ITestResult result) {20 System.out.println("onTestSkipped: " + result.getName());21 }22 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {23 System.out.println("onTestFailedButWithinSuccessPercentage: " + result.getName());24 }25 public void onStart(ITestContext context) {26 System.out.println("onStart: " + context.getName());27 }28 public void onFinish(ITestContext context) {29 System.out.println("onFinish: " + context.getName());30 }31}
TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.
You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.
Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!