public void testPoshiRunner() throws Exception {
    String classCommandName = System.getProperty("test.case.name");

    Element element = PoshiRunnerContext.getTestcaseCommandElement(classCommandName);

    PoshiRunnerExecutor.parseElement(element);
  }
  public static Map<String, String> runMacroCommandElement(
      String classCommandName, Element commandElement) throws Exception {

    PoshiRunnerStackTraceUtil.setCurrentElement(commandElement);

    PoshiRunnerVariablesUtil.pushCommandMap();

    parseElement(commandElement);

    Map<String, String> macroReturns = new HashMap<>();

    String returns = commandElement.attributeValue("returns");

    if (Validator.isNotNull(returns)) {
      String[] returnNames = StringUtil.split(returns);

      for (String returnName : returnNames) {
        if (PoshiRunnerVariablesUtil.containsKeyInReturnMap(returnName)) {

          String returnValue = PoshiRunnerVariablesUtil.getValueFromReturnMap(returnName);

          macroReturns.put(returnName, returnValue);
        }
      }
    }

    PoshiRunnerVariablesUtil.popCommandMap();

    return macroReturns;
  }
  public static void runTestCaseCommandElement(Element commandElement) throws Exception {

    PoshiRunnerStackTraceUtil.setCurrentElement(commandElement);

    PoshiRunnerVariablesUtil.pushCommandMap();

    parseElement(commandElement);

    PoshiRunnerVariablesUtil.popCommandMap();
  }
  public static void runFunctionCommandElement(String classCommandName, Element commandElement)
      throws Exception {

    PoshiRunnerStackTraceUtil.setCurrentElement(commandElement);

    PoshiRunnerVariablesUtil.pushCommandMap();

    try {
      parseElement(commandElement);
    } catch (Exception e) {
      throw e;
    } finally {
      PoshiRunnerVariablesUtil.popCommandMap();
    }
  }
  public static void runTaskElement(Element element) throws Exception {
    PoshiRunnerStackTraceUtil.setCurrentElement(element);

    XMLLoggerHandler.updateStatus(element, "pending");

    try {
      SummaryLoggerHandler.startSummary(element);

      parseElement(element);
    } catch (Exception e) {
      SummaryLoggerHandler.failSummary(element, e.getMessage());

      throw e;
    }

    SummaryLoggerHandler.passSummary(element);

    XMLLoggerHandler.updateStatus(element, "pass");
  }
  public static void runForElement(Element element) throws Exception {
    PoshiRunnerStackTraceUtil.setCurrentElement(element);

    XMLLoggerHandler.updateStatus(element, "pending");

    String list = PoshiRunnerVariablesUtil.replaceCommandVars(element.attributeValue("list"));

    String[] paramValues = list.split(",");

    String paramName = PoshiRunnerVariablesUtil.replaceCommandVars(element.attributeValue("param"));

    for (String paramValue : paramValues) {
      PoshiRunnerVariablesUtil.putIntoCommandMap(paramName, paramValue);

      parseElement(element);
    }

    XMLLoggerHandler.updateStatus(element, "pass");
  }
  public static void runWhileElement(Element element) throws Exception {
    PoshiRunnerStackTraceUtil.setCurrentElement(element);

    XMLLoggerHandler.updateStatus(element, "pending");

    int maxIterations = 15;

    if (element.attributeValue("max-iterations") != null) {
      maxIterations = GetterUtil.getInteger(element.attributeValue("max-iterations"));
    }

    List<Element> whileChildElements = element.elements();

    Element conditionElement = whileChildElements.get(0);
    Element thenElement = element.element("then");

    boolean conditionRun = false;

    for (int i = 0; i < maxIterations; i++) {
      if (!evaluateConditionalElement(conditionElement)) {
        break;
      }

      conditionRun = true;

      PoshiRunnerStackTraceUtil.setCurrentElement(thenElement);

      XMLLoggerHandler.updateStatus(thenElement, "pending");

      parseElement(thenElement);

      XMLLoggerHandler.updateStatus(thenElement, "pass");
    }

    if (conditionRun) {
      XMLLoggerHandler.updateStatus(element, "pass");
    } else {
      XMLLoggerHandler.updateStatus(element, "conditional-fail");
    }
  }
  public static void runIfElement(Element element) throws Exception {
    PoshiRunnerStackTraceUtil.setCurrentElement(element);

    XMLLoggerHandler.updateStatus(element, "pending");

    List<Element> ifChildElements = element.elements();

    Element ifConditionElement = ifChildElements.get(0);

    boolean condition = evaluateConditionalElement(ifConditionElement);
    boolean conditionRun = false;

    if (condition) {
      conditionRun = true;

      Element ifThenElement = element.element("then");

      PoshiRunnerStackTraceUtil.setCurrentElement(ifThenElement);

      XMLLoggerHandler.updateStatus(ifThenElement, "pending");

      parseElement(ifThenElement);

      XMLLoggerHandler.updateStatus(ifThenElement, "pass");
    } else if (element.element("elseif") != null) {
      List<Element> elseIfElements = element.elements("elseif");

      for (Element elseIfElement : elseIfElements) {
        PoshiRunnerStackTraceUtil.setCurrentElement(elseIfElement);

        XMLLoggerHandler.updateStatus(elseIfElement, "pending");

        List<Element> elseIfChildElements = elseIfElement.elements();

        Element elseIfConditionElement = elseIfChildElements.get(0);

        condition = evaluateConditionalElement(elseIfConditionElement);

        if (condition) {
          conditionRun = true;

          Element elseIfThenElement = elseIfElement.element("then");

          PoshiRunnerStackTraceUtil.setCurrentElement(elseIfThenElement);

          XMLLoggerHandler.updateStatus(elseIfThenElement, "pending");

          parseElement(elseIfThenElement);

          XMLLoggerHandler.updateStatus(elseIfThenElement, "pass");
          XMLLoggerHandler.updateStatus(elseIfElement, "pass");

          break;
        } else {
          XMLLoggerHandler.updateStatus(elseIfElement, "conditional-fail");
        }
      }
    }

    if ((element.element("else") != null) && !conditionRun) {
      conditionRun = true;

      Element elseElement = element.element("else");

      PoshiRunnerStackTraceUtil.setCurrentElement(elseElement);

      XMLLoggerHandler.updateStatus(elseElement, "pending");

      parseElement(elseElement);

      XMLLoggerHandler.updateStatus(elseElement, "pass");
    }

    if (conditionRun) {
      XMLLoggerHandler.updateStatus(element, "pass");
    } else {
      XMLLoggerHandler.updateStatus(element, "conditional-fail");
    }
  }