public static void runVarElement(Element element, boolean commandVar, boolean updateLoggerStatus)
      throws Exception {

    PoshiRunnerStackTraceUtil.setCurrentElement(element);

    if (updateLoggerStatus) {
      XMLLoggerHandler.updateStatus(element, "pending");
    }

    String varName = element.attributeValue("name");
    String varValue = element.attributeValue("value");

    if (varValue == null) {
      if (element.attributeValue("attribute") != null) {
        LiferaySelenium liferaySelenium = SeleniumUtil.getSelenium();

        String attribute = element.attributeValue("attribute");

        String locator = element.attributeValue("locator");

        if (locator.contains("#")) {
          locator = PoshiRunnerContext.getPathLocator(locator);
        }

        varValue = liferaySelenium.getAttribute(locator + "@" + attribute);
      } else if ((element.attributeValue("group") != null)
          && (element.attributeValue("input") != null)
          && (element.attributeValue("pattern") != null)) {

        varValue =
            RegexUtil.replace(
                PoshiRunnerVariablesUtil.replaceCommandVars(element.attributeValue("input")),
                element.attributeValue("pattern"),
                element.attributeValue("group"));
      } else if (element.attributeValue("locator") != null) {
        String locator = element.attributeValue("locator");

        if (locator.contains("#")) {
          locator = PoshiRunnerContext.getPathLocator(locator);
        }

        LiferaySelenium liferaySelenium = SeleniumUtil.getSelenium();

        locator = PoshiRunnerVariablesUtil.replaceCommandVars(locator);

        try {
          if (locator.contains("/input")) {
            varValue = liferaySelenium.getElementValue(locator);
          } else {
            varValue = liferaySelenium.getElementText(locator);
          }
        } catch (Exception e) {
          XMLLoggerHandler.updateStatus(element, "fail");

          throw e;
        }
      } else if (element.attributeValue("method") != null) {
        String classCommandName =
            PoshiRunnerVariablesUtil.replaceCommandVars(element.attributeValue("method"));

        if (classCommandName.startsWith("TestPropsUtil")) {
          classCommandName = classCommandName.replace("TestPropsUtil", "PropsUtil");
        }

        try {
          varValue = PoshiRunnerGetterUtil.getVarMethodValue(classCommandName);
        } catch (Exception e) {
          XMLLoggerHandler.updateStatus(element, "fail");

          Throwable throwable = e.getCause();

          throw new Exception(throwable.getMessage(), e);
        }
      } else if (element.attributeValue("property-value") != null) {
        varValue = PropsUtil.get(element.attributeValue("property-value"));

        if (varValue == null) {
          varValue = "";
        }
      } else {
        varValue = element.getText();
      }
    } else {
      Matcher matcher = _variableMethodPattern.matcher(varValue);

      if (matcher.find()) {
        String method = matcher.group(2);
        String variable = matcher.group(1);

        if (method.equals("length()")) {
          if (PoshiRunnerVariablesUtil.containsKeyInCommandMap(variable)) {

            variable = PoshiRunnerVariablesUtil.getValueFromCommandMap(variable);
          } else {
            throw new Exception("No such variable " + variable);
          }

          varValue = String.valueOf(variable.length());
        } else {
          throw new Exception("No such method " + method);
        }
      }
    }

    String replacedVarValue = PoshiRunnerVariablesUtil.replaceCommandVars(varValue);

    Matcher matcher = _variablePattern.matcher(replacedVarValue);

    if (matcher.matches() && replacedVarValue.equals(varValue)) {
      if (updateLoggerStatus) {
        XMLLoggerHandler.updateStatus(element, "pass");
      }

      return;
    }

    String staticValue = element.attributeValue("static");

    if (commandVar) {
      PoshiRunnerVariablesUtil.putIntoCommandMap(varName, replacedVarValue);
    } else if ((staticValue != null) && staticValue.equals("true")) {
      if (!PoshiRunnerVariablesUtil.containsKeyInStaticMap(varName)) {
        PoshiRunnerVariablesUtil.putIntoStaticMap(varName, replacedVarValue);
      }
    } else {
      PoshiRunnerVariablesUtil.putIntoExecuteMap(varName, replacedVarValue);
    }

    String currentFilePath = PoshiRunnerStackTraceUtil.getCurrentFilePath();

    if (commandVar && currentFilePath.contains(".testcase")) {
      if (PoshiRunnerVariablesUtil.containsKeyInStaticMap(varName)) {
        PoshiRunnerVariablesUtil.putIntoStaticMap(varName, replacedVarValue);
      }
    }

    if (updateLoggerStatus) {
      XMLLoggerHandler.updateStatus(element, "pass");
    }
  }
  public static void runFunctionExecuteElement(Element executeElement) throws Exception {

    if (_functionExecuteElement == null) {
      _functionExecuteElement = executeElement;
    }

    PoshiRunnerStackTraceUtil.setCurrentElement(executeElement);

    List<Element> executeVarElements = executeElement.elements("var");

    for (Element executeVarElement : executeVarElements) {
      runVarElement(executeVarElement, false, false);
    }

    PoshiRunnerStackTraceUtil.setCurrentElement(executeElement);

    String classCommandName = executeElement.attributeValue("function");

    String className = classCommandName;

    if (classCommandName.contains("#")) {
      className = PoshiRunnerGetterUtil.getClassNameFromClassCommandName(classCommandName);
    }

    Exception exception = null;

    int locatorCount = PoshiRunnerContext.getFunctionLocatorCount(className);

    for (int i = 0; i < locatorCount; i++) {
      String locator = executeElement.attributeValue("locator" + (i + 1));

      if (locator == null) {
        locator = PoshiRunnerVariablesUtil.getValueFromCommandMap("locator" + (i + 1));
      }

      if (locator != null) {
        Matcher matcher = _locatorKeyPattern.matcher(locator);

        if (matcher.find() && !locator.contains("/")) {
          String pathClassName = PoshiRunnerGetterUtil.getClassNameFromClassCommandName(locator);

          String locatorKey =
              PoshiRunnerVariablesUtil.replaceCommandVars(
                  PoshiRunnerGetterUtil.getCommandNameFromClassCommandName(locator));

          PoshiRunnerVariablesUtil.putIntoExecuteMap("locator-key" + (i + 1), locatorKey);

          try {
            locator = PoshiRunnerContext.getPathLocator(pathClassName + "#" + locatorKey);
          } catch (Exception e) {
            exception = e;
          }

          locator = PoshiRunnerVariablesUtil.replaceExecuteVars(locator);
        }

        PoshiRunnerVariablesUtil.putIntoExecuteMap("locator" + (i + 1), locator);
      }

      String value = executeElement.attributeValue("value" + (i + 1));

      if (value == null) {
        value = PoshiRunnerVariablesUtil.getValueFromCommandMap("value" + (i + 1));
      }

      if (value != null) {
        PoshiRunnerVariablesUtil.putIntoExecuteMap("value" + (i + 1), value);
      }
    }

    SummaryLoggerHandler.startSummary(executeElement);

    CommandLoggerHandler.startCommand(executeElement);

    PoshiRunnerStackTraceUtil.pushStackTrace(executeElement);

    Element commandElement = PoshiRunnerContext.getFunctionCommandElement(classCommandName);

    try {
      if (exception != null) {
        throw exception;
      }

      runFunctionCommandElement(classCommandName, commandElement);
    } catch (Throwable t) {
      String warningMessage = _getWarningFromThrowable(t);

      if (warningMessage != null) {
        _functionWarningMessage = warningMessage;
      } else {
        PoshiRunnerStackTraceUtil.popStackTrace();

        if (_functionExecuteElement == executeElement) {
          PoshiRunnerStackTraceUtil.setCurrentElement(executeElement);

          SummaryLoggerHandler.failSummary(_functionExecuteElement, t.getMessage());

          CommandLoggerHandler.failCommand(_functionExecuteElement);

          _functionExecuteElement = null;
          _functionWarningMessage = null;
        }

        throw t;
      }
    }

    PoshiRunnerStackTraceUtil.popStackTrace();

    PoshiRunnerStackTraceUtil.setCurrentElement(executeElement);

    if (_functionExecuteElement == executeElement) {
      if (_functionWarningMessage != null) {
        SummaryLoggerHandler.warnSummary(_functionExecuteElement, _functionWarningMessage);

        CommandLoggerHandler.warnCommand(_functionExecuteElement);
      } else {
        SummaryLoggerHandler.passSummary(executeElement);

        CommandLoggerHandler.passCommand(executeElement);
      }

      _functionExecuteElement = null;
      _functionWarningMessage = null;
    }
  }