Best Testng code snippet using org.testng.xml.XmlSuite.clone
Source:LocalTestNG.java
...182 }183 }184 public static XmlSuite selectiveSuite( XmlSuite suite, String regex )185 {186 XmlSuite newSuite = (XmlSuite)suite.clone();187 newSuite.setParameters( suite.getParameters() );188 Pattern p = Pattern.compile( regex );189 for( XmlTest test : suite.getTests() )190 {191 // find in test name first192 Matcher m = p.matcher( test.getName() );193 if( m.find() )194 {195 newSuite.addTest( test );196 }197 else198 {199 // if not found, look for a class name that is the first class ONLY200 m = p.matcher( test.getXmlClasses().get( 0 ).getName() );201 if( m.find() )202 {203 newSuite.addTest( test );204 }205 }206 }207 return newSuite;208 }209 public static XmlSuite randomizeSuite( XmlSuite suite, int testCount )210 {211 List< XmlTest > tests = suite.getTests();212 Collections.shuffle( tests );213 suite.setTests( (testCount >= tests.size() || testCount == 0) ? tests : tests.subList( 0, testCount ) );214 return suite;215 }216 private static XmlSuite createXmlSuite( String suitefile )217 {218 Parser parser = new Parser( suitefile );219 List< XmlSuite > xmlSuites = new ArrayList<>();220 try221 {222 xmlSuites.addAll( parser.parseToList() );223 }224 catch( ParserConfigurationException | SAXException | IOException e )225 {226 throw new NullPointerException( e.getMessage() );227 }228 if( Utility.isEmpty( xmlSuites ) )229 {230 throw new NullPointerException( "no valid xml suite found in " + suitefile );231 }232 if( xmlSuites.size() == 1 )233 {234 return xmlSuites.get( 0 );235 }236 XmlSuite suite = null;237 try238 {239 suite = XmlSuite.class.cast( xmlSuites.get( 0 ).clone() );240 xmlSuites.remove( 0 );241 }242 catch( ClassCastException e )243 {244 throw e;245 }246 for( XmlSuite remainingSuite : xmlSuites )247 {248 for( XmlTest test : remainingSuite.getTests() )249 {250 suite.addTest( test );251 }252 }253 return suite;254 }255 /**256 * Executes the list of {@link TestNG} instances in sequence one after another257 * @param suite XmlSuite258 * @return True if no problem encountered and False otherwise259 */260 private static boolean singleExecute( XmlSuite suite )261 {262 LOG.info( "Single Execution of TestNG instance" );263 LocalTestNG testNg = new LocalTestNG( LocalCommandLineArgs.instance() );264 testNg.configure();265 List< XmlSuite > suiteList = new ArrayList<>();266 suiteList.add( suite );267 testNg.setXmlSuites( suiteList );268 return testNg.execute();269 }270 /**271 * Executes the list of {@link TestNG} instances in sequence one after another272 * @param suiteName Suite Name273 * @param logPath The Path for Log274 * @param suiteList XmlSuite list275 */276 private static void sequentialExecute( String suiteName, String logPath, List< XmlSuite > suiteList )277 {278 LOG.info( "Sequential Execution of " + suiteList.size() + " suites" );279 for( int i = 0; i < suiteList.size(); ++i )280 {281 String suiteLogPath = logPath + i + File.separator;282 LocalCommandLineArgs.instance().logPath = suiteLogPath;283 // LOG = TestLogger.setupLogger( suiteLogPath, LocalCommandLineArgs.instance().consoleFile, LocalTestNG.class );284 LOG.info( "Executing " + (i + 1) + "/" + suiteList.size() + " \"" + suiteList.get( i ).getName() + "\"" );285 LocalTestNG testNg = new LocalTestNG( LocalCommandLineArgs.instance() );286 List< XmlSuite > tempSuiteList = new ArrayList<>();287 tempSuiteList.add( suiteList.get( i ) );288 testNg.setXmlSuites( tempSuiteList );289 if( !testNg.execute() )290 {291 LOG.warn( "TestNG execution for " + suiteList.get( i ).getName() + " failed" );292 }293 }294 }295 /**296 * Executes the list of {@link TestNG} parallel297 * @param suiteName Suite Name298 * @param logPath The Path for Log299 * @param suiteList XmlSuite list300 * @return True if no problem encountered and False otherwise301 */302 private static boolean parallelExecute( String suiteName, String logPath, List< XmlSuite > suiteList )303 {304 LOG.info( "Parallel Execution of " + suiteList.size() + " TestNG instances" );305 ThreadController.instance();306 for( int i = 0; i < suiteList.size(); ++i )307 {308 TestNGInstance threadInstance = new TestNGInstance( suiteList.get( i ), LOG );309 // delay the other thread to minimize errors in creating selenium clients310 threadInstance.setDelay( (long) (5 * Time.SECOND) * i );311 ThreadController.instance().addTest( threadInstance );312 }313 return ThreadController.instance().execute();314 }315 /**316 * 317 * @param suite Suite object to be split318 * @param splitCount maximum number of test case in a suite319 * @return List of split suite object with maximum test case count of Parameter <splitCount>320 */321 public static List< XmlSuite > split( XmlSuite suite, int splitCount )322 {323 LOG.info( "Splitting " + suite.getName() + " into suites with maximum of " + splitCount + " test case" );324 List< XmlSuite > resultList = new ArrayList<>();325 String name = suite.getName();326 try327 {328 List< List< XmlTest > > testLists = Lists.partition( suite.getTests(), splitCount );329 LOG.info( "Suite was Split into " + testLists.size() + " suites" );330 for( List< XmlTest > testList : testLists )331 {332 XmlSuite suiteClone = XmlSuite.class.cast( suite.clone() );333 suiteClone.setParameters( suite.getParameters() );334 resultList.add( suiteClone );335 suiteClone.setName( name + " " + resultList.size() + "/" + testLists.size() );336 suiteClone.setTests( testList );337 LOG.info( "Suite \"" + suiteClone.getName() + "\" was has " + suiteClone.getTests().size() + " test cases" );338 }339 }340 catch( ClassCastException e )341 {342 LOG.error( e.getClass().getSimpleName() + " found with " + e.getMessage() + ". Processing " + resultList.size() + " suites", e );343 }344 return resultList;345 }346 private static XmlTest getMaximumTest( List< XmlTest > tests )347 {348 int maximum = 0;349 XmlTest maxTest = null;350 for( XmlTest test : tests )351 {352 int parameterSize = test.getLocalParameters().size();353 if( parameterSize > maximum )354 {355 maximum = parameterSize;356 maxTest = test;357 }358 }359 return maxTest;360 }361 private static XmlTest getMinimumTest( List< XmlTest > tests )362 {363 int minimum = Integer.MAX_VALUE;364 XmlTest minTest = null;365 for( XmlTest test : tests )366 {367 int next = Integer.valueOf( test.getName().substring( test.getName().lastIndexOf( "_" ) + 1, test.getName().length() ) );368 if( next < minimum )369 {370 minimum = next;371 minTest = test;372 }373 }374 return minTest;375 }376 public static XmlSuite reviewSuite( XmlSuite suite )377 {378 // get the first test case in each test scenario by Regex379 String firstTestCases = "[A-Z]{2,8}_[A-Z0-9]{2,4}[_]{0,1}[0-9]{0,3}";380 XmlSuite firstTestSuite = selectiveSuite( suite, firstTestCases );381 XmlSuite newSuite = (XmlSuite)suite.clone();382 newSuite.setParameters( suite.getParameters() );383 List< String > scenario = new ArrayList<>();384 for( XmlTest test : firstTestSuite.getTests() )385 {386 // get the scenario name by getting the string before _01 for each first test case387 String scenarioName = StringUtils.substringBeforeLast( test.getName(), "_" ) + "_";388 if( scenario.contains( scenarioName ) )389 {390 continue;391 }392 else393 {394 scenario.add( scenarioName );395 }...
Source:GenerateFailedReports.java
...41 generateFailureSuite(suites.get(i).getXmlSuite(), suites.get(i), outputDirectory);42 }43 }44 protected void generateFailureSuite(XmlSuite xmlSuite, ISuite suite, String outputDir) {45 XmlSuite failedSuite = (XmlSuite) xmlSuite.clone();46 failedSuite.setName("Failed suite [" + xmlSuite.getName() + "]");47 m_xmlSuite= failedSuite;48 Map<String, XmlTest> xmlTests= Maps.newHashMap();49 for(XmlTest xmlT: xmlSuite.getTests()) {50 xmlTests.put(xmlT.getName(), xmlT);51 }52 Map<String, ISuiteResult> results = suite.getResults();53 for(Map.Entry<String, ISuiteResult> entry : results.entrySet()) {54 ISuiteResult suiteResult = entry.getValue();55 ITestContext testContext = suiteResult.getTestContext();56 generateXmlTest(suite,57 xmlTests.get(testContext.getName()),58 testContext,59 testContext.getFailedTests().getAllResults(),...
Source:XmlParser.java
...44 }45 return xmlSuites;46 }47 private void setTestsInSuites(XmlSuite xmlSuite) throws NavException, XPathParseException, XPathEvalException {48// VTDNav cloneNav = vn.cloneNav();49 int nodeinfoIds = vn.getAttrVal("nodeinfos");50// cloneNav.toElement(VTDNav.ROOT);51// int i = cloneNav.getText();52// AutoPilot ap = new AutoPilot(vn);53// ap.selectElement("testexecutioninfos");54// int index = cloneNav.getAttrVal("ids");55 List<String> ids = Arrays.asList(vn.toString(nodeinfoIds).trim().split("\\s*,\\s*"));56 VTDNav cloneNav = vn.cloneNav();57 for (String id : ids) {58 HashMap<String, String> nodeInfo = new HashMap<String, String>(8); //getGridInfo().getNodeinfo().get(id);59 AutoPilot ap = getAutoPilot(cloneNav, "/automation/gridinfo/nodeinfos/nodeinfo[@id='"+ id +"']");60 if (ap.evalXPath() != -1) {61 nodeInfo.put("appurl", getAppUrl(cloneNav));62 nodeInfo.put("suite", xmlSuite.getName());63 if (cloneNav.toElement(VTDNav.FC, "nodeurl")) {64 int index = cloneNav.getText();65 nodeInfo.put("nodeurl", cloneNav.toString(index));66 }67 if (cloneNav.toElement(VTDNav.NS, "platform")) {68 int index = cloneNav.getText();69 nodeInfo.put("platform", vn.toString(index));70 }71 if (cloneNav.toElement(VTDNav.NS, "browser")) {72 int index = cloneNav.getText();73 List<String> browsers = Arrays.asList(vn.toString(index).trim().split("\\s*,\\s*"));74 for (String browser : browsers) {75 System.out.println("browser... " + browser);76 nodeInfo.put("browser", browser);77 XmlTest xmlTest = new XmlTest(xmlSuite);78 xmlTest.setParameters((Map<String, String>) nodeInfo.clone());79 List<XmlClass> classes = new ArrayList<XmlClass>();80 XmlClass xmlClass = new XmlClass("com.photon.phresco.automation.AutomationFactory");81 classes.add(xmlClass);82 xmlTest.setXmlClasses(classes) ;83 }84 }85 }86 }87 }88 89 /*private List<XmlClass> getClasses() throws NavException {90 AutoPilot ap = new AutoPilot(vn);91 ap.selectElement("testcase");92 int index = vn.getAttrVal("name");93 String testCaseName = vn.toString(index);94 AutoPilot apSteps = new AutoPilot(vn);95 ap.selectElement("step");96 while (ap.iterate()) {97 }98 }*/99 public List<TestCase> getTestCases(String suite) throws NavException, XPathParseException, XPathEvalException {100 101 vn.toElement(VTDNav.ROOT);102 AutoPilot ap = getAutoPilot(vn, "/automation/testsuites/testsuite[@name='"+suite +"']");103 ap.selectElement("testcase");104 List<TestCase> testCases = new ArrayList<TestCase>(8);105 while (ap.iterate()) {106 int indexId = vn.getAttrVal("name");107 String testCaseName = vn.toString(indexId);108 AutoPilot apSteps = new AutoPilot(vn);109 apSteps.selectElement("step");110 List<Step> steps = new ArrayList<Step>(8);111 while (apSteps.iterate()) {112 int index = vn.getText();113 String stepId = vn.toString(index);114 Step step = getTestStep(stepId);115 steps.add(step);116 }117 TestCase testCase = new TestCase(testCaseName, steps);118 testCases.add(testCase);119 }120 return testCases;121 }122 public String getAppUrl(VTDNav vn) throws NavException, XPathParseException, XPathEvalException {123 VTDNav cloneNav = vn.cloneNav();124 cloneNav.toElement(VTDNav.ROOT);125 AutoPilot ap = getAutoPilot(cloneNav, "/automation/appurl");126 if (ap.evalXPath() != -1) {127 int index = cloneNav.getText();128 return cloneNav.toString(index);129 }130 return null;131 }132 private AutoPilot getAutoPilot(VTDNav vn, String xpath) throws XPathParseException {133 AutoPilot ap = new AutoPilot(vn);134 ap.selectXPath(xpath);135 return ap;136 }137 @SuppressWarnings("unchecked")138 public GridInfo getGridInfo() throws NavException, XPathParseException, XPathEvalException {139 VTDNav cloneNav = vn.cloneNav();140 cloneNav.toElement(VTDNav.ROOT);141 AutoPilot ap = getAutoPilot(cloneNav, "/automation/gridinfo");142 GridInfo gridInfo = new GridInfo();143 if (ap.evalXPath() != -1) {144 if( cloneNav.toElement(VTDNav.FC, "huburl")) {145 int index = cloneNav.getText();146 gridInfo.setHubURL(cloneNav.toString(index));147 }148 cloneNav.toElement(VTDNav.NS, "nodeinfos");149 AutoPilot apNodeInfo = new AutoPilot(cloneNav);150 Map<String, HashMap<String, String>> nodeInfos = new HashMap<String, HashMap<String, String>>(8);151 apNodeInfo.selectElement("nodeinfo");152 while (apNodeInfo.iterate()) {153 String id="";154 HashMap<String, String> params = new HashMap<String, String>(8);155 /*if (cloneNav.toElement(VTDNav.FC, "id")) {156 int index = cloneNav.getText();157 id = cloneNav.toString(index);158 }*/159 if (cloneNav.toElement(VTDNav.NS, "nodeurl")) {160 int index = cloneNav.getText();161 params.put("nodeurl", cloneNav.toString(index));162 }163 if (cloneNav.toElement(VTDNav.NS, "platform")) {164 int index = cloneNav.getText();165 params.put("platform", vn.toString(index));166 }167 if (cloneNav.toElement(VTDNav.NS, "browser")) {168 int index = cloneNav.getText();169 List<String> browsers = Arrays.asList(vn.toString(index).trim().split("\\s*,\\s*"));170 for (String browser : browsers) {171 params.put("browser", browser);172 nodeInfos.put(id+browser, (HashMap<String, String>) params.clone());173 }174 }175 }176 gridInfo.setNodeinfo(nodeInfos);177 }178 return gridInfo;179 }180 public Map<String, Param> getTextExecInfo() throws NavException, XPathParseException, XPathEvalException {181 vn.toElement(VTDNav.ROOT);182 AutoPilot ap = getAutoPilot(vn, "/automation/testexecutioninfos");183 Map<String, Param> params = new HashMap<String, Param>(8);184 if (ap.evalXPath() != -1) {185 AutoPilot apParam = new AutoPilot(vn);186 apParam.selectElement("param");187 while (apParam.iterate()){188 Param nodeInfo = new Param();189 if (vn.toElement(VTDNav.FC, "id")) {190 int index = vn.getText();191 nodeInfo.setId(vn.toString(index));192 }193 if (vn.toElement(VTDNav.NS, "platform")) {194 int index = vn.getText();195 nodeInfo.setPlatform(vn.toString(index));196 }197 if (vn.toElement(VTDNav.NS, "browser")) {198 int index = vn.getText();199 nodeInfo.setBrowser(vn.toString(index));200 }201 params.put(nodeInfo.getId(), nodeInfo);202 }203 }204 return params;205 }206 public Step getTestStep(String stepId) throws NavException, XPathParseException, XPathEvalException {207 VTDNav cloneNav = vn.cloneNav();208 cloneNav.toElement(VTDNav.ROOT);209 AutoPilot ap = getAutoPilot(cloneNav, "/automation/teststeps/step[@id='"+ stepId +"']");210 Step step = new Step();211 if (ap.evalXPath() != -1) {212 int index = cloneNav.getAttrVal("id");213 step.setId(cloneNav.toString(index));214 index = cloneNav.getAttrVal("name");215 step.setName(cloneNav.toString(index));216 index = cloneNav.getAttrVal("action");217 step.setAction(cloneNav.toString(index));218 index = cloneNav.getAttrVal("type");219 if (index != -1) {220 step.setType(cloneNav.toString(index));221 }222 index = cloneNav.getAttrVal("value");223 if (index != -1) {224 step.setValue(cloneNav.toString(index));225 }226 }227 return step;228 }229 230}...
Source:TestNamesMatcherTest.java
...74 public void testCloneIfContainsTestsWithNamesMatchingAnyWithoutMatch() {75 XmlSuite xmlSuite = createDummySuiteWithTestNamesAs("test1", "test2");76 TestNamesMatcher testNamesMatcher =77 new TestNamesMatcher(xmlSuite, Collections.singletonList("test3"));78 List<XmlSuite> clonedSuites = testNamesMatcher.getSuitesMatchingTestNames();79 if (!CollectionUtils.hasElements(clonedSuites)) {80 throw new TestNGException(81 "The test(s) <" + Collections.singletonList("test3").toString() + "> cannot be found.");82 }83 }84 @DataProvider(name = "getTestnames")85 public Object[][] getTestnameToSearchFor() {86 return new Object[][] {87 {"test4", false, false},88 {"test1", true, false},89 {"test5", false, true}90 };91 }92 @DataProvider(name = "getData")93 public Object[][] getTestData() {...
Source:RPATestNG.java
...85 if (tests.size() == 0) {86 return s;87 }88 else {89 XmlSuite result = (XmlSuite) s.clone();90 result.getTests().clear();91 result.getTests().addAll(tests);92 return result;93 }94 }9596 /**97 * æ·è´ ç¶ç±»çæ¹æ³98 */99 private Parser getParser(InputStream is) {100 Parser result = new Parser(is);101 initProcessor(result);102 return result;103 }
...
Source:TestNGTestUnit.java
...63 }64 private void executeInForeignLoader(ResultCollector rc, ClassLoader loader) {65 @SuppressWarnings("unchecked")66 Callable<List<String>> e = (Callable<List<String>>) IsolationUtils67 .cloneForLoader(new ForeignClassLoaderTestNGExecutor(createSuite()),68 loader);69 try {70 List<String> q = e.call();71 Events.applyEvents(q, rc, this.getDescription());72 } catch (Exception ex) {73 throw Unchecked.translateCheckedException(ex);74 }75 }76 private void executeInCurrentLoader(final ResultCollector rc) {77 final ITestListener listener = new TestNGAdapter(this.clazz,78 this.getDescription(), rc);79 final XmlSuite suite = createSuite();80 TESTNG.setDefaultSuiteName(suite.getName());81 TESTNG.setXmlSuites(Collections.singletonList(suite));...
Source:MethodGroupMappingHolder.java
...67 inited = true;68 }69 }70 public static void init(ITestContext context) {71 MethodGroupMappingHolder.xmlSuite = (XmlSuite) ((TestRunner) context).getTest().getSuite().clone();72 allTestngMethods = context.getSuite().getAllMethods();73 inited = false;74 }75}...
Source:TestNamesMatcher.java
...5import org.testng.xml.XmlSuite;6import org.testng.xml.XmlTest;7/** The class to work with "-testnames" */8public final class TestNamesMatcher {9 private final List<XmlSuite> cloneSuites = Lists.newArrayList();10 private final List<String> matchedTestNames = Lists.newArrayList();11 private final List<XmlTest> matchedTests = Lists.newArrayList();12 private final List<String> testNames;13 public TestNamesMatcher(XmlSuite xmlSuite, List<String> testNames) {14 this.testNames = testNames;15 cloneIfContainsTestsWithNamesMatchingAny(xmlSuite, this.testNames);16 }17 /**18 * Recursive search the given testNames from the current {@link XmlSuite} and its child suites.19 *20 * @param xmlSuite The {@link XmlSuite} to work with.21 * @param testNames The list of testnames to iterate through22 */23 private void cloneIfContainsTestsWithNamesMatchingAny(XmlSuite xmlSuite, List<String> testNames) {24 if (testNames == null || testNames.isEmpty()) {25 throw new TestNGException("Please provide a valid list of names to check.");26 }27 // Start searching in the current suite.28 addIfNotNull(cloneIfSuiteContainTestsWithNamesMatchingAny(xmlSuite));29 // Search through all the child suites.30 for (XmlSuite suite : xmlSuite.getChildSuites()) {31 cloneIfContainsTestsWithNamesMatchingAny(suite, testNames);32 }33 }34 public List<XmlSuite> getSuitesMatchingTestNames() {35 return cloneSuites;36 }37 /** Getting miss-matched testNames */38 public List<String> getMissMatchedTestNames() {39 List<String> tmpTestNames = Lists.newArrayList();40 tmpTestNames.addAll(testNames);41 tmpTestNames.removeIf(matchedTestNames::contains);42 return tmpTestNames;43 }44 public List<XmlTest> getMatchedTests() {45 return matchedTests;46 }47 private void addIfNotNull(XmlSuite xmlSuite) {48 if (xmlSuite != null) {49 cloneSuites.add(xmlSuite);50 }51 }52 private XmlSuite cloneIfSuiteContainTestsWithNamesMatchingAny(XmlSuite suite) {53 List<XmlTest> tests = Lists.newLinkedList();54 for (XmlTest xt : suite.getTests()) {55 if (xt.nameMatchesAny(testNames)) {56 tests.add(xt);57 matchedTestNames.add(xt.getName());58 matchedTests.add(xt);59 }60 }61 if (tests.isEmpty()) {62 return null;63 }64 return cleanClone(suite, tests);65 }66 private static XmlSuite cleanClone(XmlSuite xmlSuite, List<XmlTest> tests) {67 XmlSuite result = (XmlSuite) xmlSuite.clone();68 result.getTests().clear();69 result.getTests().addAll(tests);70 return result;71 }72}...
clone
Using AI Code Generation
1XmlSuite suite = new XmlSuite();2suite.setName("MySuite");3suite.setVerbose(1);4suite.setParallel(XmlSuite.ParallelMode.METHODS);5suite.setThreadCount(2);6XmlTest test = new XmlTest(suite);7test.setName("MyTest");8test.setPreserveOrder("true");9test.setParallel(XmlSuite.ParallelMode.METHODS);10test.setThreadCount(2);11Map<String, String> params = new HashMap<String, String>();12params.put("browser", "firefox");13test.setParameters(params);14List<XmlClass> classes = new ArrayList<XmlClass>();15classes.add(new XmlClass("test.Test1"));16classes.add(new XmlClass("test.Test2"));17test.setXmlClasses(classes);18List<XmlSuite> suites = new ArrayList<XmlSuite>();19suites.add(suite);20TestNG tng = new TestNG();21tng.setXmlSuites(suites);22tng.run();
clone
Using AI Code Generation
1XmlSuite xmlSuite = new XmlSuite();2xmlSuite.setParallel(ParallelMode.METHODS);3xmlSuite.setThreadCount(10);4xmlSuite.setVerbose(1);5xmlSuite.setPreserveOrder(true);6xmlSuite.setName("TestSuite");7xmlSuite.setFileName("testng.xml");8XmlTest xmlTest = new XmlTest(xmlSuite);9xmlTest.setName("Test");10xmlTest.setPreserveOrder(true);11List<XmlClass> testClasses = new ArrayList<XmlClass>();12testClasses.add(new XmlClass("com.test.SampleTest"));13xmlTest.setXmlClasses(testClasses);14List<XmlInclude> testMethods = new ArrayList<XmlInclude>();15testMethods.add(new XmlInclude("testMethod1"));16testMethods.add(new XmlInclude("testMethod2"));17testMethods.add(new XmlInclude("testMethod3"));18testMethods.add(new XmlInclude("testMethod4"));19testMethods.add(new XmlInclude("testMethod5"));20testClasses.get(0).setIncludedMethods(testMethods);21List<String> groups = new ArrayList<String>();22groups.add("sampleGroup");23xmlTest.setIncludedGroups(groups);24List<XmlTest> xmlTests = new ArrayList<XmlTest>();25xmlTests.add(xmlTest);26xmlSuite.setTests(xmlTests);27testNG.setXmlSuites(Arrays.asList(xmlSuite));28testNG.run();
clone
Using AI Code Generation
1XmlSuite suite = new XmlSuite();2suite.setName("My Suite");3XmlTest test = new XmlTest(suite);4test.setName("My Test");5XmlClass testClass = new XmlClass("test.TestClass");6XmlInclude testMethod = new XmlInclude("testMethod");7testClass.getIncludedMethods().add(testMethod);8List<XmlClass> testClasses = new ArrayList<>();9testClasses.add(testClass);10test.setXmlClasses(testClasses);11testClass = new XmlClass("test.TestClass2");12testMethod = new XmlInclude("testMethod2");13testClass.getIncludedMethods().add(testMethod);14testClasses = new ArrayList<>();15testClasses.add(testClass);16test.setXmlClasses(testClasses);17testClass = new XmlClass("test.TestClass3");18testMethod = new XmlInclude("testMethod3");19testClass.getIncludedMethods().add(testMethod);20testClasses = new ArrayList<>();21testClasses.add(testClass);22test.setXmlClasses(testClasses);23List<XmlSuite> suites = new ArrayList<>();24suites.add(suite);25TestNG tng = new TestNG();26tng.setXmlSuites(suites);27tng.run();28XmlSuite suite = new XmlSuite();29suite.setName("My Suite");30XmlTest test = new XmlTest(suite);31test.setName("My Test");32XmlClass testClass = new XmlClass("test.TestClass");33XmlInclude testMethod = new XmlInclude("testMethod");34testClass.getIncludedMethods().add(testMethod);35List<XmlClass> testClasses = new ArrayList<>();36testClasses.add(testClass);37test.setXmlClasses(testClasses);38testClass = new XmlClass("test.TestClass2");39testMethod = new XmlInclude("testMethod2");40testClass.getIncludedMethods().add(testMethod);41testClasses = new ArrayList<>();42testClasses.add(testClass);
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!!