1 package org.testng.reporters.jq; 2 3 import org.testng.IInvokedMethod; 4 import org.testng.ISuite; 5 import org.testng.ITestNGMethod; 6 import org.testng.ITestResult; 7 import org.testng.reporters.XMLStringBuffer; 8 9 import java.util.Collections; 10 import java.util.Comparator; 11 import java.util.List; 12 13 public class ChronologicalPanel extends BaseMultiSuitePanel { 14 15 public ChronologicalPanel(Model model) { 16 super(model); 17 } 18 19 @Override 20 public String getPrefix() { 21 return "chronological-"; 22 } 23 24 @Override 25 public String getHeader(ISuite suite) { 26 return "Methods in chronological order"; 27 } 28 29 @Override 30 public String getContent(ISuite suite, XMLStringBuffer main) { 31 XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent()); 32 List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods(); 33 34 Collections.sort(invokedMethods, new Comparator<IInvokedMethod>() { 35 @Override 36 public int compare(IInvokedMethod arg0, IInvokedMethod arg1) { 37 return (int) 38 (arg0.getTestResult().getStartMillis() - arg1.getTestResult().getStartMillis()); 39 } 40 }); 41 42 String currentClass = ""; 43 long start = 0; 44 for (IInvokedMethod im : invokedMethods) { 45 ITestNGMethod m = im.getTestMethod(); 46 // for (ITestResult tr : results) { 47 // ITestNGMethod m = tr.getMethod(); 48 String cls = "test-method"; 49 if (m.isBeforeSuiteConfiguration()) { 50 cls = "configuration-suite before"; 51 } else if (m.isAfterSuiteConfiguration()) { 52 cls = "configuration-suite after"; 53 } else if (m.isBeforeTestConfiguration()) { 54 cls = "configuration-test before"; 55 } else if (m.isAfterTestConfiguration()) { 56 cls = "configuration-test after"; 57 } else if (m.isBeforeClassConfiguration()) { 58 cls = "configuration-class before"; 59 } else if (m.isAfterClassConfiguration()) { 60 cls = "configuration-class after"; 61 } else if (m.isBeforeMethodConfiguration()) { 62 cls = "configuration-method before"; 63 } else if (m.isAfterMethodConfiguration()) { 64 cls = "configuration-method after"; 65 } 66 ITestResult tr = im.getTestResult(); 67 String methodName = Model.getTestResultName(tr); 68 69 if (!m.getTestClass().getName().equals(currentClass)) { 70 if (!"".equals(currentClass)) { 71 xsb.pop(D); 72 } 73 xsb.push(D, C, "chronological-class"); 74 xsb.addRequired(D, m.getTestClass().getName(), C, "chronological-class-name"); 75 currentClass = m.getTestClass().getName(); 76 } 77 xsb.push(D, C, cls); 78 if (tr.getStatus() == ITestResult.FAILURE) { 79 xsb.push("img", "src", Model.getImage("failed")); 80 xsb.pop("img"); 81 } 82 83 // No need to check for skipped methods since by definition, they were never 84 // invoked. 85 86 xsb.addRequired(S, methodName, C, "method-name"); 87 if (start == 0) { 88 start = tr.getStartMillis(); 89 } 90 xsb.addRequired(S, Long.toString(tr.getStartMillis() - start) + " ms", C, "method-start"); 91 xsb.pop(D); 92 } 93 return xsb.toXML(); 94 } 95 96 @Override 97 public String getNavigatorLink(ISuite suite) { 98 return "Chronological view"; 99 } 100 101 } 102