Best Testng code snippet using org.testng.TestNG.setListenerClasses
Source:Base_Driver.java
...118 119// List<Class> listenerClass = new ArrayList<Class>();120// listenerClass.add(utility.Custom_Reporter.class);121// 122// myTestNG.setListenerClasses(listenerClass);123// myTestNG.addListener(listenerClass);124 125 //Set the list of Suites to the testNG object you created earlier.126 myTestNG.setXmlSuites(mySuites);127 128 return myTestNG;129 }130 131 public static TestNG createNewTestNGXML(ArrayList<String> suites_arr) {132 133// System.out.println(suites_arr);134 135 //Create an instance on TestNG136 TestNG myTestNG = new TestNG();137 138 //Create an instance of XML Suite and assign a name for it.139 XmlSuite mySuite = new XmlSuite();140 mySuite.setName("Test Suites");141 142 //<suite>143 144 //Create a list of XmlTests and add the Xmltest you created earlier to it.145 List<XmlTest> myTests = new ArrayList<XmlTest>();146 147 for (String script : suites_arr) {148 149 //Create an instance of XmlTest and assign a name for it.150 XmlTest myTest = new XmlTest(mySuite);151 myTest.setName("testsuite");152 153 Map<String,String> testngParams = new HashMap<String,String> ();154 155 String browser = getBrowserParam();156 if (browser == "") {157 browser = "firefox";158 }159 160 System.out.println("Executing test case on :" + browser);161 162 testngParams.put("browser", browser);163 myTest.setParameters(testngParams);164 165 //<suite>166 // <test>167 168 List<XmlClass> myClasses = new ArrayList<XmlClass>(); 169// for (String script : suites_arr) { 170 System.out.println("Script name is: " + script);171 //Create a list which can contain the classes that you want to run. 172 myClasses.add(new XmlClass(script));173// }174 175 //<suite>176 // <test>177 // <classes>178 // <class>testScripts.SuiteC.TestNG_POC</class>179 // <class>testScripts.SuiteC.TestNG_POC2</class>180 // </classes>181 182 //Assign that to the XmlTest Object created earlier.183 myTest.setXmlClasses(myClasses);184 185 //<suite>186 // <test>187 // <classes>188 // <class>testScripts.SuiteC.TestNG_POC</class>189 // <class>testScripts.SuiteC.TestNG_POC2</class>190 // </classes>191 // </test>192 193 myTests.add(myTest);194 }195 196 //add the list of tests to your Suite.197 mySuite.setTests(myTests);198 199 //Add the suite to the list of suites.200 List<XmlSuite> mySuites = new ArrayList<XmlSuite>();201 mySuites.add(mySuite);202 203// System.out.println(mySuites);204 205// List<Class> listenerClass = new ArrayList<Class>();206// listenerClass.add(utility.Custom_Reporter.class);207// 208// myTestNG.setListenerClasses(listenerClass);209// myTestNG.addListener(listenerClass);210 211 //Set the list of Suites to the testNG object you created earlier.212 myTestNG.setXmlSuites(mySuites);213 214 return myTestNG;215 }216 217 public static void executeSuite(HashMap<String, ArrayList<String>> suites_array) {218 TestNG myTestNGSuites = createTestNGXML(suites_array); 219 //invoke run() - this will run your testng xml as a total suite.220 List<Class> listenerClass = new ArrayList<Class>();221 listenerClass.add(com.testing.SeleniumX.utility.CustomReportListener.class);222 myTestNGSuites.setListenerClasses(listenerClass);223// IReporter ir = new Custom_Reporter();224// myTestNGSuites.addListener(ir);225 myTestNGSuites.run(); 226 }227 228 public static TestNG executeSuites(ArrayList<String> suites_array) {229 TestNG myTestNGSuites = createNewTestNGXML(suites_array); 230 //invoke run() - this will run your testng xml as a total suite.231// List<Class> listenerClass = new ArrayList<Class>();232// listenerClass.add(com.testing.SeleniumX.utility.CustomReportListener.class);233// myTestNGSuites.setListenerClasses(listenerClass);234235// myTestNGSuites.run(); 236 int testng_status = myTestNGSuites.getStatus();237 System.out.println("testng status is : " + testng_status);238 239 return myTestNGSuites;240 }241 242 //TODO: to read sender's list from an xml file243// public static void sendEmail() throws AddressException, MessagingException {244// System.out.println("\n 1st ===> setup Mail Server Properties..");245// mailServerProperties = System.getProperties();246// mailServerProperties.put("mail.smtp.port", "587");247// mailServerProperties.put("mail.smtp.auth", "true");248// mailServerProperties.put("mail.smtp.starttls.enable", "true");249// System.out.println("Mail Server Properties have been setup successfully..");250// 251// System.out.println("\n\n 2nd ===> get Mail Session..");252//// getMailSession = Session.getDefaultInstance(mailServerProperties, null);253// getMailSession = Session.getDefaultInstance(mailServerProperties, new javax.mail.Authenticator(){254// protected PasswordAuthentication getPasswordAuthentication() {255// return new PasswordAuthentication(256// "anukul.singhal@gmail.com", "");// Specify the Username and the PassWord257// }258// });259// generateMailMessage = new MimeMessage(getMailSession);260// generateMailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("sanukul@liveops.com"));261// generateMailMessage.setSubject("Greetings from Slayer..");262// String emailBody = "Test email by Slayer. " + "<br><br> Regards, <br>Slayer";263// generateMailMessage.setContent(emailBody, "text/html");264// System.out.println("Mail Session has been created successfully..");265// 266// System.out.println("\n\n 3rd ===> Get Session and Send mail");267// Transport transport = getMailSession.getTransport("smtp");268// transport.connect("smtp.gmail.com", 587, "anukul.singhal@gmail.com", "");269// transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());270// transport.close();271// }272 273 public static String getBrowserParam() {274 String browser="";275 String workingDir = System.getProperty("user.dir");276 String path = workingDir+"\\src\\main\\java\\com\\testing\\SeleniumX\\config\\base_driver_config.properties";277 browser = Properties_Utils.get_property(path,"browser");278 return browser;279 }280 281 // http://stackoverflow.com/questions/17458243/class-not-found-exception-with-exec-maven-plugin-when-run-on-linux282 //mvn exec:java -Dexec.mainClass="com.testing.tests.SeleniumX.runManager.Base_Driver" -Dexec.classpathScope=test -e283 //To build jar:284 //mvn -X clean install exec:java -Dexec.mainClass="com.testing.tests.SeleniumX.runManager.Base_Driver" -Dexec.classpathScope=test -e285 public static void main(String[] args) {286 287 //ANUKUL288 String workingDir = System.getProperty("user.dir");289 String path = workingDir+"\\src\\main\\java\\com\\testing\\SeleniumX\\config\\base_driver_config.properties";290 String test = Properties_Utils.get_property(path,"tests");291 System.out.println("tests to be executed : " + test);292 //ANUKUL293 294// HashMap<String, String[]> suite_script_hash = new HashMap<String, String[]>();295// suite_script_hash.put("SuiteC", tests);296 297 //TODO: to fetch this ArrayList as cmd line argument from Automation Manager298// HashMap<String, ArrayList<String>> suite_script_hash = args;299// String suite_script_hash = args;300 301 //TODO: Create base_driver_config, read tests to run from it, and then form 302 //TestNG xml, and execute303 304// System.out.println("Check parameter : " + suite_script_hash);305 306// HashMap<String, ArrayList<String>> suite_script_hash = new HashMap<String, ArrayList<String>>();307 308 //ANUKUL309 ArrayList<String> tests = new ArrayList<>();310 tests.add(test);311 //ANUKUL312 313// String[] test = {"testScripts.suiteC.TestNG_POC", "testScripts.suiteC.TestNG_POC2"};314// String[] test1 = {"testScripts.suiteD.TestNG_Stub"};315// suite_script_hash.put("SuiteC", tests);316// suite_script_hash.put("SuiteD", test1);317// createTestNGXML(suite_script_hash);318 319// System.out.println("execute tests : " + tests);320 321 //ANUKUL322 TestNG myTestNG = executeSuites(tests);323// System.out.println("TestNG suite is : " + myTestNG);324 List<Class> listenerClass = new ArrayList<Class>();325 listenerClass.add(com.testing.SeleniumX.utility.CustomReportListener.class);326 myTestNG.setListenerClasses(listenerClass);327 myTestNG.run();328// System.out.println("test run complete..");329 //ANUKUL330 331// sendEmail();332 }333334}
...
Source:Batch_Driver.java
...22 suites.add(suitepath);23 testng.setTestSuites(suites);24 List<Class> listenerClass = new ArrayList<Class>();25 listenerClass.add(com.testing.SeleniumX.utility.CustomReportListener.class);26 testng.setListenerClasses(listenerClass);27 testng.run();28 }29 30 // Pass the output report path, parse and get the failures, and return the 31 //failure classes to be rerun32 public static ArrayList<String> getFailures() {33 ArrayList<String> getFailureClassNames = new ArrayList<>();34 getFailureClassNames = CustomReportListener.getFailureClasses();35 System.out.println("Failure Class Names are : " + getFailureClassNames);36 return getFailureClassNames;37 } 38 39 public static TestNG formTestNGFailureCases(ArrayList<String> failureArray) {40 TestNG myTestNG = new TestNG();41 42 //Create an instance of XML Suite and assign a name for it.43 XmlSuite mySuite = new XmlSuite();44 mySuite.setName("Test Suites");45 46 //<suite>47 48 //Create a list of XmlTests and add the Xmltest you created earlier to it.49 List<XmlTest> myTests = new ArrayList<XmlTest>();50 51// for (String suite : failureArray) {52 53 //Create an instance of XmlTest and assign a name for it.54 XmlTest myTest = new XmlTest(mySuite);55 myTest.setName("suite1");56 57 Map<String,String> testngParams = new HashMap<String,String> ();58 59 //TODO: access browser param from the original testng xml, hard coding for now60 String browser = "chrome";61// if (browser == "") {62// browser = "firefox";63// }64 65 System.out.println("Executing test case on :" + browser);66 67 testngParams.put("browser", browser);68 myTest.setParameters(testngParams);69 70 //<suite>71 // <test>72 73 List<XmlClass> myClasses = new ArrayList<XmlClass>(); 74 for (String script : failureArray) { 75 System.out.println("Script name is: " + script);76 //Create a list which can contain the classes that you want to run. 77 myClasses.add(new XmlClass(script));78 }79 80 //<suite>81 // <test>82 // <classes>83 // <class>testScripts.SuiteC.TestNG_POC</class>84 // <class>testScripts.SuiteC.TestNG_POC2</class>85 // </classes>86 87 //Assign that to the XmlTest Object created earlier.88 myTest.setXmlClasses(myClasses);89 90 //<suite>91 // <test>92 // <classes>93 // <class>testScripts.SuiteC.TestNG_POC</class>94 // <class>testScripts.SuiteC.TestNG_POC2</class>95 // </classes>96 // </test>97 98 myTests.add(myTest);99// }100 101 //add the list of tests to your Suite.102 mySuite.setTests(myTests);103 104 //Add the suite to the list of suites.105 List<XmlSuite> mySuites = new ArrayList<XmlSuite>();106 mySuites.add(mySuite);107 108 System.out.println(mySuites);109 110// List<Class> listenerClass = new ArrayList<Class>();111// listenerClass.add(utility.Custom_Reporter.class);112// 113// myTestNG.setListenerClasses(listenerClass);114// myTestNG.addListener(listenerClass);115 116 //Set the list of Suites to the testNG object you created earlier.117 myTestNG.setXmlSuites(mySuites);118 119 return myTestNG;120 }121 122 public static void rerunFailures(ArrayList<String> failures) {123 System.out.println("Rerunning Failures");124 TestNG myTestNGSuites = formTestNGFailureCases(failures);125 //TODO: Need to create a new report after rerunning failures, merge original with the rerun report126 List<Class> listenerClass = new ArrayList<Class>();127 listenerClass.add(com.testing.SeleniumX.utility.CustomReportListener.class);128 myTestNGSuites.setListenerClasses(listenerClass);129 myTestNGSuites.run();130 }131 132 public static void main(String[] args) {133 // TODO Auto-generated method stub134 String suite_path = args[0];135 136 executeTestNGSuite(suite_path); 137 String workingDir = System.getProperty("user.dir");138 String path = workingDir+"\\src\\main\\java\\com\\testing\\SeleniumX\\config\\batch_driver_config.properties";139 String rerun = Properties_Utils.get_property(path,"rerun");140 Integer rerun_count = Integer.valueOf(rerun);141 ArrayList<String> failures = getFailures();142
...
Source:AnnotationsSimulatedRunTest.java
...55 public void testMethodsAnnotated() throws IOException, ParseException {56 final Calendar before = Calendar.getInstance();57 final TestNG testNG = new TestNG();58 testNG.setTestClasses(new Class[] {MethodsAnnotatedTest.class});59 testNG.setListenerClasses(ImmutableList.of(TesterraListener.class));60 testNG.setParallel(XmlSuite.ParallelMode.METHODS);61 testNG.setThreadCount(3);62 testNG.run();63 checkTestExecutionResult(TEST_EXEC_KEY_DEFAULT, fullWithoutParametrized, before);64 }65 @Test66 public void testClassAnnotatedWithKey() throws IOException, ParseException {67 final Calendar before = Calendar.getInstance();68 final TestNG testNG = new TestNG();69 testNG.setTestClasses(new Class[] {ClassAnnotatedWithKeyTest.class});70 testNG.setListenerClasses(ImmutableList.of(TesterraListener.class));71 testNG.setParallel(XmlSuite.ParallelMode.METHODS);72 testNG.run();73 checkTestExecutionResult(TEST_EXEC_KEY_DEFAULT, before);74 }75 @Test76 public void testClassAnnotatedWithoutKey() throws IOException, ParseException {77 final Calendar before = Calendar.getInstance();78 final TestNG testNG = new TestNG();79 testNG.setTestClasses(new Class[] {ClassAnnotatedWithoutKeyTest.class});80 testNG.setListenerClasses(ImmutableList.of(TesterraListener.class));81 testNG.setParallel(XmlSuite.ParallelMode.METHODS);82 testNG.run();83 checkTestExecutionResult(TEST_EXEC_KEY_DEFAULT, before);84 }85}...
Source:Start.java
...54 // Zuordnung der Testsuite die wir oben angelegt haben55 suites.add(suite);56 // Die auszuführenden Testsuiten werden an TestNG übergeben57 testng.setXmlSuites(suites);58 testng.setListenerClasses(myITestNGListeners);59// testng.setListenerClasses(myITestResultsListeners);60 61 testng.run();62 }63}...
Source:SuitesRunner.java
...29 }30 System.out.println("Starting " + testSuite.getSuiteName() + " test suite: ");31 final InputStream xmlSuiteStream = getXmlSuiteStream(testSuite);32 testNG.setXmlSuites((List<XmlSuite>) new Parser(xmlSuiteStream).parse());33 testNG.setListenerClasses(listenerClasses);34 testNG.setUseDefaultListeners(false);35 testNG.setParallel("classes");36 testNG.setThreadCount(5);37 testNG.run();38 }39 public static InputStream getXmlSuiteStream(final TestSuites testSuite) {40 return org.testng.SuiteRunner.class.getClassLoader().getResourceAsStream(testSuite.getSuitePath());41 }42}...
Source:ReportPortalRunner.java
...19 public static boolean run(String xml) {20 TestNG testNG = new TestNG(true);21 List<Class<? extends ITestNGListener>> classes = new ArrayList<>();22 classes.add(ReportPortalTestNGListener.class);23 testNG.setListenerClasses(classes);24 testNG.setTestSuites(Arrays.asList(xml));25 TestListenerAdapter results = new TestListenerAdapter() {26 @Override27 public void onStart(ITestContext testContext) {28 super.onStart(testContext);29 }30 };31 testNG.addListener((ITestNGListener) results);32 boolean hasFailures;33 try {34 testNG.run();35 hasFailures = results.getFailedTests().size() > 0 || results.getSkippedTests().size() > 0;36 } catch (Throwable e) {37 /* something goes wrong... */...
Source:TestMaker.java
...18 public void run()19 {20 final TestNG tng = new TestNG();21 tng.setUseDefaultListeners(false);22 tng.setListenerClasses(Arrays.<Class> asList(TestListenerAdapter.class, SimpleReporter.class));23 final List<XmlSuite> suites = createSuites();24 tng.setXmlSuites(suites);25 tng.setVerbose(0);26 tng.run();2728// Reporter.log(tng.getSuiteListeners().size() + "", true);29// for (final XmlSuite xmlSuite : suites)30// {31// Reporter.log(xmlSuite.getName() + ": " + xmlSuite.getListeners().size(), true);32// }33 }3435 private List<XmlSuite> createSuites()36 {
...
Source:Runner.java
...10 public static void main(String[] args) {11 TestNG testNG = new TestNG(false);12 List<Class<? extends ITestNGListener>> classes = new ArrayList<>();13 classes.add(ReportPortalTestNGListener.class);14 testNG.setListenerClasses(classes);15 testNG.setTestSuites(Arrays.asList("src/test/java/com/epam/auto/TestSuite.xml"));16 TestListenerAdapter results = new TestListenerAdapter();17 testNG.addListener(results);18 boolean hasFailures;19 try {20 testNG.run();21 hasFailures = results.getFailedTests().size() > 0 || results.getSkippedTests().size() > 0;22 } catch (Throwable e) {23 hasFailures = true;24 e.printStackTrace();25 }26 System.exit(hasFailures ? 1 : 0);27 }28}...
setListenerClasses
Using AI Code Generation
1import org.testng.TestNG;2import java.util.ArrayList;3import java.util.List;4public class TestNGExample {5 public static void main(String[] args) {6 TestNG testNG = new TestNG();7 List<String> suites = new ArrayList<>();8 suites.add("src/test/resources/testng.xml");9 testNG.setTestSuites(suites);10 testNG.run();11 }12}13package com.javacodegeeks.testng;14import org.testng.Assert;15import org.testng.annotations.Test;16public class TestNGExample {17 public void testMethod1() {18 Assert.assertTrue(true);19 }20}21package com.javacodegeeks.testng;22import org.testng.ITestContext;23import org.testng.ITestListener;24import org.testng.ITestResult;25public class CustomListener implements ITestListener {26 public void onTestStart(ITestResult result) {27 System.out.println("Test started: " + result.getName());28 }29 public void onTestSuccess(ITestResult result) {30 System.out.println("Test succeeded: " + result.getName());31 }32 public void onTestFailure(ITestResult result) {33 System.out.println("Test failed: " + result.getName());34 }35 public void onTestSkipped(ITestResult result) {36 System.out.println("Test skipped: " + result.getName());37 }38 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {39 System.out.println("Test failed but within success percentage: " + result.getName());40 }41 public void onStart(ITestContext context) {42 System.out.println("Test started: " + context.getName());43 }
setListenerClasses
Using AI Code Generation
1import org.testng.TestNG;2import java.util.ArrayList;3import java.util.List;4public class TestNGListenerDemo {5 public static void main(String[] args) {6 TestNG testNG = new TestNG();7 List<String> suiteFiles = new ArrayList<>();8 suiteFiles.add("src/test/resources/testng.xml");9 testNG.setTestSuites(suiteFiles);10 List<Class> listenerClasses = new ArrayList<>();11 listenerClasses.add(TestNGListener.class);12 testNG.setListenerClasses(listenerClasses);13 testNG.run();14 }15}16package com.coderbd.testng;17import org.testng.ITestContext;18import org.testng.ITestListener;19import org.testng.ITestResult;20public class TestNGListener implements ITestListener {21 public void onTestStart(ITestResult result) {22 System.out.println("Test Started: " + result.getName());23 }24 public void onTestSuccess(ITestResult result) {25 System.out.println("Test Success: " + result.getName());26 }27 public void onTestFailure(ITestResult result) {28 System.out.println("Test Failed: " + result.getName());29 }30 public void onTestSkipped(ITestResult result) {31 System.out.println("Test Skipped: " + result.getName());32 }33 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {34 System.out.println("Test Failed but within success percentage: " + result.getName());35 }36 public void onStart(ITestContext context) {37 System.out.println("Test Started: " + context.getName());38 }39 public void onFinish(ITestContext context) {40 System.out.println("Test Finished: " + context.getName());
setListenerClasses
Using AI Code Generation
1import java.util.Arrays;2import java.util.List;3import org.testng.TestListenerAdapter;4import org.testng.TestNG;5import org.testng.annotations.Test;6public class SetListenerClasses {7 public void setListenerClasses() {8 TestNG testng = new TestNG();9 TestListenerAdapter tla = new TestListenerAdapter();10 testng.addListener(tla);11 List<String> suites = Arrays.asList("testng.xml");12 testng.setTestSuites(suites);13 testng.run();14 }15}16import java.util.Arrays;17import java.util.List;18import org.testng.TestListenerAdapter;19import org.testng.TestNG;20import org.testng.annotations.Test;21public class SetListenerClasses {22 public void setListenerClasses() {23 TestNG testng = new TestNG();24 TestListenerAdapter tla = new TestListenerAdapter();25 testng.addListener(tla);26 List<String> suites = Arrays.asList("testng.xml");27 testng.setTestSuites(suites);28 testng.run();29 }30}31import java.util.Arrays;32import java.util.List;33import org.testng.TestListenerAdapter;34import org.testng.TestNG;35import org.testng.annotations.Test;36public class SetListenerClasses {37 public void setListenerClasses() {38 TestNG testng = new TestNG();39 TestListenerAdapter tla = new TestListenerAdapter();40 testng.addListener(tla);41 List<String> suites = Arrays.asList("testng.xml");42 testng.setTestSuites(suites);43 testng.run();44 }45}
setListenerClasses
Using AI Code Generation
1package com.example;2import org.testng.*;3import org.testng.xml.*;4import java.util.*;5public class TestNGSetListenerClasses {6 public static void main(String[] args) {7 TestNG testng = new TestNG();8 testng.setTestClasses(new Class[]{TestNGListenerClass.class});9 testng.setListenerClasses(new Class[]{TestNGListenerClass.class});10 testng.run();11 }12}13package com.example;14import org.testng.*;15public class TestNGListenerClass implements ITestListener {16 public void onTestStart(ITestResult result) {17 System.out.println("Test started: " + result.getName());18 }19 public void onTestSuccess(ITestResult result) {20 System.out.println("Test successful: " + result.getName());21 }22 public void onTestFailure(ITestResult result) {23 System.out.println("Test failed: " + result.getName());24 }25 public void onTestSkipped(ITestResult result) {26 System.out.println("Test skipped: " + result.getName());27 }28 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {29 System.out.println("Test failed but within success percentage: " + result.getName());30 }31 public void onStart(ITestContext context) {32 System.out.println("Test started: " + context.getName());33 }34 public void onFinish(ITestContext context) {35 System.out.println("Test finished: " + context.getName());36 }37}38package com.example;39import org.testng.*;40import org.testng.xml.*;41import java.util.*;42public class TestNGSetListenerClasses {43 public static void main(String[] args) {44 TestNG testng = new TestNG();45 testng.setTestClasses(new Class[]{TestNGListenerClass.class});46 testng.setListenerClasses(new Class[]{TestNGListenerClass.class});47 testng.run();48 }49}50package com.example;51import org.testng.*;52public class TestNGListenerClass implements ITestListener {53 public void onTestStart(ITestResult result) {54 System.out.println("Test started: " + result.getName());
setListenerClasses
Using AI Code Generation
1import org.testng.TestNG;2import java.util.ArrayList;3import java.util.List;4public class TestRunner {5 public static void main(String[] args) {6 TestNG runner = new TestNG();7 List<String> suitefiles = new ArrayList<String>();8 suitefiles.add("testng.xml");9 runner.setTestSuites(suitefiles);10 runner.setListenerClasses(new Class[]{TestNGListener.class});11 runner.run();12 }13}14import org.testng.ITestContext;15import org.testng.ITestListener;16import org.testng.ITestResult;17public class TestNGListener implements ITestListener {18 public void onTestStart(ITestResult result) {19 System.out.println("onTestStart: " + result.getName());20 }21 public void onTestSuccess(ITestResult result) {22 System.out.println("onTestSuccess: " + result.getName());23 }24 public void onTestFailure(ITestResult result) {25 System.out.println("onTestFailure: " + result.getName());26 }27 public void onTestSkipped(ITestResult result) {28 System.out.println("onTestSkipped: " + result.getName());29 }30 public void onTestFailedButWithinSuccessPercentage(ITestResult result) {31 System.out.println("onTestFailedButWithinSuccessPercentage: " + result.getName());32 }33 public void onStart(ITestContext context) {34 System.out.println("onStart: " + context.getName());35 }36 public void onFinish(ITestContext context) {37 System.out.println("onFinish: " + context.getName());38 }39}40import org.testng.annotations.Test;41public class TestNGListenerExample {42 public void testMethod1() {43 System.out.println("testMethod1");44 }45 public void testMethod2()
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!!