com.github.siwenyan.si.SiCommandExecutorIf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of side Show documentation
Show all versions of side Show documentation
Java runner of Selenium IDE project
package com.github.siwenyan.si;
class SiCommandExecutorIf extends SiCommandExecutor {
@Override
public void execute(SiCommand command, SiContext siContext) throws SiVerifyException {
String scriptRaw = command.getSiModelCommand().getTarget();
String script = siContext.dynamic(scriptRaw, "'", "'");
Boolean ifTrue = null;
try {
Object o = siContext.asJavascriptExecutor().executeScript("return " + script);
if (null == o) {
o = siContext.asJavascriptExecutor().executeScript(script);
if (null == o) {
throw new RuntimeException("Browser: script evaluated as null: " + script);
}
}
ifTrue = (Boolean) o;
} catch (Exception e) {
siContext.getReporter().reportMessage(e);
siContext.getReporter().reportMessage("Browser: Fail to evaluate if script: " + script);
try {
SiScriptEngine sse = SiScriptEngine.instance();
Object o = sse.executeScript(script);
ifTrue = (Boolean) o;
if (null == o) {
o = sse.executeScript("return " + script);
if (null == o) {
throw new RuntimeException("ScriptEngine: script evaluated as null: " + script);
}
}
} catch (Exception e1) {
throw new RuntimeException(
"ScriptEngine: Fail to evaluate if script: " + script + " | " +
e1.getClass().getName() + " | " +
e1.getMessage());
}
}
SiCommandIf realCommand = (SiCommandIf) command;
realCommand.setIfTrue(ifTrue);
siContext.getReporter().reportMessage("ifTrue: " + ifTrue);
if (!ifTrue) {
SiCommand elseOrEnd = command.getPairInBack();
command.getSiTest().setCursor(elseOrEnd.getIndexInTest());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy