@Override public void tearDown() throws Exception { SeleniumUtil.stopSelenium(); }
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"); } }
@Override public void setUp() throws Exception { SeleniumUtil.startSelenium(); }
public static void runSeleniumElement(Element executeElement) throws Exception { PoshiRunnerStackTraceUtil.setCurrentElement(executeElement); List<String> arguments = new ArrayList<>(); List<Class<?>> parameterClasses = new ArrayList<>(); String selenium = executeElement.attributeValue("selenium"); int parameterCount = PoshiRunnerContext.getSeleniumParameterCount(selenium); for (int i = 0; i < parameterCount; i++) { String argument = executeElement.attributeValue("argument" + (i + 1)); if (argument == null) { if (i == 0) { if (selenium.equals("assertConfirmation") || selenium.equals("assertConsoleTextNotPresent") || selenium.equals("assertConsoleTextPresent") || selenium.equals("assertLocation") || selenium.equals("assertHTMLSourceTextNotPresent") || selenium.equals("assertHTMLSourceTextPresent") || selenium.equals("assertNotLocation") || selenium.equals("assertTextNotPresent") || selenium.equals("assertTextPresent") || selenium.equals("waitForConfirmation") || selenium.equals("waitForTextNotPresent") || selenium.equals("waitForTextPresent")) { argument = PoshiRunnerVariablesUtil.getValueFromCommandMap("value1"); } else { argument = PoshiRunnerVariablesUtil.getValueFromCommandMap("locator1"); } } else if (i == 1) { argument = PoshiRunnerVariablesUtil.getValueFromCommandMap("value1"); if (selenium.equals("clickAt")) { argument = ""; } } else if (i == 2) { if (selenium.equals("assertCssValue")) { argument = PoshiRunnerVariablesUtil.getValueFromCommandMap("value1"); } else { argument = PoshiRunnerVariablesUtil.getValueFromCommandMap("locator2"); } } } else { argument = PoshiRunnerVariablesUtil.replaceCommandVars(argument); } arguments.add(argument); parameterClasses.add(String.class); } CommandLoggerHandler.logSeleniumCommand(executeElement, arguments); LiferaySelenium liferaySelenium = SeleniumUtil.getSelenium(); Class<?> clazz = liferaySelenium.getClass(); try { Method method = clazz.getMethod(selenium, parameterClasses.toArray(new Class[parameterClasses.size()])); _returnObject = method.invoke( liferaySelenium, (Object[]) arguments.toArray(new String[arguments.size()])); } catch (Exception e) { Throwable throwable = e.getCause(); throw new Exception(throwable.getMessage(), e); } }