private String executeCommand( final ExtendedSeleniumCommand command, final String[] values, long delay) { if (LOG.isDebugEnabled()) { LOG.debug( "executeCommand. Command: " + command.getSeleniumCommand() + " with values: [" + join(values, ", ") + "]"); } if (commandProcessor == null) { throw new IllegalStateException( "Command processor not running. " + "First start it by invoking startBrowserOnUrl."); } if ("pause".equals(command.getSeleniumCommand())) { pause(values[0]); return null; } String output = getCommandOutput(command, values); waitForPageLoadIfNeeded(command); delayIfNeeded(delay); return output; }
public String is(final String command, final String[] parameters) { ExtendedSeleniumCommand seleniumCommand = new ExtendedSeleniumCommand(command); String output = executeCommand(seleniumCommand, parameters, stepDelay); if (seleniumCommand.isBooleanCommand() && seleniumCommand.isNegateCommand()) { if ("true".equals(output)) { output = "false"; } else if ("false".equals(output)) { output = "true"; } else { throw new IllegalStateException("Illegal boolean value: '" + output + "'"); } } return output; }
private String getCommandOutput(ExtendedSeleniumCommand command, String[] values) { try { if (command.returnTypeIsArray()) { return executeArrayCommand(command.getSeleniumCommand(), values); } else { return executeCommand(command.getSeleniumCommand(), values); } } catch (final SeleniumException e) { String output = "Execution of command failed: " + e.getMessage(); LOG.error(output); if (!(command.isAssertCommand() || command.isVerifyCommand() || command.isWaitForCommand())) { throw e; } return output; } }
private boolean checkResult(ExtendedSeleniumCommand command, String expected, String actual) { return command.matches(expected, actual); }
private void waitForPageLoadIfNeeded(ExtendedSeleniumCommand command) { if (command.isAndWaitCommand()) { commandProcessor.doCommand("waitForPageToLoad", new String[] {"" + timeout}); } }
private boolean executeDoCommand(final String methodName, final String[] values) { final ExtendedSeleniumCommand command = new ExtendedSeleniumCommand(methodName); String output = null; boolean result = true; if (!locatorCheck.verifyElementPresent(command, values)) { result = false; } else if (command.requiresPolling()) { long timeoutTime = System.currentTimeMillis() + timeout; do { output = executeCommand(command, values, 0); result = checkResult(command, values[values.length - 1], output); if (!result) { delayIfNeeded(pollDelay); } } while (!result && timeoutTime > System.currentTimeMillis()); LOG.info( "WaitFor- command '" + command.getSeleniumCommand() + (result ? "' succeeded" : "' failed")); } else { output = executeCommand(command, values, stepDelay); if (command.isCaptureEntirePageScreenshotCommand()) { writeToFile(values[0], output); result = true; } else if (command.isAssertCommand() || command.isVerifyCommand() || command.isWaitForCommand()) { String expected = values[values.length - 1]; result = checkResult(command, expected, output); LOG.info( "Command '" + command.getSeleniumCommand() + "' returned '" + output + "' => " + (result ? "ok" : "not ok, expected '" + expected + "'")); } else { LOG.info("Command '" + command.getSeleniumCommand() + "' returned '" + output + "'"); } } if (screenCapture.requireScreenshot(command, result)) { screenCapture.captureScreenshot(methodName, values); } if (!result && command.isAssertCommand()) { if (stopBrowserOnAssertion) { stopBrowser(); } throw new AssertionAndStopTestError(output); } return result; }