How to use setParallel method of org.testng.TestNG class

Best Testng code snippet using org.testng.TestNG.setParallel

Source:ReporterTest.java Github

copy

Full Screen

...115 List<String> testList = new ArrayList<>();116 117 XmlSuite suite = new XmlSuite();118 suite.setName("TmpSuite");119 suite.setParallel(ParallelMode.NONE);120 suite.setFileName(SeleniumTestsContextManager.getRootPath() + "/data/core/testng/testLoggging.xml");121 Map<String, String> suiteParameters = new HashMap<>();122 suiteParameters.put("softAssertEnabled", "false");123 suite.setParameters(suiteParameters);124// suite.setConfigFailurePolicy(FailurePolicy.CONTINUE);125 List<XmlSuite> suites = new ArrayList<XmlSuite>();126 suites.add(suite);127 128 129 if (threadCount > 1) {130 suite.setThreadCount(threadCount);131 suite.setParallel(parallelMode);132 }133 134 for (String testClass: testClasses) {135 XmlTest test = new XmlTest(suite);136 test.setName(String.format("%s_%d", testClass.substring(testClass.lastIndexOf(".") + 1), new Random().nextInt()));137 testList.add(test.getName());138 test.addParameter(SeleniumTestsContext.BROWSER, "none");139 List<XmlClass> classes = new ArrayList<XmlClass>();140 XmlClass xmlClass = new XmlClass(testClass);141 if (methods.length > 0) {142 List<XmlInclude> includes = new ArrayList<>();143 for (String method: methods) {144 includes.add(new XmlInclude(method));145 }146 xmlClass.setIncludedMethods(includes);147 }148 classes.add(xmlClass);149 test.setXmlClasses(classes) ;150 } 151 152 TestNG tng = new TestNG(false);153 tng.setXmlSuites(suites);154 tng.setOutputDirectory(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory());155 tng.run(); 156 157 return testList;158 }159 160 public static TestNG executeMultiSuites(String[] testClasses, String[] methods) throws IOException {161162 List<XmlSuite> suites = new ArrayList<XmlSuite>();163 164 XmlSuite suite = new XmlSuite();165 suite.setName("TmpSuite");166 suite.setParallel(ParallelMode.NONE);167 suite.setFileName("/home/test/seleniumRobot/data/core/testng/testLoggging.xml");168 Map<String, String> suiteParameters = new HashMap<>();169 suiteParameters.put("softAssertEnabled", "false");170 suite.setParameters(suiteParameters);171 suites.add(suite);172 173 XmlSuite suite2 = new XmlSuite();174 suite2.setName("TmpSuite2");175 suite2.setParallel(ParallelMode.NONE);176 suite2.setFileName("/home/test/seleniumRobot/data/core/testng/testLoggging2.xml");177 Map<String, String> suiteParameters2 = new HashMap<>();178 suiteParameters2.put("softAssertEnabled", "false");179 suite2.setParameters(suiteParameters2);180 suites.add(suite2);181 182 for (String testClass: testClasses) {183 XmlTest test = new XmlTest(suite);184 test.setName(String.format("%s_%d", testClass.substring(testClass.lastIndexOf(".") + 1), new Random().nextInt()));185 test.addParameter(SeleniumTestsContext.BROWSER, "none");186 List<XmlClass> classes = new ArrayList<XmlClass>();187 XmlClass xmlClass = new XmlClass(testClass);188 if (methods.length > 0) {189 List<XmlInclude> includes = new ArrayList<>();190 for (String method: methods) {191 includes.add(new XmlInclude(method));192 }193 xmlClass.setIncludedMethods(includes);194 }195 classes.add(xmlClass);196 test.setXmlClasses(classes) ;197 198 XmlTest test2 = new XmlTest(suite2);199 test2.setName(String.format("%s_%d", testClass.substring(testClass.lastIndexOf(".") + 1), new Random().nextInt()));200 test2.addParameter(SeleniumTestsContext.BROWSER, "none");201 List<XmlClass> classes2 = new ArrayList<XmlClass>();202 XmlClass xmlClass2 = new XmlClass(testClass);203 if (methods.length > 0) {204 List<XmlInclude> includes = new ArrayList<>();205 for (String method: methods) {206 includes.add(new XmlInclude(method));207 }208 xmlClass2.setIncludedMethods(includes);209 }210 classes2.add(xmlClass2);211 test2.setXmlClasses(classes2) ;212 } 213 214 TestNG tng = new TestNG(false);215 tng.setXmlSuites(suites);216 tng.setOutputDirectory(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory());217 tng.run(); 218 219 return tng;220 }221 222 /**223 * Execute SeleniumTestPlan and cucumber tests224 * Each test method is put in its own TestNG test225 * @param threadCount226 * @param testMethods227 * @param cucumberTests228 * @return229 * @throws IOException230 */231 public TestNG executeSubTest(int threadCount, String[] testMethods, String cucumberTests, String group) throws IOException {232233 XmlSuite suite = new XmlSuite();234 suite.setName("TmpSuite");235 suite.setParallel(ParallelMode.NONE);236 suite.setFileName("/home/test/seleniumRobot/testng/testLoggging.xml");237 Map<String, String> suiteParameters = new HashMap<>();238 suiteParameters.put("softAssertEnabled", "false");239 suiteParameters.put("cucumberPackage", "com.seleniumtests");240 suite.setParameters(suiteParameters);241 List<XmlSuite> suites = new ArrayList<XmlSuite>();242 suites.add(suite);243 244 if (threadCount > 1) {245 suite.setThreadCount(threadCount);246 suite.setParallel(XmlSuite.ParallelMode.TESTS);247 }248 249 // TestNG tests250 for (String testMethod: testMethods) {251 String className = testMethod.substring(0, testMethod.lastIndexOf("."));252 String methodName = testMethod.substring(testMethod.lastIndexOf(".") + 1);253254 XmlTest test = new XmlTest(suite);255 test.setName(String.format("%s_%d", methodName, new Random().nextInt()));256 257 if (group != null) {258 test.addIncludedGroup(group);259 }260 261 test.addParameter(SeleniumTestsContext.BROWSER, "none");262 List<XmlClass> classes = new ArrayList<XmlClass>();263 XmlClass xmlClass = new XmlClass(className);264 265 List<XmlInclude> include = new ArrayList<>();266 include.add(new XmlInclude(methodName));267 xmlClass.setIncludedMethods(include);268 classes.add(xmlClass);269 test.setXmlClasses(classes) ;270 } 271 272 // cucumber tests273 if (!cucumberTests.isEmpty()) {274 XmlTest test = new XmlTest(suite);275 test.setName(String.format("cucumberTest_%d", new Random().nextInt()));276 XmlPackage xmlPackage = new XmlPackage("com.seleniumtests.core.runner.*");277 test.setXmlPackages(Arrays.asList(xmlPackage));278 Map<String, String> parameters = new HashMap<>();279 parameters.put("cucumberTests", cucumberTests);280 parameters.put("cucumberTags", "");281 test.setParameters(parameters);282 }283 284 TestNG tng = new TestNG(false);285 tng.setXmlSuites(suites);286 tng.setOutputDirectory(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory());287 tng.run(); 288 289 return tng;290 }291 292 /**293 * 294 * @param cucumberTests cucumber test param as it would be passed in XML file295 * @return296 * @throws IOException 297 */298 public static XmlSuite executeSubCucumberTests(String cucumberTests, int threadCount) throws IOException {299300 XmlSuite suite = new XmlSuite();301 suite.setName("TmpSuite");302 suite.setFileName("/home/test/seleniumRobot/testng/testLoggging.xml");303 Map<String, String> suiteParameters = new HashMap<>();304 suiteParameters.put("cucumberPackage", "com.seleniumtests");305 suiteParameters.put("softAssertEnabled", "false");306 suite.setParameters(suiteParameters);307 List<XmlSuite> suites = new ArrayList<XmlSuite>();308 suites.add(suite);309 310311 if (threadCount > 1) {312 suite.setThreadCount(threadCount);313 suite.setParallel(XmlSuite.ParallelMode.METHODS);314 }315 316 XmlTest test = new XmlTest(suite);317 test.setName(String.format("cucumberTest_%d", new Random().nextInt()));318 XmlPackage xmlPackage = new XmlPackage("com.seleniumtests.core.runner.*");319 test.setXmlPackages(Arrays.asList(xmlPackage));320 Map<String, String> parameters = new HashMap<>();321 parameters.put("cucumberTests", cucumberTests);322 parameters.put("cucumberTags", "");323 test.setParameters(parameters);324 325 TestNG tng = new TestNG(false);326 tng.setXmlSuites(suites);327 tng.setOutputDirectory(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory()); ...

Full Screen

Full Screen

Source:Runner.java Github

copy

Full Screen

...87 }88 //parallel in suite89 private static void setSuiteParallelizationType(XmlSuite suite) {90 if (TESTNG_PARALLELIZATION_MODE == null) {91 suite.setParallel(XmlSuite.ParallelMode.NONE);92 return;93 }94 String parallelMode = TESTNG_PARALLELIZATION_MODE.toLowerCase().trim();95 switch (parallelMode) {96 case "classes":97 suite.setParallel(XmlSuite.ParallelMode.CLASSES);98 break;99 case "methods":100 suite.setParallel(XmlSuite.ParallelMode.METHODS);101 break;102 case "tests":103 suite.setParallel(XmlSuite.ParallelMode.TESTS);104 break;105 case "instances":106 suite.setParallel(XmlSuite.ParallelMode.INSTANCES);107 break;108 default:109 suite.setParallel(XmlSuite.ParallelMode.NONE);110 }111 }112 // thread count in suite113 private static void setSuiteThreadCount(XmlSuite suite){114 if (TESTNG_THREADS_QTY == null) {115 suite.setThreadCount(MIN_TESTNG_THREADS);116 return;117 }118 try {119 int threadQty = Integer.parseInt(TESTNG_THREADS_QTY);120 if (threadQty<MIN_TESTNG_THREADS){121 threadQty = MIN_TESTNG_THREADS;122 } else if (threadQty > MAX_TESTNG_THREADS){123 threadQty = MAX_TESTNG_THREADS;...

Full Screen

Full Screen

Source:ThreadAffinityTest.java Github

copy

Full Screen

...24 }25 @Test(dataProvider = "dp1")26 public void testThreadAffinity(Class<?>... classes) {27 XmlSuite xmlsuite = createXmlSuite("test_suite");28 xmlsuite.setParallel(XmlSuite.ParallelMode.CLASSES);29 xmlsuite.setThreadCount(6);30 createXmlTest(xmlsuite, "Test 1", classes);31 TestNG testng = create(xmlsuite);32 testng.setVerbose(2);33 LogGatheringListener listener = new LogGatheringListener();34 testng.addListener(listener);35 testng.run();36 assertThat(listener.getLog()).hasSize(2);37 }38 @Test(dataProvider = "dp2")39 public void testThreadAffinityAcrossTests(XmlSuite.ParallelMode mode, int size) {40 XmlSuite xmlsuite = createXmlSuite("test_suite");41 xmlsuite.setParallel(XmlSuite.ParallelMode.TESTS);42 xmlsuite.setThreadCount(6);43 createXmlTest(xmlsuite, "Test_1", PriorityTestSample1.class, PriorityTestSample2.class).setParallel(mode);44 createXmlTest(xmlsuite, "Test_2", PriorityTestSample1.class,PriorityTestSample2.class).setParallel(mode);45 TestNG testng = create(xmlsuite);46 testng.setVerbose(2);47 LogGatheringListener listener = new LogGatheringListener();48 testng.addListener(listener);49 testng.run();50 assertThat(listener.getLog()).hasSize(size);51 }52 @DataProvider(name = "dp2")53 public Object[][] createTestData() {54 return new Object[][] {55 {XmlSuite.ParallelMode.NONE, 2},56 {XmlSuite.ParallelMode.CLASSES, 4}57 };58 }59 @DataProvider(name = "dp1")60 public Object[][] getData() {61 return new Object[][] {62 {PriorityTestSample1.class, PriorityTestSample2.class},63 {MethodDependenciesSample1.class, MethodDependenciesSample2.class}64 };65 }66 @Test(description = "GITHUB-2321")67 public void testThreadAffinityInFactoryInstances() {68 ParallelMode mode = ParallelMode.INSTANCES;69 XmlSuite xmlsuite = createXmlSuite("test_suite");70 xmlsuite.setParallel(mode);71 xmlsuite.setThreadCount(6);72 createXmlTest(xmlsuite, "Test_1", TestMultipleInstance.class).setParallel(mode);73 TestNG testng = create(xmlsuite);74 testng.setVerbose(2);75 testng.run();76 Assertions.assertThat(testng.getStatus()).isEqualTo(0);77 }78 @Test(description = "GITHUB-2110")79 public void ensureNoNPEIsThrown() {80 XmlSuite xmlsuite = createXmlSuite("2110_suite");81 xmlsuite.setParallel(ParallelMode.CLASSES);82 xmlsuite.setThreadCount(50);83 createXmlTest(xmlsuite, "2110_test", TestClass.class);84 TestNG testng = create(xmlsuite);85 testng.setVerbose(2);86 testng.run();87 assertThat(TestClass.getThreadIds()).hasSize(1);88 }89 @AfterClass(alwaysRun = true)90 public void teardown() {91 System.setProperty(RuntimeBehavior.TESTNG_THREAD_AFFINITY, "false");92 }93}...

Full Screen

Full Screen

Source:MethodInterceptorTest.java Github

copy

Full Screen

...52 if (useInterceptor) {53 tng.setMethodInterceptor(new FastTestsFirstInterceptor());54 }55 TestListenerAdapter tla = new TestListenerAdapter();56// tng.setParallel("methods");57 tng.addListener(tla);58 tng.run();59 Assert.assertEquals(tla.getPassedTests().size(), 3);60 ITestResult first = tla.getPassedTests().get(0);61 String method = "zzzfast";62 if (useInterceptor) {63 Assert.assertEquals(first.getMethod().getMethodName(), method);64 } else {65 Assert.assertNotSame(first.getMethod().getMethodName(), method);66 }67 }68 @Test69 public void fastShouldRunFirst() {70 testFast(true /* use interceptor */);71 }72 @Test73 public void fastShouldNotRunFirst() {74 testFast(false /* don't use interceptor */);75 }76 @Test77 public void nullMethodInterceptorWorksInTestngXml()78 throws IOException, ParserConfigurationException, SAXException {79 File f = File.createTempFile("testng-tests-", "");80 f.deleteOnExit();81 BufferedWriter bw = new BufferedWriter(new FileWriter(f));82 bw.write(XML);83 bw.close();84 try {85 List<XmlSuite> xmlSuites = new Parser(f.getAbsolutePath()).parseToList();86 TestNG tng = create();87 tng.setXmlSuites(xmlSuites);88 testNullInterceptor(tng);89 }90 catch(Exception ex) {91 ex.printStackTrace();92 }93 }94 @Test(timeOut = 1000)95 public void shouldNotLockUpWithInterceptorThatRemovesMethods() {96 TestNG tng = create(LockUpInterceptorSampleTest.class);97 tng.setParallel(XmlSuite.ParallelMode.METHODS);98 tng.run();99 }100}...

Full Screen

Full Screen

Source:Method_TestNG.java Github

copy

Full Screen

...26 test.setClasses(classes);27 List<XmlTest> tests = new ArrayList<XmlTest>();28 tests.add(test);29 suite.setTests(tests);30 testng.setParallel(ParallelMode.METHODS);31 testng.setThreadCount(3);32 List<XmlSuite> suites = new ArrayList<XmlSuite>();33 suites.add(suite);34 testng.setXmlSuites(suites);35 System.out.println(suite.toXml());36 //testng.run();37 }38 39 public static void runViaClasses(){40 Class[] classes = new Class[]{TestNGMethodSelector.class,DemoClassWithManyMethodsTest.class};41 TestNG testng = new TestNG();42 testng.setParallel(ParallelMode.METHODS);43 testng.setThreadCount(2);44 testng.setTestClasses(classes);45 testng.run();46 }47 48 public static void runXML(){49 TestNG testNG = new TestNG();50 testNG.setVerbose(2);51 testNG.setThreadCount(2);52 testNG.setParallel(ParallelMode.METHODS);53 XmlSuite suite = new XmlSuite();54 suite.setName("TestNG Forum");55 XmlTest test = new XmlTest(suite);56 test.setName("TestNG Test");57 XmlClass clazz = new XmlClass();58 //Since DemoClassWithManyMethods is a nested class, we have to use "$" symbol, else we could have just used59 //getCanonicalName() alone60 61 clazz.setName(DemoClassWithManyMethodsTest.class.getSimpleName());62 clazz.setClass(DemoClassWithManyMethodsTest.class);63 XmlInclude include = new XmlInclude("methodOne_1");64 include.setXmlClass(clazz);65 clazz.setIncludedMethods(Arrays.asList(include));66 test.setXmlClasses(Arrays.asList(clazz));...

Full Screen

Full Screen

Source:IssueTest.java Github

copy

Full Screen

...15 }16 @Test(dataProvider = "dp1")17 public void testThreadAffinity(Class<?>... classes) {18 XmlSuite xmlsuite = createXmlSuite("test_suite");19 xmlsuite.setParallel(XmlSuite.ParallelMode.CLASSES);20 xmlsuite.setThreadCount(6);21 createXmlTest(xmlsuite, "Test 1", classes);22 TestNG testng = create(xmlsuite);23 testng.setVerbose(2);24 LogGatheringListener listener = new LogGatheringListener();25 testng.addListener(listener);26 testng.run();27 assertThat(listener.log).hasSize(2);28 }29 @Test(dataProvider = "dp2")30 public void testThreadAffinityAcrossTests(XmlSuite.ParallelMode mode, int size) {31 XmlSuite xmlsuite = createXmlSuite("test_suite");32 xmlsuite.setParallel(XmlSuite.ParallelMode.TESTS);33 xmlsuite.setThreadCount(6);34 createXmlTest(xmlsuite, "Test_1", PriorityTestSample1.class,PriorityTestSample2.class).setParallel(mode);35 createXmlTest(xmlsuite, "Test_2", PriorityTestSample1.class,PriorityTestSample2.class).setParallel(mode);36 TestNG testng = create(xmlsuite);37 testng.setVerbose(2);38 LogGatheringListener listener = new LogGatheringListener();39 testng.addListener(listener);40 testng.run();41 assertThat(listener.log).hasSize(size);42 }43 @DataProvider(name = "dp2")44 public Object[][] createTestData() {45 return new Object[][] {46 {XmlSuite.ParallelMode.NONE, 2},47 {XmlSuite.ParallelMode.CLASSES, 4}48 };49 }...

Full Screen

Full Screen

Source:TestNgRunner.java Github

copy

Full Screen

...17 // Suite18 XmlSuite suite = new XmlSuite();19 suite.setName("Suite");20 suite.setThreadCount(5);21 suite.setParallel(ParallelMode.TESTS);22 // Test123 XmlTest test = new XmlTest(suite);24 test.setName("FirstTest");25 test.setThreadCount(5);26 test.setParallel(ParallelMode.METHODS);27 // Params28 Map<String, String> params = new HashMap<>();29 params.put("browser", "firefox");30 params.put("playerToAdd", "1272");31 params.put("playerToRemove", "346");32 test.setParameters(params);33 // Classes34 List<XmlClass> classes = new ArrayList<XmlClass>();35 classes.add(new XmlClass("com.parser.selenium.SeleniumGridDockerParser"));36 test.setXmlClasses(classes) ;37 // Test238 XmlTest test2 = new XmlTest(suite);39 test2.setName("SecondTest");40 test2.setThreadCount(5);41 test2.setParallel(ParallelMode.METHODS);42 43 // Params Test244 Map<String, String> params2 = new HashMap<>();45 params2.put("browser", "firefox");46 params2.put("playerToAdd", "1267");47 params2.put("playerToRemove", "965");48 test2.setParameters(params2);49 test2.setXmlClasses(classes) ;50 suites.add(suite);51 TestNG tng = new TestNG();52 tng.setXmlSuites(suites);53 tng.run();54 }55}...

Full Screen

Full Screen

Source:TestNgXml.java Github

copy

Full Screen

...9 10 public void RuntimeTestngXmlfileDistubuted(int Devicecount,String pack){11 XmlSuite suite = new XmlSuite();12 suite.setName("Cucumber Automation");13 suite.setParallel("classes");14 suite.setThreadCount(Devicecount);15 16 XmlTest test = new XmlTest(suite);17 test.setName("Automation");18 List<XmlPackage> packages = new ArrayList<XmlPackage>();19 packages.add(new XmlPackage(pack));20 test.setXmlPackages(packages) ;21 22 List<XmlSuite> suites = new ArrayList<XmlSuite>();23 suites.add(suite);24 TestNG tng = new TestNG();25 tng.setXmlSuites(suites);26 tng.run();27 28 }29 30 public void RuntimeTestngXmlfileParallel(int Devicecount, String pack){31 XmlSuite suite = new XmlSuite();32 suite.setName("Cucumber Automation");33 suite.setParallel("tests");34 suite.setThreadCount(Devicecount);35 36 List<XmlPackage> allPackages = new ArrayList<>();37 XmlPackage eachPackage = new XmlPackage();38 eachPackage.setName(pack);39 allPackages.add(eachPackage);40 41 for(int i=1;i<=Devicecount;i++){42 XmlTest test = new XmlTest(suite);43 test.setName("Automation"+i);44 test.setXmlPackages(allPackages) ;45 }46 47 List<XmlSuite> suites = new ArrayList<XmlSuite>();...

Full Screen

Full Screen

setParallel

Using AI Code Generation

copy

Full Screen

1import org.testng.TestNG;2public class RunTestsInParallel {3 public static void main(String[] args) {4 TestNG runner = new TestNG();5 runner.setTestClasses(new Class[] { TestClass1.class, TestClass2.class });6 runner.setParallel("classes");7 runner.run();8 }9}10[Note]: # (The above code is taken from

Full Screen

Full Screen

setParallel

Using AI Code Generation

copy

Full Screen

1import org.testng.TestNG;2import org.testng.xml.XmlSuite;3import java.util.ArrayList;4import java.util.List;5public class TestNGParallel {6public static void main(String[] args) {7TestNG runner = new TestNG();8XmlSuite suite = new XmlSuite();9suite.setName("TestNG Parallel Suite");10List<String> files = new ArrayList<>();11files.add("C:\\Users\\selenium\\IdeaProjects\\TestNGParallel\\testng.xml");12suite.setSuiteFiles(files);13List<XmlSuite> suites = new ArrayList<>();14suites.add(suite);15runner.setXmlSuites(suites);16runner.setParallel(XmlSuite.ParallelMode.METHODS);17runner.run();18}19}

Full Screen

Full Screen

setParallel

Using AI Code Generation

copy

Full Screen

1import org.testng.TestNG;2TestNG testng = new TestNG();3testng.setParallel("methods");4testng.setThreadCount(5);5testng.setSuiteThreadPoolSize(10);6testng.run();

Full Screen

Full Screen

setParallel

Using AI Code Generation

copy

Full Screen

1TestNG testng = new TestNG();2testng.setParallel(ParallelMode.TESTS);3testng.setOutputDirectory("C:\\test-output");4testng.setTestSuites(Arrays.asList("C:\\testng.xml"));5testng.run();6package com.test;7import org.testng.annotations.Test;8public class Test1 {9 public void test1(){10 System.out.println("Test1");11 }12}13package com.test;14import org.testng.annotations.Test;15public class Test2 {16 public void test2(){17 System.out.println("Test2");18 }19}20 C:\Program Files\Java\jdk1.8.0_111\jre\bin\java.exe -Dfile.encoding=UTF-8 -classpath C:\Users\user\.m2\repository\org\testng\testng\6.14.3\testng-6.14.3.jar;C:\Users\user\.m2\repository\org\beanshell\bsh\2.0b4\bsh-2.0b4.jar;C:\Users\user\.m2\repository\com\beust\jcommander\1.72\jcommander-1.72.jar;C:\Users\user\.m2\repository\org\yaml\snakeyaml\1.17\snakeyaml-1.17.jar;C:\Users\user\.m2\repository\org\apache\ant\ant\1.9.6\ant-1.9.6.jar;C:\Users\user\.m2\repository\org\apache\ant\ant-launcher\1.9.6\ant-launcher-1.9.6.jar;C:\Users\user\.m2\repository\org\apache\ant\ant-junit\1.9.6

Full Screen

Full Screen

setParallel

Using AI Code Generation

copy

Full Screen

1TestNG testng = new TestNG();2testng.setParallel(ParallelMode.METHODS);3testng.setTestClasses(new Class[] { TestClass1.class, TestClass2.class });4testng.run();5XmlSuite suite = new XmlSuite();6suite.setParallel(ParallelMode.METHODS);7XmlTest test = new XmlTest(suite);8test.setName("My test");9List<XmlClass> classes = new ArrayList<XmlClass>();10classes.add(new XmlClass("TestClass1"));11classes.add(new XmlClass("TestClass2"));12test.setXmlClasses(classes);13List<XmlTest> tests = new ArrayList<XmlTest>();14tests.add(test);15suite.setTests(tests);16List<XmlSuite> suites = new ArrayList<XmlSuite>();17suites.add(suite);18testng.setXmlSuites(suites);19testng.run();

Full Screen

Full Screen

setParallel

Using AI Code Generation

copy

Full Screen

1package testng;2import org.testng.TestNG;3public class TestNGParallelExecution {4 public static void main(String[] args) {5 TestNG testng = new TestNG();6 testng.setTestClasses(new Class[] { Test1.class, Test2.class });7 testng.setParallel("methods");8 testng.run();9 }10}11package testng;12import org.testng.annotations.Test;13public class Test1 {14 public void testMethod1() throws InterruptedException {15 System.out.println("Test1 -> testMethod1 -> " + Thread.currentThread().getId());16 Thread.sleep(1000);17 }18 public void testMethod2() throws InterruptedException {19 System.out.println("Test1 -> testMethod2 -> " + Thread.currentThread().getId());20 Thread.sleep(1000);21 }22}23package testng;24import org.testng.annotations.Test;25public class Test2 {26 public void testMethod3() throws InterruptedException {27 System.out.println("Test2 -> testMethod3 -> " + Thread.currentThread().getId());28 Thread.sleep(1000);29 }30 public void testMethod4() throws InterruptedException {31 System.out.println("Test2 -> testMethod4 -> " + Thread.currentThread().getId());32 Thread.sleep(1000);33 }34}

Full Screen

Full Screen

TestNG tutorial

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.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

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.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful