Ejemplo n.º 1
0
  /**
   * Take a screenshoot, log an Running Error into test result file.
   *
   * @param e
   * @param dr
   * @param tcName
   * @throws Exception
   */
  public void logCaseFail(String e, WebDriver dr, String tcName) throws Exception {
    try {
      if (tcName.trim() == "") {
        tcName = oi.logRunningTC;
      }

      if (StringUtils.left(tcName, 4).equals("test")) {
        tcName = StringUtils.mid(tcName, 4, tcName.length());
      }

      // log fail

      System.out.println(init.logErrorPrefixMsg + "Test Case Name:" + tcName + " ERROR: " + e);
      String tmp = "" + ran.nextInt(100000);
      String picName = oi.reportFilePath + "pic-" + tmp + ".jpg";

      String tmpStepLog = "";
      tmpStepLog = ",At step " + init.currentStep + " of " + init.sumStep;

      if (e.contains("\n")) {
        oi.logList.add(
            tcName
                + ","
                + init.logErrorPrefixMsg
                + tmpStepLog
                + ","
                + " Photo: "
                + picName
                + ","
                + e.toString().substring(0, e.toString().indexOf("\n")));
      } else {
        oi.logList.add(
            tcName
                + ","
                + init.logErrorPrefixMsg
                + tmpStepLog
                + ","
                + " Photo: "
                + picName
                + ","
                + e);
      }

      // taking screenshot
      org.apache.commons.io.FileUtils.copyFile(
          ((TakesScreenshot) dr).getScreenshotAs(OutputType.FILE), new File(picName));
    } catch (Exception e1) {
      throw e1;
    }

    // oi.reportFilePath = oi.reportFilePath + "error-" + tmp + "-";
  }