How to use newArrayList method of org.testng.collections.Lists class

Best Testng code snippet using org.testng.collections.Lists.newArrayList

Source:Model.java Github

copy

Full Screen

...20 private Map<ITestResult, String> m_testResultMap = Maps.newHashMap();21 private Map<ISuite, ResultsByClass> m_failedResultsByClass = Maps.newHashMap();22 private Map<ISuite, ResultsByClass> m_skippedResultsByClass = Maps.newHashMap();23 private Map<ISuite, ResultsByClass> m_passedResultsByClass = Maps.newHashMap();24 private List<ITestResult> m_allFailedResults = Lists.newArrayList();25 // Each suite is mapped to failed.png, skipped.png or nothing (which means passed.png)26 private Map<String, String> m_statusBySuiteName = Maps.newHashMap();27 private SetMultiMap<String, String> m_groupsBySuiteName = Maps.newSetMultiMap();28 private SetMultiMap<String, String> m_methodsByGroup = Maps.newSetMultiMap();29 public Model(List<ISuite> suites) {30 m_suites = suites;31 init();32 }33 public List<ISuite> getSuites() {34 return m_suites;35 }36 private void init() {37 int testCounter = 0;38 for (ISuite suite : m_suites) {39 List<ITestResult> passed = Lists.newArrayList();40 List<ITestResult> failed = Lists.newArrayList();41 List<ITestResult> skipped = Lists.newArrayList();42 Map<String, ISuiteResult> suiteResults = suite.getResults();43 for (ISuiteResult sr : suiteResults.values()) {44 ITestContext context = sr.getTestContext();45 m_testTags.put(context.getName(), "test-" + testCounter++);46 failed.addAll(context.getFailedTests().getAllResults());47 skipped.addAll(context.getSkippedTests().getAllResults());48 passed.addAll(context.getPassedTests().getAllResults());49 IResultMap[] map =50 new IResultMap[] {51 context.getFailedTests(), context.getSkippedTests(), context.getPassedTests()52 };53 for (IResultMap m : map) {54 for (ITestResult tr : m.getAllResults()) {55 m_testResultMap.put(tr, getTestResultName(tr));56 }57 }58 }59 // Process them in the order passed, skipped and failed, so that the failed60 // icon overrides all the others and the skipped icon overrides passed.61 // Passed62 {63 ResultsByClass rbc = new ResultsByClass();64 for (ITestResult tr : passed) {65 rbc.addResult(tr.getTestClass().getRealClass(), tr);66 updateGroups(suite, tr);67 }68 m_passedResultsByClass.put(suite, rbc);69 }70 // Skipped71 {72 ResultsByClass rbc = new ResultsByClass();73 for (ITestResult tr : skipped) {74 m_statusBySuiteName.put(suite.getName(), "skipped");75 rbc.addResult(tr.getTestClass().getRealClass(), tr);76 updateGroups(suite, tr);77 }78 m_skippedResultsByClass.put(suite, rbc);79 }80 // Failed81 {82 ResultsByClass rbc = new ResultsByClass();83 for (ITestResult tr : failed) {84 m_statusBySuiteName.put(suite.getName(), "failed");85 rbc.addResult(tr.getTestClass().getRealClass(), tr);86 m_allFailedResults.add(tr);87 updateGroups(suite, tr);88 }89 m_failedResultsByClass.put(suite, rbc);90 }91 m_model.putAll(suite, failed);92 m_model.putAll(suite, skipped);93 m_model.putAll(suite, passed);94 }95 }96 private void updateGroups(ISuite suite, ITestResult tr) {97 String[] groups = tr.getMethod().getGroups();98 m_groupsBySuiteName.putAll(suite.getName(), Arrays.asList(groups));99 for (String group : groups) {100 m_methodsByGroup.put(group, tr.getMethod().getMethodName());101 }102 }103 public ResultsByClass getFailedResultsByClass(ISuite suite) {104 return m_failedResultsByClass.get(suite);105 }106 public ResultsByClass getSkippedResultsByClass(ISuite suite) {107 return m_skippedResultsByClass.get(suite);108 }109 public ResultsByClass getPassedResultsByClass(ISuite suite) {110 return m_passedResultsByClass.get(suite);111 }112 public String getTag(ITestResult tr) {113 return m_testResultMap.get(tr);114 }115 public List<ITestResult> getTestResults(ISuite suite) {116 return m_model.get(suite);117 }118 public static String getTestResultName(ITestResult tr) {119 StringBuilder result = new StringBuilder(tr.getMethod().getMethodName());120 Object[] parameters = tr.getParameters();121 if (parameters.length > 0) {122 result.append("(");123 StringBuilder p = new StringBuilder();124 for (int i = 0; i < parameters.length; i++) {125 if (i > 0) p.append(", ");126 p.append(Utils.toString(parameters[i]));127 }128 if (p.length() > 100) {129 String s = p.toString().substring(0, 100);130 s = s + "...";131 result.append(s);132 } else {133 result.append(p.toString());134 }135 result.append(")");136 }137 return result.toString();138 }139 public List<ITestResult> getAllFailedResults() {140 return m_allFailedResults;141 }142 public static String getImage(String tagClass) {143 return tagClass + ".png";144 }145 public String getStatusForSuite(String suiteName) {146 String result = m_statusBySuiteName.get(suiteName);147 return result != null ? result : "passed";148 }149 public List<String> getGroups(String name) {150 List<String> result = Lists.newArrayList(m_groupsBySuiteName.get(name));151 Collections.sort(result);152 return result;153 }154 public List<String> getMethodsInGroup(String groupName) {155 List<String> result = Lists.newArrayList(m_methodsByGroup.get(groupName));156 Collections.sort(result);157 return result;158 }159 public List<ITestResult> getAllTestResults(ISuite suite) {160 return getAllTestResults(suite, true /* tests only */);161 }162 public List<ITestResult> getAllTestResults(ISuite suite, boolean testsOnly) {163 List<ITestResult> result = Lists.newArrayList();164 for (ISuiteResult sr : suite.getResults().values()) {165 result.addAll(sr.getTestContext().getPassedTests().getAllResults());166 result.addAll(sr.getTestContext().getFailedTests().getAllResults());167 result.addAll(sr.getTestContext().getSkippedTests().getAllResults());168 if (!testsOnly) {169 result.addAll(sr.getTestContext().getPassedConfigurations().getAllResults());170 result.addAll(sr.getTestContext().getFailedConfigurations().getAllResults());171 result.addAll(sr.getTestContext().getSkippedConfigurations().getAllResults());172 }173 }174 return result;175 }176}...

Full Screen

Full Screen

Source:AlphabeticalMethodInterceptor.java Github

copy

Full Screen

...16import org.testng.collections.Maps;17public class AlphabeticalMethodInterceptor implements IMethodInterceptor {18 @Override19 public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {20 List<Object> instanceList = Lists.newArrayList();21 Map<Object, List<IMethodInstance>> map = Maps.newHashMap();22 for (IMethodInstance mi : methods) {23 Object instance = mi.getInstance();24 if (!instanceList.contains(instance)) {25 instanceList.add(instance);26 }27 List<IMethodInstance> l = map.computeIfAbsent(instance, k -> Lists.newArrayList());28 l.add(mi);29 }30 Comparator<IMethodInstance> comparator = Comparator.comparing(o -> o.getMethod().getMethodName());31 List<IMethodInstance> result = Lists.newArrayList();32 for (Object instance : instanceList) {33 List<IMethodInstance> methodlist = map.get(instance);34 IMethodInstance[] array = methodlist.toArray(new IMethodInstance[methodlist.size()]);35 Arrays.sort(array, comparator);36 result.addAll(Arrays.asList(array));37 }38 System.out.println("AlphabeticalMethodInterceptor: "+result);39 return result;40 }41}...

Full Screen

Full Screen

Source:XmlRun.java Github

copy

Full Screen

...21 xsb.pop("run");22 }23 return xsb.toXML();24 }25 private List<String> m_excludes = Lists.newArrayList();26 public List<String> getExcludes() {27 return m_excludes;28 }29 @OnElement(tag = "exclude", attributes = "name")30 public void onExclude(String name) {31 m_excludes.add(name);32 }33 private List<String> m_includes = Lists.newArrayList();34 public List<String> getIncludes() {35 return m_includes;36 }37 @OnElement(tag = "include", attributes = "name")38 public void onInclude(String name) {39 m_includes.add(name);40 }41}...

Full Screen

Full Screen

Source:InstanceOrderingMethodInterceptor.java Github

copy

Full Screen

...10 return groupMethodsByInstance(methods);11 }12 /** The default method interceptor which sorts methods by instances (i.e. by class). */13 private List<IMethodInstance> groupMethodsByInstance(List<IMethodInstance> methods) {14 List<Object> instanceList = Lists.newArrayList();15 Map<Object, List<IMethodInstance>> map = Maps.newLinkedHashMap();16 for (IMethodInstance mi : methods) {17 Object instance = mi.getInstance();18 if (!instanceList.contains(instance)) {19 instanceList.add(instance);20 }21 List<IMethodInstance> l = map.computeIfAbsent(instance, k -> Lists.newArrayList());22 l.add(mi);23 }24 List<IMethodInstance> result = Lists.newArrayList();25 for (Object instance : instanceList) {26 result.addAll(map.get(instance));27 }28 return result;29 }30}

Full Screen

Full Screen

Source:BaseSample.java Github

copy

Full Screen

...4import org.testng.collections.Lists;5import org.testng.collections.Maps;6import java.util.List;7public class BaseSample {8 public static List<String> m_methods = Lists.newArrayList();9 protected void add(String m) {10 String s = m;11// System.out.println("BaseSample recording " + this + " " + s);12 synchronized(m_methods) {13 m_methods.add(s);14 }15 }16 @BeforeClass17 public void bc() {18 m_methods = Lists.newArrayList();19 }20 @Test21 public void f1() { add("f1"); }22 @Test23 public void f2() { add("f2"); }24 @Test25 public void f3() { add("f3"); }26 @Test27 public void f4() { add("f4"); }28 @Test29 public void f5() { add("f5"); }30 @Test31 public void f6() { add("f6"); }32 @Test...

Full Screen

Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

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

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

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

Run Testng automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful