How to use getTest method of org.testng.xml.XmlSuite class

Best Testng code snippet using org.testng.xml.XmlSuite.getTest

Source:MyTestExecutor.java Github

copy

Full Screen

...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<>();...

Full Screen

Full Screen

Source:BaseTest.java Github

copy

Full Screen

...60 return m_configuration;61 }6263 protected void setDebug() {64 getTest().setVerbose(9);65 }6667 protected void setParallel(XmlSuite.ParallelMode parallel) {68 getTest().setParallel(parallel);69 }7071 protected void setVerbose(int n) {72 m_verbose = n;73 }7475 protected void setTestTimeOut(long n) {76 getTest().setTimeOut(n);77 }7879 protected void setSuiteTimeOut(long n) {80 m_suite.setTimeOut(Long.toString(n));81 }8283 protected void setJUnit(boolean f) {84 getTest().setJUnit(f);85 }8687 protected void setThreadCount(int count) {88 getTest().getSuite().setThreadCount(count);89 }9091 private Map<Long, XmlTest> m_tests= new HashMap<>();92 private Map<Long, Map> m_passedTests= new HashMap<>();93 private Map<Long, Map> m_failedTests= new HashMap<>();94 private Map<Long, Map> m_skippedTests= new HashMap<>();95 private Map<Long, XmlTest> m_testConfigs= new HashMap<>();96 private Map<Long, Map> m_passedConfigs= new HashMap<>();97 private Map<Long, Map> m_failedConfigs= new HashMap<>();98 private Map<Long, Map> m_skippedConfigs= new HashMap<>();99 private Map<Long, Map> m_failedButWithinSuccessPercentageTests= new HashMap<>();100101 protected Map<String, List<ITestResult>> getTests(Map<Long, Map> map) {102 Map<String, List<ITestResult>> result= map.get(getId());103 if(null == result) {104 result= new HashMap<>();105 map.put(getId(), result);106 }107108 return result;109 }110111 protected XmlTest getTest() {112 return m_tests.get(getId());113 }114115 protected void setTests(Map<Long, Map> map, Map m) {116 map.put(getId(), m);117 }118119 public Map<String, List<ITestResult>> getFailedTests() {120 return getTests(m_failedTests);121 }122123 public Map<String, List<ITestResult>> getFailedButWithinSuccessPercentageTests() {124 return getTests(m_failedButWithinSuccessPercentageTests);125 }126127 public Map<String, List<ITestResult>> getPassedTests() {128 return getTests(m_passedTests);129 }130131 public Map<String, List<ITestResult>> getSkippedTests() {132 return getTests(m_skippedTests);133 }134135 public Map<String, List<ITestResult>> getFailedConfigs() {136 return getTests(m_failedConfigs);137 }138139 public Map<String, List<ITestResult>> getPassedConfigs() {140 return getTests(m_passedConfigs);141 }142143 public Map<String, List<ITestResult>> getSkippedConfigs() {144 return getTests(m_skippedConfigs);145 }146147 public void setSkippedTests(Map m) {148 setTests(m_skippedTests, m);149 }150151 public void setPassedTests(Map m) {152 setTests(m_passedTests, m);153 }154155 public void setFailedTests(Map m) {156 setTests(m_failedTests, m);157 }158159 public void setFailedButWithinSuccessPercentageTests(Map m) {160 setTests(m_failedButWithinSuccessPercentageTests, m);161 }162163 public void setSkippedConfigs(Map m) {164 setTests(m_skippedConfigs, m);165 }166167 public void setPassedConfigs(Map m) {168 setTests(m_passedConfigs, m);169 }170171 public void setFailedConfigs(Map m) {172 setTests(m_failedConfigs, m);173 }174175176 protected void run() {177 assert null != getTest() : "Test wasn't set, maybe @Configuration methodSetUp() was never called";178 setPassedTests(new HashMap());179 setFailedTests(new HashMap());180 setSkippedTests(new HashMap());181 setPassedConfigs(new HashMap());182 setFailedConfigs(new HashMap());183 setSkippedConfigs(new HashMap());184 setFailedButWithinSuccessPercentageTests(new HashMap());185186 m_suite.setVerbose(m_verbose != null ? m_verbose : 0);187 SuiteRunner suite = new SuiteRunner(m_configuration,188 m_suite, m_outputDirectory, m_testRunnerFactory);189190 suite.run();191 }192193 protected void addMethodSelector(String className, int priority) {194 XmlMethodSelector methodSelector= new XmlMethodSelector();195 methodSelector.setName(className);196 methodSelector.setPriority(priority);197 getTest().getMethodSelectors().add(methodSelector);198 }199200 protected XmlClass addClass(Class<?> cls) {201 return addClass(cls.getName());202 }203204 protected XmlClass addClass(String className) {205 XmlClass result= new XmlClass(className);206 getTest().getXmlClasses().add(result);207208 return result;209 }210211 protected void setBeanShellExpression(String expression) {212 getTest().setBeanShellExpression(expression);213 }214215 protected void addPackage(String pkgName, String[] included, String[] excluded) {216 XmlPackage pkg= new XmlPackage();217 pkg.setName(pkgName);218 pkg.getInclude().addAll(Arrays.asList(included));219 pkg.getExclude().addAll(Arrays.asList(excluded));220 getTest().getSuite().getXmlPackages().add(pkg);221 }222223 private XmlClass findClass(String className) {224 for(XmlClass cl : getTest().getXmlClasses()) {225 if(cl.getName().equals(className)) {226 return cl;227 }228 }229230 XmlClass result= addClass(className);231232 return result;233 }234235 public void addIncludedMethod(String className, String m) {236 XmlClass xmlClass= findClass(className);237 xmlClass.getIncludedMethods().add(new XmlInclude(m));238 getTest().getXmlClasses().add(xmlClass);239 }240241 public void addExcludedMethod(String className, String m) {242 XmlClass xmlClass= findClass(className);243 xmlClass.getExcludedMethods().add(m);244 getTest().getXmlClasses().add(xmlClass);245 }246247 public void addIncludedGroup(String g) {248 getTest().addIncludedGroup(g);249 }250251 public void addExcludedGroup(String g) {252 getTest().addExcludedGroup(g);253 }254255 public void addMetaGroup(String mg, List<String> l) {256 getTest().getMetaGroups().put(mg, l);257 }258259 public void addMetaGroup(String mg, String n) {260 List<String> l= new ArrayList<>();261 l.add(n);262 addMetaGroup(mg, l);263 }264265 public void setParameter(String key, String value) {266 getTest().addParameter(key, value);267 }268269// @Configuration(beforeTestMethod = true, groups = { "init", "initTest"})270 @BeforeMethod(groups= { "init", "initTest" })271 public void methodSetUp() {272 m_suite= new XmlSuite();273 m_suite.setName("Internal_suite");274 XmlTest xmlTest= new XmlTest(m_suite);275 xmlTest.setName("Internal_test_failures_are_expected");276 m_tests.put(getId(), xmlTest);277 }278279 private void addTest(Map<String, List<ITestResult>> tests, ITestResult t) {280 List<ITestResult> l= tests.get(t.getMethod().getMethodName()); ...

Full Screen

Full Screen

Source:Helper.java Github

copy

Full Screen

...131 suite=getParallelMode(suite,parallel);132 suite.setVerbose(2);133 suite.setListeners(listeners);134 System.out.println("includedMethods final string : "+includedMethods);135 xmlTest = getTest(suite,136 testClassName,137 includedMethods,138 excludedMethods,139 param1,140 param2);141 alXmlTest.add(xmlTest);142 }143 // List<XmlTest> disntictList = alXmlTest.stream().distinct().collect(Collectors.toList());144 } catch (Exception e) {145 e.printStackTrace();146 } finally {147 recordset.close();148 }149 return writeTestNGFile(suite, xmlName);150 }151 public static String createSuiteCucumber(String mapping,152 String suiteName,153 String xmlName,ArrayList<String> dataBnd) {154 XmlSuite suite = new XmlSuite();155 ArrayList<XmlTest> alXmlTest=new ArrayList<XmlTest>();156 ArrayList<String> dataBindingList=new ArrayList<>();157 XmlTest xmlTest = new XmlTest();158 // FundsTransferWithinUae;functionality;FundsTransferWithinUae_Scn_002;chrome159 suite.setName(suiteName);160 suite.setThreadCount(4);//.setThreadCount(5);161 //suite.setDataProviderThreadCount(5);162 HashMap<String,String> hm=new HashMap<>();163 hm.put("Devicetype",mapping.split(";")[3]);164 suite.setParameters(hm);165 String ab=mapping.split(";")[0]+"_"+mapping.split(";")[1]+"_"+mapping.split(";")[2];166 String testClassName=mapping.split(";")[0]+mapping.split(";")[1]+mapping.split(";")[2];167 String param1="Devicetype"+"-"+mapping.split(";")[3];168 dataBindingList=(dataBnd);169 suite=getParallelMode(suite,"CLASSES");170 suite.setVerbose(2);171 System.out.println("suite : "+suite);172 xmlTest = getSimpleTest(suite,173 testClassName,174 param1,dataBindingList);175 alXmlTest.add(xmlTest);176 // }177 // List<XmlTest> disntictList = alXmlTest.stream().distinct().collect(Collectors.toList());178 return writeTestNGFile(suite, xmlName);179 }180 public static XmlTest getTest(XmlSuite suite,String ... strings) {181 List<String> listValue=Arrays.asList(strings);182 String testClassName=listValue.get(0);183 String includedMethods=listValue.get(1);184 String excludedMethods=listValue.get(2);185 String param1=listValue.get(3);186 String param2=listValue.get(4);187 /*Test tag*/188 XmlTest test1 = new XmlTest(suite);189 HashMap<String, String> hmParam = new HashMap<String, String>();190 hmParam.put(param1.split("-")[0],param1.split("-")[1]);191 hmParam.put(param2.split("-")[0], param2.split("-")[1]);192 test1.setParameters(hmParam);193 test1.setName((testClassName.trim()+"_".trim()+param2.split("-")[1]).trim());194 /*Class tag*/195 List<XmlClass> lstClasses = new ArrayList<XmlClass>();196 XmlClass xmlClass = new XmlClass();197 xmlClass.setName("pom.tests." +testClassName);198 /*Exclude tag*/199 List<String> lstxmlExclude = new ArrayList<String>();200 for(String str :excludedMethods.split("-")) {201 lstxmlExclude.add(str);202 }203 xmlClass.setExcludedMethods(lstxmlExclude);204 /*Include tag*/205 List<XmlInclude> lstxmlInclude = new ArrayList<XmlInclude>();206 XmlInclude xmlInclude=null;207 for(String str :includedMethods.split("-")) {208 xmlInclude = new XmlInclude(str);209 lstxmlInclude.add(xmlInclude);210 }211 xmlClass.setIncludedMethods(lstxmlInclude);212 lstClasses.add(xmlClass);213 test1.setClassNames(lstClasses);214 return test1;215 }216 public static XmlTest getSimpleTest(XmlSuite suite,217 String testClassName,218 String param1,ArrayList<String >arrayList) {219 /*Test tag*/220 XmlTest test1 = new XmlTest(suite);221 HashMap<String, String> hmParam = new HashMap<String, String>();222 hmParam.put(param1.split("-")[0],param1.split("-")[1]);223 test1.setParameters(hmParam);224 test1.setName((testClassName.trim()));225 /*Class tag*/226 List<XmlClass> lstClasses = new ArrayList<XmlClass>();227 for(String str : arrayList) {228 XmlClass xmlClass = new XmlClass();229 HashMap<String, String> hmap = new HashMap<>();230 xmlClass.setName("com.cucumber.testCucumber." + "FundsTransferWithinUaeTest");231 hmap.put(("DataBinding"),232 (str.split(";")[3]));233 xmlClass.setParameters(hmap);234 lstClasses.add(xmlClass);235 }236 test1.setClasses(lstClasses);237 return test1;238 }239 public static String writeTestNGFile(XmlSuite suite, String xmlName) {240 String xmlPath=System.getProperty("user.dir") +"/suites/"+ xmlName;241 try {242 FileWriter writer = new FileWriter(new File(xmlPath));243 BufferedWriter bw = new BufferedWriter(writer);244 bw.write(suite.toXml());245 bw.close();246 } catch (IOException e) {247 e.printStackTrace();248 }249 return xmlPath;250 }251 public static void createSuite(Recordset recordset,252 String suiteName,253 String xmlName) {254 XmlSuite suite = new XmlSuite();255 ArrayList<String> listeners = new ArrayList<>();256 listeners.add("framework.listeners.TestNGSuiteListener");257 suite.setName(suiteName);258 suite.setThreadCount(1);259 suite.setDataProviderThreadCount(1);260 suite.setParallel(XmlSuite.PARALLEL_TESTS);261 suite.setVerbose(2);262 suite.setListeners(listeners);263 XmlTest xmlTest = null;264 try {265 while (recordset.next()) {266 // Run TestcaseName username password password_Wrong267 String testName = recordset.getField("TestcaseName");268 String username = recordset.getField("username");269 String password = recordset.getField("password");270 String password_Wrong = recordset.getField("password_Wrong");271 xmlTest = getTest(suite);272 suite.addTest(xmlTest);273 writeTestNGFile(suite, xmlName);274 }275 } catch (Exception e) {276 e.printStackTrace();277 } finally {278 recordset.close();279 }280 }281 public static ArrayList<String> getSheetNames(Recordset recordset) {282 ArrayList<String> alSheetNames = new ArrayList<String>();283 try {284 while (recordset.next()) {285 // Run TestcaseName username password password_Wrong...

Full Screen

Full Screen

Source:ATDExecutor.java Github

copy

Full Screen

...55 Set<Method> setOfMethods = getMethods(pack);56 String runnerLevel = RUNNER_LEVEL.get();57 if (executionType.equalsIgnoreCase("distribute")) {58 if (runnerLevel != null && runnerLevel.equalsIgnoreCase("class")) {59 constructXmlSuiteForClassLevelDistributionRunner(test, getTestMethods(setOfMethods),60 suiteName, categoryName, deviceCount);61 } else {62 constructXmlSuiteForMethodLevelDistributionRunner(test,63 getTestMethods(setOfMethods), suiteName, categoryName, deviceCount);64 }65 } else {66 constructXmlSuiteForParallelRunner(test, getTestMethods(setOfMethods),67 suiteName, categoryName, deviceCount);68 }69 result = testNGParallelRunner();70 figlet("Test Completed");71 return result;72 }73 public XmlSuite constructXmlSuiteForParallelRunner(List<String> tests,74 Map<String, List<Method>> methods,75 String suiteName, String categoryName,76 int deviceCount) {77 ArrayList<String> listeners = new ArrayList<>();78 listeners.add("com.appium.manager.AppiumParallelTestListener");79 listeners.add("com.appium.utils.RetryListener");80 include(listeners, LISTENERS);81 include(groupsInclude, INCLUDE_GROUPS);82 include(groupsExclude, EXCLUDE_GROUPS);83 XmlSuite suite = new XmlSuite();84 suite.setName(suiteName);85 suite.setThreadCount(deviceCount);86 suite.setDataProviderThreadCount(deviceCount);87 suite.setParallel(ParallelMode.TESTS);88 suite.setVerbose(2);89 suite.setListeners(listeners);90 for (int i = 0; i < deviceCount; i++) {91 XmlTest test = new XmlTest(suite);92 test.setName(categoryName + "-" + i);93 test.setPreserveOrder(false);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<>();...

Full Screen

Full Screen

Source:MethodSelector.java Github

copy

Full Screen

...47 XmlSuite eachSuite = new XmlSuite();48 eachSuite.setName("VBricks Suite");49 eachSuite.setParallel("tests");50 eachSuite.setThreadCount(8);51 eachSuite.setTests(getTest(eachSuite, getMethodsfromClass, allParameters,ls));52 //eachSuite.setTests(getTest(eachSuite, getMethodsfromClass, testngParams));53 logger.info("Each Class " + eachSuite.toXml()); 54 suites.add(eachSuite);55 return suites;56 }5758 public List<XmlTest> getTest(XmlSuite suite, Map<String, String> getMethodsfromClass,59 List<Map<String,String>> allParameters, List<String> ls) {60 List<XmlTest> tests = new ArrayList<XmlTest>();61 62 //System.out.println("getmethods from class value "+getMethodsfromClass.isEmpty());63 for (int i = 0; i < allParameters.size(); i++) {64 //System.out.println("All Parameter value"+allParameters.get(i).get("TestCaseName"));65 XmlTest eachTest = new XmlTest();66 tests.add(eachTest);67 eachTest.setName(allParameters.get(i).get("TestCaseName"));68 eachTest.setParameters(allParameters.get(i));69 //System.out.println(allParameters.get(i));70 eachTest.setXmlClasses(getXmlClasses(eachTest, getMethodsfromClass,ls));71 eachTest.setSuite(suite);72 ...

Full Screen

Full Screen

Source:MethodGroupMappingHolder.java Github

copy

Full Screen

...41 if (inited) {42 return;43 }44 Map<String, Set<String>> testnameGroupMapping = new HashMap<>();45 List<XmlTest> xmlTests = xmlSuite.getTests();46 for (XmlTest xmlTest : xmlTests) {47 String testname = xmlTest.getName();48 List<String> includeGroups = xmlTest.getIncludedGroups();49 if (CollectionUtils.isNotEmpty(includeGroups)) {50 testnameGroupMapping.put(testname, new HashSet<String>(includeGroups));51 }52 }53 methodGroupsMapping.clear();54 for (ITestNGMethod tMethod : allTestngMethods) {55 Method method = tMethod.getConstructorOrMethod().getMethod();56 String testname = tMethod.getXmlTest().getName();57 Set<String> groups = testnameGroupMapping.get(testname);58 if (CollectionUtils.isEmpty(groups)) {59 continue;60 }61 if (methodGroupsMapping.containsKey(method)) {62 methodGroupsMapping.get(method).addAll(groups);63 } else {64 methodGroupsMapping.put(method, groups);65 }66 }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}...

Full Screen

Full Screen

Source:ExtentReport.java Github

copy

Full Screen

...30 for (ISuite suite : suites) {31 Map<String, ISuiteResult> result = suite.getResults();32 33 for (ISuiteResult r : result.values()) {34 ITestContext context = r.getTestContext();35 36 buildTestNodes(context.getPassedTests(), Status.PASS);37 buildTestNodes(context.getFailedTests(), Status.FAIL);38 buildTestNodes(context.getSkippedTests(), Status.SKIP);39 }40 }41 42 extent.flush();43 44 }45 46 private void buildTestNodes(IResultMap tests, Status status) {47 ExtentTest test;48 49 if (tests.size() > 0) {50 for (ITestResult result : tests.getAllResults()) {51 test = extent.createTest(result.getMethod().getMethodName());52 53 /*test.getTest(). = getTime(result.getStartMillis());54 test.getTest().endedTime = getTime(result.getEndMillis());*/55 56 for (String group : result.getMethod().getGroups())57 test.assignCategory(group);58 59 String message = "Test " + status.toString().toLowerCase() + "ed";60 61 if (result.getThrowable() != null)62 message = result.getThrowable().getMessage();63 64 test.log(status, message);65 66 // extent.endTest(test);67 }68 }...

Full Screen

Full Screen

Source:TestNGListener.java Github

copy

Full Screen

...12 final private String REPORT_NAME_PARAM = "ReportName";13 private static XmlSuite suite;14 @Override15 public void onTestFailure(ITestResult Result) {16 ExtentReport.getTest().log(LogStatus.ERROR, Result.getThrowable());17 }18 @Override19 public void alter(List<XmlSuite> suites) {20 suite = suites.get(0);21 List<XmlTest> testsList = suite.getTests();22 suite.setTests(new ArrayList<>());23 List<XmlTest> updatedTestsList = new ArrayList<>();24 for (XmlTest test : testsList) {25 XmlTest newTest = getXmlTest(test);26 updatedTestsList.add(newTest);27 }28 suite.setTests(updatedTestsList);29 }30 private XmlTest getXmlTest(XmlTest test) {31 String testName = test.getName();32 XmlTest newTest = new XmlTest(suite);33 newTest.setName(testName);34 newTest.setClasses(test.getClasses());35 newTest.addParameter(REPORT_NAME_PARAM, testName);...

Full Screen

Full Screen

getTest

Using AI Code Generation

copy

Full Screen

1XmlSuite mySuite = new XmlSuite();2List<XmlTest> myTests = mySuite.getTests();3for (XmlTest myTest : myTests) {4 System.out.println("Test Name: " + myTest.getName());5 System.out.println("Test Name: " + myTest.getXmlClasses());6}

Full Screen

Full Screen

getTest

Using AI Code Generation

copy

Full Screen

1package com.automation;2import java.util.List;3import org.testng.xml.XmlClass;4import org.testng.xml.XmlSuite;5import org.testng.xml.XmlTest;6public class TestNGXmlSuite {7 public static void main(String[] args) {8 XmlSuite suite = new XmlSuite();9 suite.setName("TestNG Suite");10 XmlTest test = new XmlTest(suite);11 test.setName("TestNG Test");

Full Screen

Full Screen

getTest

Using AI Code Generation

copy

Full Screen

1public class TestNGTest {2 public void test() {3 XmlSuite suite = new XmlSuite();4 suite.getTests().get(0).getClasses().get(0).getIncludedMethods().get(0).getMethodName();5 }6}7public class TestNGTest {8 public void test() {9 XmlSuite suite = new XmlSuite();10 suite.getTest("test").getClasses().get(0).getIncludedMethods().get(0).getMethodName();11 }12}13public class TestNGTest {14 public void test() {15 XmlSuite suite = new XmlSuite();16 suite.getTest("test").getXmlClasses().get(0).getIncludedMethods().get(0).getMethodName();17 }18}19public class TestNGTest {20 public void test() {21 XmlSuite suite = new XmlSuite();22 suite.getTest("test").getXmlClasses().get(0).getIncludedMethods().get(0).getName();23 }24}25public class TestNGTest {26 public void test() {27 XmlSuite suite = new XmlSuite();28 suite.getTest("test").getXmlClasses().get(0).getIncludedMethods().get(0).getMethodName();29 }30}31public class TestNGTest {32 public void test() {33 XmlSuite suite = new XmlSuite();34 suite.getTest("test").getXmlClasses().get(0).getIncludedMethods().get(0).getMethodName();35 }36}37public class TestNGTest {38 public void test() {39 XmlSuite suite = new XmlSuite();40 suite.getTest("test").getXmlClasses().get(0).getIncludedMethods().get(0).getMethodName();41 }42}43public class TestNGTest {44 public void test() {

Full Screen

Full Screen

getTest

Using AI Code Generation

copy

Full Screen

1import org.testng.xml.XmlSuite;2public class TestNGXmlSuiteGetTest {3public static void main(String[] args) {4 XmlSuite xmlSuite = new XmlSuite();5 xmlSuite.setName("TestNG Suite");6 xmlSuite.setParallel(XmlSuite.ParallelMode.METHODS);7 xmlSuite.setThreadCount(5);8 XmlTest xmlTest = new XmlTest(xmlSuite);9 xmlTest.setName("TestNG Test");10 System.out.println("xmlSuite.getTests().size() = " + xmlSuite.getTests().size());11 System.out.println("xmlSuite.getTests().get(0) = " + xmlSuite.getTests().get(0));12 System.out.println("xmlSuite.getTests().get(0).getName() = " + xmlSuite.getTests().get(0).getName());13}14}15xmlSuite.getTests().size() = 116xmlSuite.getTests().get(0) = org.testng.xml.XmlTest@1b6d358617xmlSuite.getTests().get(0).getName() = TestNG Test18Related posts: TestNG XmlSuite getParallel() Method Example TestNG XmlSuite getParameter() Method Example TestNG XmlSuite getParameters() Method Example TestNG XmlSuite getParameterTypes() Method Example TestNG XmlSuite getPreserveOrder() Method Example TestNG XmlSuite getSkipFailedInvocationCounts() Method Example TestNG XmlSuite getThreadCount() Method Example TestNG XmlSuite getVerbose() Method Example TestNG XmlSuite getXmlClasses() Method Example TestNG XmlSuite getXmlPackages() Method Example TestNG XmlSuite getXmlSuiteFiles() Method Example TestNG XmlSuite getXmlTestFiles() Method Example TestNG XmlSuite getXmlTests() Method Example TestNG XmlSuite getXmlVersion() Method Example TestNG XmlSuite isAllowReturnValues() Method Example TestNG XmlSuite isConfigFailurePolicy() Method Example TestNG XmlSuite isGroupByInstances() Method

Full Screen

Full Screen

getTest

Using AI Code Generation

copy

Full Screen

1package com.qa.test;2import java.util.List;3import org.testng.annotations.Test;4import org.testng.xml.XmlSuite;5public class GetTest {6public void getTest() {7XmlSuite suite = new XmlSuite();8List<String> tests = suite.getTests();9System.out.println(tests);10}11}12Recommended Posts: TestNG | getParameter() method13TestNG | getParameterTypes() method14TestNG | getParameterNames() method15TestNG | getParameterValues() method16TestNG | getParameterInvocationCount() method17TestNG | getParameterTypesForMethod() method18TestNG | getParameterNamesForMethod() method19TestNG | getParameterValuesForMethod() method20TestNG | getParameterInvocationCountForMethod() method21TestNG | getParameterAnnotation() method22TestNG | getParameterAnnotationForMethod() method23TestNG | getParameterAnnotationForClass() method24TestNG | getParameterAnnotationForMethodAndClass() method25TestNG | getParameterAnnotationForMethodAndClass() method26TestNG | getParameters() method27TestNG | getParameterTypes() method28TestNG | getParameterNames() method29TestNG | getParameterValues() method30TestNG | getParameterInvocationCount() method31TestNG | getParameterTypesForMethod() method

Full Screen

Full Screen

getTest

Using AI Code Generation

copy

Full Screen

1String testName = XmlSuite.getTest().getName();2extent.setSystemInfo("Test Name", testName);3extent.setSystemInfo("Test Environment", "QA");4extent.setSystemInfo("Browser", "Chrome");5extent.setSystemInfo("User Name", "Selenium");6extent.setSystemInfo("Operating System", "Windows");7extent.setSystemInfo("Host Name", "Local");8extent.setSystemInfo("Application Name", "TestNG");9extent.setSystemInfo("Application Version", "1.0");10extent.setSystemInfo("Application Build", "1.0.1");11extent.setSystemInfo("Application Build Date", "10/10/2017");12extent.setSystemInfo("Application Build Number", "100");13extent.setSystemInfo("Application Build Version", "

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful