Best Testng code snippet using org.testng.xml.XmlSuite.setExcludedGroups
Source:MyTestExecutor.java
...159 test.setPreserveOrder(false);160 test.addParameter("device", deviceSerail.get(i).getDevice().getUdid());161 test.addParameter("hostName", deviceSerail.get(i).getHostName());162 test.setIncludedGroups(groupsInclude);163 test.setExcludedGroups(groupsExclude);164 List<XmlClass> xmlClasses = writeXmlClass(testcases, methods);165 test.setXmlClasses(xmlClasses);166 }167 writeTestNGFile(suite);168 return suite;169 }170 private List<XmlClass> writeXmlClass(List<String> testcases, Map<String,171 List<Method>> methods) {172 List<XmlClass> xmlClasses = new ArrayList<>();173 for (String className : methods.keySet()) {174 if (className.contains("Test")) {175 if (testcases.size() == 0) {176 xmlClasses.add(createClass(className));177 } else {178 for (String s : testcases) {179 for (String item : items) {180 String testName = item.concat("." + s);181 if (testName.equals(className)) {182 xmlClasses.add(createClass(className));183 }184 }185 }186 }187 }188 }189 return xmlClasses;190 }191 public XmlSuite constructXmlSuiteForDistribution(List<String> tests,192 Map<String, List<Method>> methods,193 String suiteName,194 String category,195 int deviceCount) {196 XmlSuite suite = new XmlSuite();197 suite.setName(suiteName);198 suite.setThreadCount(deviceCount);199 suite.setParallel(ParallelMode.CLASSES);200 suite.setVerbose(2);201 listeners.add("com.appium.manager.AppiumParallelMethodTestListener");202 listeners.add("com.appium.utils.RetryListener");203 include(listeners, LISTENERS);204 suite.setListeners(listeners);205 XmlTest test = new XmlTest(suite);206 test.setName(category);207 test.addParameter("device", "");208 include(groupsExclude, EXCLUDE_GROUPS);209 include(groupsInclude, INCLUDE_GROUPS);210 test.setIncludedGroups(groupsInclude);211 test.setExcludedGroups(groupsExclude);212 List<XmlClass> xmlClasses = writeXmlClass(tests, methods);213 test.setXmlClasses(xmlClasses);214 writeTestNGFile(suite);215 return suite;216 }217 public XmlSuite constructXmlSuiteForDistributionMethods(List<String> tests,218 Map<String, List<Method>> methods,219 String suiteName,220 String category,221 int deviceCount) {222 include(groupsInclude, INCLUDE_GROUPS);223 XmlSuite suite = new XmlSuite();224 suite.setName(suiteName);225 suite.setThreadCount(deviceCount);226 suite.setDataProviderThreadCount(deviceCount);227 suite.setVerbose(2);228 suite.setParallel(ParallelMode.METHODS);229 listeners.add("com.appium.manager.AppiumParallelMethodTestListener");230 listeners.add("com.appium.utils.RetryListener");231 include(listeners, LISTENERS);232 suite.setListeners(listeners);233 CreateGroups createGroups = new CreateGroups(tests, methods, category, suite).invoke();234 List<XmlClass> xmlClasses = createGroups.getXmlClasses();235 XmlTest test = createGroups.getTest();236 List<XmlClass> writeXml = createGroups.getWriteXml();237 for (XmlClass xmlClass : xmlClasses) {238 writeXml.add(new XmlClass(xmlClass.getName()));239 test.setClasses(writeXml);240 }241 writeTestNGFile(suite);242 return suite;243 }244 private void writeTestNGFile(XmlSuite suite) {245 try (FileWriter writer = new FileWriter(new File(246 getProperty("user.dir") + PARALLEL_XML_LOCATION))) {247 writer.write(suite.toXml());248 writer.flush();249 } catch (IOException e) {250 e.printStackTrace();251 }252 }253 private void include(List<String> groupsInclude, ConfigFileManager config) {254 String listItems = config.get();255 if (isNotEmpty(listItems)) {256 addAll(groupsInclude, listItems.split("\\s*,\\s*"));257 }258 }259 private XmlClass createClass(String className) {260 XmlClass clazz = new XmlClass();261 clazz.setName(className);262 return clazz;263 }264 private List<XmlInclude> constructIncludes(List<Method> methods) {265 List<XmlInclude> includes = new ArrayList<>();266 for (Method m : methods) {267 includes.add(new XmlInclude(m.getName()));268 }269 return includes;270 }271 public Map<String, List<Method>> createTestsMap(Set<Method> methods) {272 Map<String, List<Method>> testsMap = new HashMap<>();273 methods.forEach(method -> {274 List<Method> methodsList = testsMap.computeIfAbsent(275 method.getDeclaringClass().getPackage().getName()276 + "." + method.getDeclaringClass()277 .getSimpleName(), k -> new ArrayList<>());278 methodsList.add(method);279 });280 return testsMap;281 }282 private void deleteOutputDirectory() {283 File delete_output = new File(getProperty("user.dir")284 + "/src/test/java/output/");285 File[] files = delete_output.listFiles();286 for (File file : files) {287 file.delete();288 }289 }290 public XmlSuite constructXmlSuiteForParallelCucumber(291 int deviceCount, List<AppiumDevice> deviceSerail) {292 ArrayList<String> listeners = new ArrayList<>();293 listeners.add("com.cucumber.listener.CucumberListener");294 XmlSuite suite = new XmlSuite();295 suite.setName("TestNG Forum");296 suite.setThreadCount(deviceCount);297 suite.setParallel(ParallelMode.TESTS);298 suite.setVerbose(2);299 suite.setListeners(listeners);300 for (int i = 0; i < deviceCount; i++) {301 XmlTest test = new XmlTest(suite);302 test.setName("TestNG Test" + i);303 test.setPreserveOrder(false);304 test.addParameter("device", deviceSerail.get(i).getDevice().getUdid());305 test.setPackages(getPackages());306 }307 return getXmlSuite(suite);308 }309 public XmlSuite constructXmlSuiteDistributeCucumber(int deviceCount) {310 ArrayList<String> listeners = new ArrayList<>();311 listeners.add("com.cucumber.listener.CucumberListener");312 XmlSuite suite = new XmlSuite();313 suite.setName("TestNG Forum");314 suite.setThreadCount(deviceCount);315 suite.setParallel(ParallelMode.CLASSES);316 suite.setVerbose(2);317 suite.setListeners(listeners);318 XmlTest test = new XmlTest(suite);319 test.setName("TestNG Test");320 test.addParameter("device", "");321 test.setPackages(getPackages());322 return getXmlSuite(suite);323 }324 private XmlSuite getXmlSuite(XmlSuite suite) {325 File file = new File(getProperty("user.dir") + PARALLEL_XML_LOCATION);326 try (FileWriter fw = new FileWriter(file.getAbsoluteFile())) {327 try (BufferedWriter bw = new BufferedWriter(fw)) {328 bw.write(suite.toXml());329 } catch (IOException e) {330 e.printStackTrace();331 }332 } catch (IOException e) {333 e.printStackTrace();334 }335 return suite;336 }337 private static List<XmlPackage> getPackages() {338 List<XmlPackage> allPackages = new ArrayList<>();339 XmlPackage eachPackage = new XmlPackage();340 eachPackage.setName("output");341 allPackages.add(eachPackage);342 return allPackages;343 }344 private String getSuiteName() {345 return SUITE_NAME.get();346 }347 private String getCategoryName() {348 return CATEGORY.get();349 }350 private class CreateGroups {351 private List<String> tests;352 private Map<String, List<Method>> methods;353 private String category;354 private XmlSuite suite;355 private List<XmlClass> xmlClasses;356 private XmlTest test;357 private List<XmlClass> writeXml;358 public CreateGroups(List<String> tests, Map<String, List<Method>> methods,359 String category, XmlSuite suite) {360 this.tests = tests;361 this.methods = methods;362 this.category = category;363 this.suite = suite;364 }365 public List<XmlClass> getXmlClasses() {366 return xmlClasses;367 }368 public XmlTest getTest() {369 return test;370 }371 public List<XmlClass> getWriteXml() {372 return writeXml;373 }374 public CreateGroups invoke() {375 xmlClasses = writeXmlClass(tests, methods);376 test = new XmlTest(suite);377 test.setName(category);378 test.addParameter("device", "");379 include(groupsExclude, EXCLUDE_GROUPS);380 test.setIncludedGroups(groupsInclude);381 test.setExcludedGroups(groupsExclude);382 writeXml = new ArrayList<>();383 return this;384 }385 }386}...
Source:ATDExecutor.java
...94 final AppiumDevice appiumDevice = deviceAllocationManager.getDevices().get(i);95 test.addParameter("device", appiumDevice.getDevice().getUdid());96 test.addParameter("hostName", appiumDevice.getHostName());97 test.setIncludedGroups(groupsInclude);98 test.setExcludedGroups(groupsExclude);99 List<XmlClass> xmlClasses = writeXmlClass(tests, methods);100 test.setXmlClasses(xmlClasses);101 }102 writeTestNGFile(suite);103 return suite;104 }105 public XmlSuite constructXmlSuiteForClassLevelDistributionRunner(List<String> tests,106 Map<String, List<Method>> methods,107 String suiteName, String categoryName, int deviceCount) {108 XmlSuite suite = new XmlSuite();109 suite.setName(suiteName);110 suite.setThreadCount(deviceCount);111 suite.setParallel(ParallelMode.CLASSES);112 suite.setVerbose(2);113 listeners.add("com.appium.manager.AppiumParallelMethodTestListener");114 listeners.add("com.appium.utils.RetryListener");115 include(listeners, LISTENERS);116 suite.setListeners(listeners);117 XmlTest test = new XmlTest(suite);118 test.setName(categoryName);119 test.addParameter("device", "");120 include(groupsExclude, EXCLUDE_GROUPS);121 include(groupsInclude, INCLUDE_GROUPS);122 test.setIncludedGroups(groupsInclude);123 test.setExcludedGroups(groupsExclude);124 List<XmlClass> xmlClasses = writeXmlClass(tests, methods);125 test.setXmlClasses(xmlClasses);126 writeTestNGFile(suite);127 return suite;128 }129 public XmlSuite constructXmlSuiteForMethodLevelDistributionRunner(List<String> tests,130 Map<String, List<Method>> methods, String suiteName,131 String category, int deviceCount) {132 include(groupsInclude, INCLUDE_GROUPS);133 XmlSuite suite = new XmlSuite();134 suite.setName(suiteName);135 suite.setThreadCount(deviceCount);136 suite.setDataProviderThreadCount(deviceCount);137 suite.setVerbose(2);138 suite.setParallel(ParallelMode.METHODS);139 listeners.add("com.appium.manager.AppiumParallelMethodTestListener");140 listeners.add("com.appium.utils.RetryListener");141 include(listeners, LISTENERS);142 suite.setListeners(listeners);143 CreateGroups createGroups = new CreateGroups(tests, methods, category, suite).invoke();144 List<XmlClass> xmlClasses = createGroups.getXmlClasses();145 XmlTest test = createGroups.getTest();146 List<XmlClass> writeXml = createGroups.getWriteXml();147 for (XmlClass xmlClass : xmlClasses) {148 writeXml.add(new XmlClass(xmlClass.getName()));149 test.setClasses(writeXml);150 }151 writeTestNGFile(suite);152 return suite;153 }154 public boolean testNGParallelRunner() {155 TestNG testNG = new TestNG();156 List<String> suites = Lists.newArrayList();157 suites.add(getProperty("user.dir") + PARALLEL_XML_LOCATION);158 testNG.setTestSuites(suites);159 testNG.run();160 return testNG.hasFailure();161 }162 private Set<Method> getMethods(String pack) throws MalformedURLException {163 URL newUrl;164 List<URL> newUrls = new ArrayList<>();165 addAll(items, pack.split("\\s*,\\s*"));166 int a = 0;167 Collection<URL> urls = ClasspathHelper.forPackage(items.get(a));168 Iterator<URL> iter = urls.iterator();169 URL url = null;170 while (iter.hasNext()) {171 url = iter.next();172 if (url.toString().contains("test-classes")) {173 break;174 }175 }176 for (String item : items) {177 newUrl = new URL(url.toString() + item.replaceAll("\\.", "/"));178 newUrls.add(newUrl);179 a++;180 }181 Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(newUrls)182 .setScanners(new MethodAnnotationsScanner()));183 return reflections.getMethodsAnnotatedWith(Test.class);184 }185 private List<XmlClass> writeXmlClass(List<String> testCases, Map<String,186 List<Method>> methods) {187 List<XmlClass> xmlClasses = new ArrayList<>();188 for (String className : methods.keySet()) {189 XmlClass xmlClass = new XmlClass();190 xmlClass.setName(className);191 if (className.contains("Test")) {192 if (testCases.size() == 0) {193 xmlClasses.add(xmlClass);194 } else {195 for (String s : testCases) {196 for (String item : items) {197 String testName = item.concat("." + s);198 if (testName.equals(className)) {199 xmlClasses.add(xmlClass);200 }201 }202 }203 }204 }205 }206 return xmlClasses;207 }208 private void writeTestNGFile(XmlSuite suite) {209 try (FileWriter writer = new FileWriter(new File(210 getProperty("user.dir") + PARALLEL_XML_LOCATION))) {211 writer.write(suite.toXml());212 writer.flush();213 } catch (IOException e) {214 e.printStackTrace();215 }216 }217 private void include(List<String> groupsInclude, ConfigFileManager config) {218 String listItems = config.get();219 if (isNotEmpty(listItems)) {220 addAll(groupsInclude, listItems.split("\\s*,\\s*"));221 }222 }223 public Map<String, List<Method>> getTestMethods(Set<Method> methods) {224 Map<String, List<Method>> listOfMethods = new HashMap<>();225 methods.forEach(method -> {226 List<Method> methodsList = listOfMethods.computeIfAbsent(227 method.getDeclaringClass().getPackage().getName()228 + "." + method.getDeclaringClass()229 .getSimpleName(), k -> new ArrayList<>());230 methodsList.add(method);231 });232 return listOfMethods;233 }234 private class CreateGroups {235 private List<String> tests;236 private Map<String, List<Method>> methods;237 private String category;238 private XmlSuite suite;239 private List<XmlClass> xmlClasses;240 private XmlTest test;241 private List<XmlClass> writeXml;242 public CreateGroups(List<String> tests, Map<String, List<Method>> methods,243 String category, XmlSuite suite) {244 this.tests = tests;245 this.methods = methods;246 this.category = category;247 this.suite = suite;248 }249 public List<XmlClass> getXmlClasses() {250 return xmlClasses;251 }252 public XmlTest getTest() {253 return test;254 }255 public List<XmlClass> getWriteXml() {256 return writeXml;257 }258 public CreateGroups invoke() {259 xmlClasses = writeXmlClass(tests, methods);260 test = new XmlTest(suite);261 test.setName(category);262 test.addParameter("device", "");263 include(groupsExclude, EXCLUDE_GROUPS);264 test.setIncludedGroups(groupsInclude);265 test.setExcludedGroups(groupsExclude);266 writeXml = new ArrayList<>();267 return this;268 }269 }270}...
Source:DynamicSuiteGenerator.java
...26 totalTests+=testConfig.getTestsList().size();27 XmlTest test = new XmlTest(suite);28 test.setName(testConfig.getModuleName() + "-Tests");29 test.setPreserveOrder(true);30 test.setExcludedGroups(excludeGroup);31 //If Test is parallel32 if (testConfig.getParallel().equalsIgnoreCase("Yes")) {33 int threadCount = Integer.parseInt(testConfig.getParallelCount());34 if (threadCount > 0) {35 test.setParallel(XmlSuite.ParallelMode.CLASSES);36 test.setThreadCount(Integer.parseInt(testConfig.getParallelCount()));37 }38 }39 //Set XmlClasses40 test.setXmlClasses(FilterXmlClasse(testConfig.getModuleName(), testConfig.getTestsList()));41 }42 System.out.println("\n-----------------------------------------------------------------------------------------------------------");43 System.out.println("\t\tTotal Enabled Modules # " +totalModules);44 System.out.println("\t\tTotal Enabled Tests # " +totalTests);45 System.out.println("============================================================================================================\n");46 writeSuiteToFile(suite);47 }//End of function > GenerateSuite48 //Filter Xml Class based on Module and enabled test names49 private static List<XmlClass> FilterXmlClasse(String moduleName, List<String> tetsIds) {50 String packageName = "MRCS.Tests."+moduleName;51 List<XmlClass> xmlClasses = new ArrayList<XmlClass>();52 for (String testName : tetsIds) {53 String strClass = packageName + "." + testName;54 XmlClass xmlClass = new XmlClass(strClass);55 //Add current xml class to list56 xmlClasses.add(xmlClass);57 }58 return xmlClasses;59 }60 //Write Xml Suite to File61 private static void writeSuiteToFile(XmlSuite suite) {62 String xmlpath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "suite-xml-files" + File.separator + "MRCS Test Suite.xml";63 File f = new File(xmlpath);64 FileWriter fr = null;65 try {66 fr = new FileWriter(f);67 fr.write(suite.toXml().toString());68 } catch (IOException e) {69 e.printStackTrace();70 } finally {71 //close resources72 try {73 fr.close();74 } catch (IOException e) {75 e.printStackTrace();76 }77 }//End finally78 }//End> writeSuiteToFile79 public static void removeOldXmlFiles(){80 try {81 File file = new File("src/test/resources/dynamic_suites_xml_files");82 //Delete all old files83 for (File delFile:file.listFiles()){84 if(delFile.isFile()){85 if(delFile.getName().endsWith(".xml")){86 delFile.delete();87 }88 }89 }90 } catch (Exception e) {91 e.printStackTrace();92 }93 }94 //Write Xml Suite to File95 private static void writeMultipleSuiteToFile(XmlSuite suite) {96 File file = new File("src/test/resources/dynamic_suites_xml_files");97 int count=file.listFiles().length+1;98 String xmlpath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "dynamic_suites_xml_files" + File.separator + "MRCS Test Suite"+count+".xml";99 System.out.println("Writing suite to file >"+xmlpath);100 File f = new File(xmlpath);101 FileWriter fr = null;102 try {103 fr = new FileWriter(f);104 fr.write(suite.toXml().toString());105 System.out.println("Xml Suite File written successfully > "+xmlpath);106 } catch (IOException e) {107 e.printStackTrace();108 } finally {109 //close resources110 try {111 fr.close();112 } catch (IOException e) {113 e.printStackTrace();114 }115 }//End finally116 }//End> writeSuiteToFile117 public static List<File> getSuiteXmlFiles(){118 List<File> xmlFiles= new ArrayList<>();119 try {120 File file = new File("src/test/resources/dynamic_suites_xml_files");121 //Delete all old files122 for (File xmlFile:file.listFiles()){123 if(xmlFile.isFile()){124 if(xmlFile.getName().endsWith(".xml")){125 xmlFiles.add(xmlFile);126 }127 }128 }129 } catch (Exception e) {130 e.printStackTrace();131 }132 return xmlFiles;133 }134 public static void GenerateSuite(List<TestConfig> lstTestConfig) throws Exception {135 System.out.println("-----------------------------------------------------------");136 System.out.println("\t TEST SUITE CONFIGURATIONS");137 System.out.println("-----------------------------------------------------------");138 int totalModules =lstTestConfig.size();139 int totalTests=0;140 XmlSuite suite = new XmlSuite();141 suite.setName("MRCS Test Suite");142 suite.addListener("MRCS.Utils.ReportListener");143 List excludeGroup = new ArrayList<String>();144 excludeGroup.add("broken");145 //Add Tests into Suite146 for (TestConfig testConfig : lstTestConfig) {147 System.out.println("Test module details" + testConfig.toString());148 totalTests+=testConfig.getTestsList().size();149 XmlTest test = new XmlTest(suite);150 test.setName(testConfig.getModuleName() + "-Tests");151 test.setPreserveOrder(true);152 test.setExcludedGroups(excludeGroup);153 //If Test is parallel154 if (testConfig.getParallel().equalsIgnoreCase("Yes")) {155 int threadCount = Integer.parseInt(testConfig.getParallelCount());156 if (threadCount > 0) {157 test.setParallel(XmlSuite.ParallelMode.CLASSES);158 test.setThreadCount(Integer.parseInt(testConfig.getParallelCount()));159 }160 }161 //Set XmlClasses162 test.setXmlClasses(FilterXmlClasse(testConfig.getModuleName(), testConfig.getTestsList()));163 }164 System.out.println("\n-----------------------------------------------------------------------------------------------------------");165 System.out.println("\t\tTotal Enabled Modules # " +totalModules);166 System.out.println("\t\tTotal Enabled Tests # " +totalTests);...
Source:ExcludeProdFailuresFromRCFailureXML.java
...54 System.out.println(rcxmlSuite.getAllParameters());55 rctestList = rcxmlSuite.getTests();56 57 rcxmlclasses = rctestList.get(0).getClasses();58 rcxmlSuite.setExcludedGroups(rcxmlSuite.getExcludedGroups());59 for (XmlClass classes : rcxmlclasses) {60 System.out.println(classes.getName());61 }62 prodFileData();63 createTestNgFile();64 } catch (Exception e) {65 e.printStackTrace();66 }67 }68 @Test69 public void prodFileData() {70 try {71 prodinputStream = new FileInputStream(prodFailureFile);72 prodxmlSuite = sl.parse(prodFailureFile, prodinputStream, false);73 System.out.println(prodxmlSuite.getAllParameters());74 prodtestList = prodxmlSuite.getTests();75 76 prodxmlclasses = prodtestList.get(0).getClasses();77 prodxmlSuite.setExcludedGroups(prodxmlSuite.getExcludedGroups());78 for (XmlClass classes : prodxmlclasses) {79 System.out.println(classes.getName());80 for (XmlInclude include : classes.getIncludedMethods()) {81 prodFileMethods.add(include.getName());82 }83 }84 createTestNgFile();85 } catch (Exception e) {86 // TODO Auto-generated catch block87 e.printStackTrace();88 }89 90 }91 92 public void createTestNgFile() {93 rcxmlSuite.getName();94 XmlSuite writeXmlSuite=new XmlSuite();95 writeXmlSuite.setName("Failed suite [Failed suite [Failed suite [Failed suite [Failed suite [Failed suite [Failed suite [Automation Suite 1]]]]]]]");96 writeXmlSuite.setParallel(ParallelMode.METHODS);97 writeXmlSuite.setThreadCount(20);98 writeXmlSuite.setConfigFailurePolicy(FailurePolicy.CONTINUE);99 writeXmlSuite.setVerbose(0);100 writeXmlSuite.setGuiceStage("DEVELOPMENT");101 XmlTest writeXmlTest=new XmlTest(writeXmlSuite);102 writeXmlTest.setName("Automation Test Part 1: Execute test cases externally.(failed)(failed)(failed)(failed)(failed)(failed)");103 writeXmlTest.setParallel(ParallelMode.METHODS);104 writeXmlTest.setExcludedGroups(groupsToExclude());105 106 List<XmlClass> classList=new ArrayList<XmlClass>();107 for (XmlClass classes : rcxmlclasses) {108 count=0;109 List<XmlInclude> includeList=new ArrayList<XmlInclude>();110 for (XmlInclude include : classes.getIncludedMethods()) {111 if(!prodFileMethods.contains(include.getName()))112 {113 count++;114 includeList.add(include);115 }116}117 if(count>0)118 classList.add(classes);...
Source:MasterTestSuite.java
...23 suite.setParameters(parameters); 24 for (SuiteVariables suiteVariables : suiteVariablesList) {25 XmlTest test = new XmlTest(suite);26 test.setName(suiteVariables.geTestName());27 test.setExcludedGroups(Arrays.asList(suiteVariables.getExcludeGrops()));28 XmlClass[] classes = new XmlClass[]{29 new XmlClass(suiteVariables.getTestClass()),30 };31 test.setXmlClasses(Arrays.asList(classes));32 }33 TestNG tng = new TestNG();34 List<Class> listnerClasses = new ArrayList<Class>();35 listnerClasses.add(org.wso2.platform.test.core.PlatformTestManager.class);36 listnerClasses.add(org.wso2.platform.test.core.PlatformSuiteManager.class);37 listnerClasses.add(PlatformReportManager.class);38 listnerClasses.add(PlatformPriorityManager.class);39 tng.setListenerClasses(listnerClasses);40 tng.setDefaultSuiteName(SuiteName);41 tng.setXmlSuites(Arrays.asList(new XmlSuite[]{suite}));...
Source:GroupSuiteTest.java
...43 String[] testGroups, String[] excludedTestGroups,44 String[] methods) {45 XmlSuite s = createXmlSuite("Groups");46 s.setIncludedGroups(Arrays.asList(suiteGroups));47 s.setExcludedGroups(Arrays.asList(excludedSuiteGroups));48 XmlTest t = createXmlTest(s, "Groups-test", GroupSuiteSampleTest.class.getName());49 t.setIncludedGroups(Arrays.asList(testGroups));50 t.setExcludedGroups(Arrays.asList(excludedTestGroups));51 TestListenerAdapter tla = new TestListenerAdapter();52 TestNG tng = create();53 tng.addListener(tla);54 tng.setXmlSuites(Arrays.asList(new XmlSuite[] { s }));55 tng.run();56 verifyPassedTests(tla, methods);57 }58 private String[] g(String... groups) {59 return groups;60 }61}...
Source:AdditionalTest.java
...32 }33 public static void main(String[] args) throws Exception{34 final TestNG testNG = new TestNG(true);35// testNG.setTestClasses(new Class[] { AdditionalTest.class });36// testNG.setExcludedGroups("optional");37 final Parser parser = new Parser("testing/testing-testng/src/test/resources/testng.yaml");38 final List<XmlSuite> suites = parser.parseToList();39 testNG.setXmlSuites(suites);40 testNG.run();41 }42}...
Source:OverrideProcessor.java
...25 }26 }27 if (m_excludedGroups != null && m_excludedGroups.length > 0) {28 for (XmlTest t : s.getTests()) {29 t.setExcludedGroups(Arrays.asList(m_excludedGroups));30 }31 }32 }33 return suites;34 }35}...
setExcludedGroups
Using AI Code Generation
1import org.testng.xml.XmlSuite;2public class SetExcludedGroups {3 public static void main(String[] args) {4 XmlSuite suite = new XmlSuite();5 suite.setExcludedGroups("group1, group2");6 System.out.println(suite.toXml());7 }8}9Related Posts: How to use setIncludedGroups() method of org.testng.xml.XmlSuite class?10How to use setParallel() method of org.testng.xml.XmlSuite class?11How to use setThreadCount() method of org.testng.xml.XmlSuite class?12How to use setVerbose() method of org.testng.xml.XmlSuite class?13How to use setXmlPackages() method of org.testng.xml.XmlSuite class?14How to use setXmlClasses() method of org.testng.xml.XmlSuite class?15How to use setXmlTests() method of org.testng.xml.XmlSuite class?16How to use setXmlFiles() method of org.testng.xml.XmlSuite class?17How to use setXmlSuiteFiles() method of org.testng.xml.XmlSuite class?18How to use setXmlSuiteFiles() method of org.testng.xml.XmlSuite class?
setExcludedGroups
Using AI Code Generation
1public class TestNGGroups {2 @Test(groups = "group1")3 public void test1() {4 System.out.println("test1");5 }6 @Test(groups = "group2")7 public void test2() {8 System.out.println("test2");9 }10 @Test(groups = "group3")11 public void test3() {12 System.out.println("test3");13 }14 @Test(groups = "group1")15 public void test4() {16 System.out.println("test4");17 }18}19@Test(groups = "group1", enabled = false)20public void test1() {21 System.out.println("test1");22}23@Test(groups = "group1", enabled = false)24public void test1() {25 System.out.println("test1");26}
setExcludedGroups
Using AI Code Generation
1XmlSuite suite = new XmlSuite();2suite.setName("TestNG Suite");3suite.setExcludedGroups("group1,group2");4XmlSuite suite = new XmlSuite();5suite.setName("TestNG Suite");6suite.setIncludedGroups("group1,group2");7XmlSuite suite = new XmlSuite();8suite.setName("TestNG Suite");9suite.setExcludedGroups("group1,group2");10XmlSuite suite = new XmlSuite();11suite.setName("TestNG Suite");12suite.setIncludedGroups("group1,group2");13XmlSuite suite = new XmlSuite();14suite.setName("TestNG Suite");15suite.setExcludedGroups("group1,group2");16XmlSuite suite = new XmlSuite();17suite.setName("TestNG Suite");18suite.setIncludedGroups("group1,group2");19XmlSuite suite = new XmlSuite();20suite.setName("TestNG Suite");21suite.setExcludedGroups("group1,group2");22XmlSuite suite = new XmlSuite();23suite.setName("TestNG Suite");24suite.setIncludedGroups("group1,group2");25XmlSuite suite = new XmlSuite();26suite.setName("TestNG Suite");27suite.setExcludedGroups("group1,group2");28XmlSuite suite = new XmlSuite();29suite.setName("TestNG Suite");30suite.setIncludedGroups("group1,group2");31XmlSuite suite = new XmlSuite();32suite.setName("TestNG Suite");33suite.setExcludedGroups("group1,group2");34XmlSuite suite = new XmlSuite();35suite.setName("TestNG Suite");36suite.setIncludedGroups("group1,group2
setExcludedGroups
Using AI Code Generation
1import org.testng.TestNG;2import org.testng.xml.XmlSuite;3public class TestNGExcludedGroups {4 public static void main(String[] args) {5 XmlSuite suite = new XmlSuite();6 suite.setName("MySuite");7 suite.setExcludedGroups("group1");8 TestNG tng = new TestNG();9 tng.setXmlSuites(Arrays.asList(suite));10 tng.run();11 }12}13MyTest.testMethod1() - group114MyTest.testMethod2() - group215Example 2: [crayon-5f0b0a0a0a7c1169602469/] Output: MyTest.testMethod1() - group1 MyTest.testMethod2() - group2 Note: The above code will exclude all the test methods that belongs to group1. Example 2: [crayon-5f0b0a0a0a7c1169602469/] Output: MyTest.testMethod1() - group1 MyTest.testMethod2() - group2 Note: The above code will exclude all the test methods that belongs to group1. Example 2: [crayon-5f0b0a0a0a7c1169602469/] Output: MyTest.testMethod1() - group1 MyTest.testMethod2() - group2 Note: The above code will exclude all the test methods that belongs to group1. Example 2: [crayon-5f0b0a0a0a7c1169602469/] Output: MyTest.testMethod1() - group1 MyTest.testMethod2() - group2 Note: The above code will exclude all the test methods that belongs to group1. Example 2: [crayon-5f0b0a0a0a7c1169602469/] Output: MyTest.testMethod1() - group1 MyTest.testMethod2() - group2 Note: The above code will exclude all the test methods that belongs to group1. Example 2: [crayon-5f0b0a0a0a7c1169602469/] Output: MyTest.testMethod1() - group1 MyTest.testMethod2() - group2 Note: The above code
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!!