コード例 #1
0
  @Override
  public void onStart(ITestContext context) {
    CommonUtils.createDirectory(screenDirPath);
    imageCounter = 0;
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();

    StringBuilder builder = new StringBuilder();
    builder.append(
        "<html><style>"
            + "table {margin:0 auto;}td:first-child {width:200px;}td:nth-child(2) {width:660px;}td:nth-child(3) "
            + "{width:100px;}tr.success{color:black;background-color:#CCFFCC;}"
            + "tr.warning{color:black;background-color:#FEE01E;}"
            + "tr.error{color:black;background-color:#FFCCCC;}"
            + "tr.step{color:white;background:grey}"
            + "</style><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
            + "<style>td { border-top: 1px solid grey; } </style></head><body>"
            + "<script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.8.2.min.js\"></script>"
            + "<p>Date: "
            + DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ")
                .print(DateTime.now(DateTimeZone.UTC))
            + "</p>"
            + "<p>Polish Time: "
            + DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss ZZ")
                .print(
                    DateTime.now()
                        .withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Europe/Warsaw"))))
            + "</p>"
            + "<p>Browser: "
            + Configuration.getBrowser()
            + "</p>"
            + "<p>OS: "
            + System.getProperty("os.name")
            + "</p>"
            + "<p>Testing environment: "
            + new UrlBuilder().getUrlForWiki(Configuration.getWikiName())
            + "</p>"
            + "<p>Testing environment: "
            + Configuration.getEnv()
            + "</p>"
            + "<p>Tested version: "
            + "TO DO: GET WIKI VERSION HERE"
            + "</p>"
            + "<div id='toc'></div>");
    CommonUtils.appendTextToFile(logPath, builder.toString());
    appendShowHideButtons();
    try {
      FileInputStream input = new FileInputStream("./src/test/resources/script.txt");
      String content = IOUtils.toString(input);
      CommonUtils.appendTextToFile(logPath, content);
    } catch (IOException e) {
      System.out.println("no script.txt file available");
    }
  }
コード例 #2
0
  @Override
  public void onTestStart(ITestResult result) {
    logsResults.clear();
    StringBuilder builder = new StringBuilder();
    String testName = result.getName().toString();
    String className = result.getTestClass().getName().toString();

    Method testMethod = result.getMethod().getConstructorOrMethod().getMethod();

    builder.append("<table>" + "<h1>Class: <em>" + className + "." + testName + " </em></h1>");
    if (testMethod.isAnnotationPresent(RelatedIssue.class)) {
      String issueID = testMethod.getAnnotation(RelatedIssue.class).issueID();
      String jiraUrl = jiraPath + issueID;
      builder.append(
          "<tr class=\"step\"><td>Known failure</td><td><h1><em>"
              + testName
              + " - "
              + "<a href=\""
              + jiraUrl
              + "\">"
              + issueID
              + "</a> "
              + testMethod.getAnnotation(RelatedIssue.class).comment()
              + "</em></h1></td><td> <br/> &nbsp;</td></tr>");
    } else {
      builder.append(
          "<tr class=\"step\"><td>&nbsp</td><td><h1><em>"
              + testName
              + "</em></h1></td><td> <br/> &nbsp;</td></tr>");
    }
    CommonUtils.appendTextToFile(logPath, builder.toString());
    System.out.println(className + " " + testName);
  }
コード例 #3
0
  private static void log(String command, String description, boolean success, boolean ifLowLevel) {
    logsResults.add(success);
    String escapedDescription = escapeHtml(description);

    String className = success ? "success" : "error";
    StringBuilder builder = new StringBuilder();
    if (ifLowLevel) {
      builder.append(
          "<tr class=\""
              + className
              + " lowLevelAction"
              + "\"><td>"
              + command
              + "</td><td>"
              + escapedDescription
              + "</td><td> <br/> &nbsp;</td></tr>");
    } else {
      builder.append(
          "<tr class=\""
              + className
              + "\"><td>"
              + command
              + "</td><td>"
              + escapedDescription
              + "</td><td> <br/> &nbsp;</td></tr>");
    }
    CommonUtils.appendTextToFile(logPath, builder.toString());
    logJSError(NewDriverProvider.getWebDriver());
  }
コード例 #4
0
 private void appendShowHideButtons() {
   String hideButton = "<button id=\"hideLowLevel\">hide low level actions</button>";
   String showButton = "<button id=\"showLowLevel\">show low level actions</button>";
   StringBuilder builder = new StringBuilder();
   builder.append(hideButton);
   builder.append(showButton);
   CommonUtils.appendTextToFile(logPath, builder.toString());
 }
コード例 #5
0
 @Override
 public void afterChangeValueOf(WebElement element, WebDriver driver) {
   StringBuilder builder = new StringBuilder();
   builder.append(
       "<tr class=\"success lowLevelAction\"><td>ChangeValueOfField</td><td>"
           + lastFindBy
           + "</td><td> <br/> &nbsp;</td></tr>");
   CommonUtils.appendTextToFile(logPath, builder.toString());
 }
コード例 #6
0
 @Override
 public void beforeNavigateTo(String url, WebDriver driver) {
   StringBuilder builder = new StringBuilder();
   builder.append(
       "<tr class=\"success\"><td>Navigate to</td><td>"
           + url
           + "</td><td> <br/> &nbsp;</td></tr>");
   CommonUtils.appendTextToFile(logPath, builder.toString());
   logJSError(driver);
 }
コード例 #7
0
 @Override
 public void onTestSuccess(ITestResult result) {
   StringBuilder builder = new StringBuilder();
   builder.append(
       "<tr class=\"step\">"
           + "<td>&nbsp</td><td>STOP LOGGING METHOD  "
           + "<div style=\"text-align:center\">"
           + "<a href=\"#toc\" style=\"color:blue\">"
           + "<b>BACK TO MENU</b></a></div> </td><td> <br/> &nbsp;</td></tr>"
           + "</table>");
   CommonUtils.appendTextToFile(logPath, builder.toString());
 }
コード例 #8
0
 public static void log(String command, String description, boolean success, WebDriver driver) {
   logsResults.add(success);
   imageCounter += 1;
   new Shooter().savePageScreenshot(screenPath + imageCounter, driver);
   CommonUtils.appendTextToFile(screenPath + imageCounter + ".html", getPageSource(driver));
   String className = success ? "success" : "error";
   StringBuilder builder = new StringBuilder();
   builder.append(
       "<tr class=\""
           + className
           + "\"><td>"
           + command
           + "</td><td>"
           + description
           + "</td><td> <br/><a href='screenshots/screenshot"
           + imageCounter
           + ".png'>Screenshot</a><br/><a href='screenshots/screenshot"
           + imageCounter
           + ".html'>HTML Source</a></td></tr>");
   CommonUtils.appendTextToFile(logPath, builder.toString());
   logJSError(driver);
 }
コード例 #9
0
  @Override
  public void onTestFailure(ITestResult result) {
    driver = NewDriverProvider.getWebDriver();
    if (driver == null) {
      driver = NewDriverProvider.getWebDriver();
    }

    imageCounter += 1;
    if ("true".equals(Configuration.getLogEnabled())) {
      try {
        new Shooter().savePageScreenshot(screenPath + imageCounter, driver);
        CommonUtils.appendTextToFile(screenPath + imageCounter + ".html", getPageSource(driver));
      } catch (Exception e) {
        log(
            "onException",
            "driver has no ability to catch screenshot or html source - driver may died",
            false);
      }

      String exception =
          escapeHtml(
              result.getThrowable().toString()
                  + "\n"
                  + ExceptionUtils.getStackTrace(result.getThrowable()));

      StringBuilder builder = new StringBuilder();
      builder.append(
          "<tr class=\"error\"><td>error</td><td><pre>"
              + exception
              + "</pre></td><td> <br/><a href='screenshots/screenshot"
              + imageCounter
              + ".png'>Screenshot</a><br/><a href='screenshots/screenshot"
              + imageCounter
              + ".html'>HTML Source</a></td></tr>");
      CommonUtils.appendTextToFile(logPath, builder.toString());
      logJSError(driver);
      onTestSuccess(result);
    }
  }
コード例 #10
0
 private static void logJSError(WebDriver driver) {
   if ("true".equals(Configuration.getJSErrorsEnabled())) {
     JavascriptExecutor js = (JavascriptExecutor) driver;
     List<String> error =
         (ArrayList<String>) js.executeScript("return window.JSErrorCollector_errors.pump()");
     if (!error.isEmpty()) {
       StringBuilder builder = new StringBuilder();
       builder.append(
           "<tr class=\"error\"><td>click</td><td>" + error + "</td><td> <br/> &nbsp;</td></tr>");
       CommonUtils.appendTextToFile(logPath, builder.toString());
     }
   }
 }
コード例 #11
0
 public static void logImage(String command, String imageAsBase64, boolean success) {
   imageAsBase64 = "<img src=\"data:image/png;base64," + imageAsBase64 + "\">";
   String className = success ? "success" : "error";
   CommonUtils.appendTextToFile(
       logPath,
       ("<tr class=\""
           + className
           + "\"><td>"
           + command
           + "</td><td>"
           + imageAsBase64
           + "</td><td> <br/> &nbsp;</td></tr>"));
 }
コード例 #12
0
 /** This method will log warning to log file (line in yellow color) */
 public static void logWarning(String command, String description) {
   StringBuilder builder =
       new StringBuilder()
           .append(
               "<tr class=\"warning\">"
                   + "<td>"
                   + command
                   + "</td>"
                   + "<td>"
                   + description
                   + "</td>"
                   + "<td> <br/> &nbsp;</td></tr>");
   CommonUtils.appendTextToFile(logPath, builder.toString());
 }
コード例 #13
0
 @Override
 public void afterNavigateTo(String url, WebDriver driver) {
   StringBuilder builder = new StringBuilder();
   if (!AlertHandler.isAlertPresent(driver)) {
     if (url.equals(driver.getCurrentUrl())) {
       builder.append(
           "<tr class=\"success\"><td>Url after navigation</td><td>"
               + driver.getCurrentUrl()
               + "</td><td> <br/> &nbsp;</td></tr>");
       CommonUtils.appendTextToFile(logPath, builder.toString());
     } else {
       if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) {
         driver.get(url);
       }
       logWarning("Url after navigation", driver.getCurrentUrl());
     }
   } else {
     logWarning("Url after navigation", "Unable to check URL after navigation - alert present");
   }
   logJSError(driver);
 }
コード例 #14
0
 @Override
 public void onFinish(ITestContext context) {
   CommonUtils.appendTextToFile(logPath, "</body></html>");
 }