Exemplo n.º 1
0
 @Override
 public void scenario(Scenario scenario) {
   replay();
   featureElementTags = scenario.getTags();
   featureElementName = scenario.getName();
   featureElementRange = scenario.getLineRange();
   featureElementEvents = new ArrayList<BasicStatement>();
   featureElementEvents.add(scenario);
 }
    private Element writeTo(Document doc) {
      Element tc = doc.createElement("testcase");
      tc.setAttribute("classname", feature.getName());
      tc.setAttribute(
          "name", examples > 0 ? scenario.getName() + "_" + examples-- : scenario.getName());
      long totalDurationNanos = 0;
      for (Result r : results) {
        totalDurationNanos += r.getDuration() == null ? 0 : r.getDuration();
      }

      double totalDurationSeconds = ((double) totalDurationNanos) / 1000000000;
      String time = NUMBER_FORMAT.format(totalDurationSeconds);
      tc.setAttribute("time", time);

      StringBuilder sb = new StringBuilder();
      Result skipped = null, failed = null;
      for (int i = 0; i < steps.size(); i++) {
        int length = sb.length();
        Result result = results.get(i);
        if ("failed".equals(result.getStatus())) failed = result;
        if ("undefined".equals(result.getStatus()) || "pending".equals(result.getStatus()))
          skipped = result;
        sb.append(steps.get(i).getKeyword());
        sb.append(steps.get(i).getName());
        for (int j = 0; sb.length() - length + j < 140; j++) sb.append(".");
        sb.append(result.getStatus());
        sb.append("\n");
      }
      Element child;
      if (failed != null) {
        sb.append("\nStackTrace:\n");
        StringWriter sw = new StringWriter();
        failed.getError().printStackTrace(new PrintWriter(sw));
        sb.append(sw.toString());
        child = doc.createElement("failure");
        child.setAttribute("message", failed.getErrorMessage());
        child.appendChild(doc.createCDATASection(sb.toString()));
      } else if (skipped != null) {
        child = doc.createElement("skipped");
        child.appendChild(doc.createCDATASection(sb.toString()));
      } else {
        child = doc.createElement("system-out");
        child.appendChild(doc.createCDATASection(sb.toString()));
      }
      tc.appendChild(child);
      return tc;
    }
 @Override
 public void scenario(Scenario scenario) {
   org.testng.Reporter.log("<div class=\"scenario\">Scenario: " + scenario.getName() + "</div>");
 }