Пример #1
0
  /**
   * Verify strings. Using for comparing displayed text.
   *
   * @param exp
   * @param obs
   * @param pro
   * @return [boolean]
   * @throws Exception
   */
  public boolean QVerify(String exp, String obs, int pro) throws Exception {
    /*
     * pro:
     * 0:Expected is Equal	(e.g: return TRUE if a=a);
     * 1:Expected is NOT equal. (e.g: return TRUE if a=a)
     */
    try {
      // handle logging text START
      String logExp, logObs;
      if (exp.length() > 50) {
        logExp = StringUtils.mid(exp, 0, 50) + "...";
      } else {
        logExp = StringUtils.mid(exp, 0, exp.length());
      } // Cut expected string for Reporting
      if (exp.length() > 50) {
        logObs = StringUtils.mid(obs, 0, 50) + "...";
      } else {
        logObs = StringUtils.mid(obs, 0, obs.length());
      } // Cut observed string for Reporting
      if (StringUtils.indexOf(logObs, "\n") > 0) {
        logObs = StringUtils.mid(logObs, 0, StringUtils.indexOf(obs, "\n"));
      }
      ; // Again cut observed string for Reporting

      // handle logging text END

      if (StringUtils.containsIgnoreCase(obs.trim(), exp.trim()) == true) {
        if (pro == 0) {
          logStep("", "TRUE", "Expectation: " + logExp + " , " + "Observation: " + logObs);
          return true;
        } else {
          logStep("", "FALSE", "Expectation: " + logExp + " , " + "Observation: " + logObs);
          return false;
        }
      } else {
        if (pro == 0) {
          logStep("", "FALSE", "Expectation: " + logExp + " , " + "Observation: " + logObs);
          return false;
        } else {
          logStep("", "TRUE", "Expectation: " + logExp + " , " + "Observation: " + logObs);
          return true;
        }
      }
    } catch (Exception e) {
      logStep("", "FALSE", "Expectation: " + exp.trim() + " , " + "Observation: " + obs.trim());
      return false;
    }
  }
Пример #2
0
 /**
  * Log a step into test case result.
  *
  * @param tcName
  * @param result
  * @param msg
  */
 public void logStep(String tcName, String result, String msg) {
   if ("".equals(tcName)) {
     tcName = oi.logRunningTC;
     if (!"".equals(result.trim())) {
       if ("false".equals(StringUtils.lowerCase(result.trim()))) {
         oi.logList.add(
             tcName
                 + ","
                 + result.trim()
                 + ",At step "
                 + init.currentStep
                 + " of "
                 + init.sumStep
                 + ","
                 + msg.trim());
       } else {
         oi.logList.add(tcName + "," + result.trim() + "," + msg.trim());
       }
     }
   } else {
     if (StringUtils.left(tcName, 4).equals("test")) {
       tcName = StringUtils.mid(tcName, 4, tcName.length());
     }
     oi.logRunningTC = tcName;
     if ("".equals(result.trim())) {
       oi.logList.add(tcName + "," + init.logTcStart);
     } else {
       oi.logList.add(tcName + "," + result.trim());
     }
   }
 }
  /**
   * Tokenize the input line with the given deliminator and populate the given object with values of
   * the tokens
   *
   * @param targetObject the target object
   * @param line the input line
   * @param delim the deminator that separates the fields in the given line
   * @param keyFields the specified fields
   */
  public static void convertLineToBusinessObject(
      Object targetObject, String line, int[] fieldLength, List<String> keyFields) {
    String[] tokens = new String[fieldLength.length];

    int currentPosition = 0;
    for (int i = 0; i < fieldLength.length; i++) {
      currentPosition = i <= 0 ? 0 : fieldLength[i - 1] + currentPosition;
      tokens[i] = StringUtils.mid(line, currentPosition, fieldLength[i]).trim();
    }
    ObjectUtil.buildObject(targetObject, tokens, keyFields);
  }
Пример #4
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 + "-";
  }