Exemple #1
0
  private void loadParameter(Element elem) {
    logger.info("loadParameter: fileName=" + elem.getAttributeValue("file"));
    String parameterFile = elem.getAttributeValue("file");
    String absolutePath = getAbsolutePath(parameterFile);
    BasicConfigurator.configure();

    try {
      InputStream in = new FileInputStream(absolutePath);
      Properties parameter = new Properties();
      parameter.load(in);
      in.close();

      Set<Entry<Object, Object>> entrySet = parameter.entrySet();

      for (Map.Entry entry : entrySet) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        System.out.println(key + " = " + value);
        addParam(key, value);
      }
    } catch (Exception e) {
      logger.error("Can not load parameter . ");
    }

    String newStr =
        replaceParam(elem.getAttributeValue("src1")) + replaceParam(elem.getAttributeValue("src2"));
    addParam(elem.getAttributeValue("out"), newStr);
  }
Exemple #2
0
 /**
  * Gets the visible (displayed) value of a list box
  *
  * @param elem
  */
 private void getSelectedLabel(Element elem) {
   String locator = elem.getAttributeValue("locator");
   String out = elem.getAttributeValue("out");
   String text = this.sel.getSelectedLabel(locator);
   logger.info("getSelectedValue: locator=" + locator + " text=" + text);
   addParam(out, text);
 }
Exemple #3
0
  private void callByReflection(Element elem) {
    String methodName = elem.getName();
    String param1 = elem.getAttributeValue("param1");
    String param2 = elem.getAttributeValue("param2");

    Class[] paramTypes = null;
    Object[] args = null;
    if ((param1 != null) && (param2 != null)) {
      paramTypes = new Class[] {String.class, String.class};
      args = new Object[] {replaceParam(param1), replaceParam(param2)};
    } else if (param1 != null) {
      paramTypes = new Class[] {String.class};
      args = new Object[] {replaceParam(param1)};
    } else {
      paramTypes = new Class[] {};
      args = new Object[] {};
    }

    // Capture the output name for "get" methods
    String out = elem.getAttributeValue("out");

    Method m;
    try {
      m = (Method) this.sel.getClass().getDeclaredMethod(methodName, paramTypes);
      Object results = m.invoke(this.sel, args);

      // Add output parameter to common map
      if ((out != null) && (results != null)) {
        addParam(out, results);
      }
    } catch (Exception e) {
      logger.error("Exception occurred when Unknown SeleniumXml command found:" + elem.getName());
      e.printStackTrace();
    }
  }
Exemple #4
0
 private void randomStringCmd(Element elem) {
   String paramName = elem.getAttributeValue("out");
   String size = elem.getAttributeValue("size");
   String prefix = elem.getAttributeValue("prefix");
   String paramValue = TestUtils.createRandomString(prefix, Integer.parseInt(size));
   logger.info("randomStringCmd: paramName=" + paramName + " paramValue=" + paramValue);
   addParam(paramName, paramValue);
 }
Exemple #5
0
 private void appendCmd(Element elem) {
   logger.info(
       "appendCmd: src1="
           + elem.getAttributeValue("src1")
           + " src2="
           + elem.getAttributeValue("src2"));
   String newStr =
       replaceParam(elem.getAttributeValue("src1")) + replaceParam(elem.getAttributeValue("src2"));
   addParam(elem.getAttributeValue("out"), newStr);
 }
Exemple #6
0
  /*
   * captureText command captures the current HTML page and runs a regex to
   * get the specified string.
   *
   * For example:  if the following string existed in a web page
   *   "xx <tag a=b> yy </tag> zz"
   * And you wanted to capture the value in the of the XML (yy).  You would do the following;
   * Use regxp: "<(\\S+?).*?>(.*?)</\\1>";  //The \\1 reuses group 1
   *
   * <captureText regex="<(\\S+?).*?>(.*?)</\\1>" group="2" results="xmlValue" />
   *
   * The command will find the <tag>.. and group 2 contains the 'yy' value.
   *
   * Note: if 'group' is null it will default to the entire regex group.
   */
  private void captureTextInPageCmd(Element elem) {
    String regex = elem.getAttributeValue("regex");
    String group = elem.getAttributeValue("group");
    String results = elem.getAttributeValue("results");
    Pattern pattern = Pattern.compile(regex);
    String targetString = this.sel.getHtmlSource();

    // Create the 'target' string we wish to interrogate.
    // Get a Matcher based on the target string.
    Matcher matcher = pattern.matcher(targetString);

    // Find all the matches.
    if (matcher.find()) {
      String resultsValue = null;
      if (group != null) {
        resultsValue = matcher.group(Integer.parseInt(group));
      } else {
        resultsValue = matcher.group();
      }
      logger.info("Found match for " + resultsValue);
      logger.debug("Using regex " + regex);
      logger.debug("Copy results to " + results);
      addParam(results, resultsValue);
    } else {
      logger.info("Didn't find results with regex: " + regex);

      // TODO: temporary to capture the missed string
      /*try {
            FileWriter out = new FileWriter("c:/dev/erep/output/failure.txt");
            BufferedWriter buffWriter = new BufferedWriter(out);
            buffWriter.write(targetString);
            out.flush();
            out.close();
      } catch (IOException e) {
            System.err.println(e);
      } */
    }
  }
Exemple #7
0
  private void randomAlphaStringCmd(Element elem) {
    int nSize = 0;
    int nPrefixSize = 0;
    String paramName = elem.getAttributeValue("out");
    String size = elem.getAttributeValue("size");
    if (size != null) {
      nSize = Integer.parseInt(size);
    }
    String prefix = elem.getAttributeValue("prefix");
    if (prefix != null) {
      nPrefixSize = prefix.length();
    }

    String paramValue = null;
    if (prefix != null) {
      paramValue = prefix + RandomStringUtils.randomAlphabetic(nSize - nPrefixSize);
    } else {
      paramValue = RandomStringUtils.randomAlphabetic(nSize);
    }
    // String paramValue = TestUtils.createRandomString(prefix, Integer.parseInt(size));
    logger.info("randomStringAlphaCmd: paramName=" + paramName + " paramValue=" + paramValue);
    addParam(paramName, paramValue);
  }
Exemple #8
0
 private void copyCmd(Element elem) {
   String toStr = replaceParam(elem.getAttributeValue("to"));
   String fromStr = replaceParam(elem.getAttributeValue("from"));
   logger.info("copyCmd: to=" + toStr + " from=" + fromStr);
   addParam(toStr, fromStr);
 }
Exemple #9
0
 private void uniqueIdCmd(Element elem) {
   String paramName = elem.getAttributeValue("out");
   String paramValue = RandomStringUtils.randomAlphanumeric(MAX_STR_LENGTH).toUpperCase();
   logger.info("uniqueIdCmd: parameter=" + paramName + " value=" + paramValue);
   addParam(paramName, paramValue);
 }
Exemple #10
0
 private void getBodyText(Element elem) {
   String paramName = elem.getAttributeValue("out");
   String text = this.sel.getBodyText();
   addParam(paramName, text);
 }
Exemple #11
0
 private void getHtmlSource(Element elem) {
   String paramName = elem.getAttributeValue("out");
   String text = this.sel.getHtmlSource();
   logger.info("getHtmlsource: paramName=" + paramName + " text=" + text);
   addParam(paramName, text);
 }
Exemple #12
0
 private void getSelectedId(Element elem) {
   String locator = elem.getAttributeValue("locator");
   String out = elem.getAttributeValue("out");
   String text = this.sel.getSelectedId(locator);
   addParam(out, text);
 }