com.github.siwenyan.si.SiCommandExecutorRunScript 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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SiCommandExecutorRunScript extends SiCommandExecutor {
private static final Pattern p = Pattern.compile("\\s*document\\.setVar\\(\\s*'(.+)'\\s*,\\s*'(.+)'\\s*\\)\\s*;\\s*");
@Override
public void execute(SiCommand command, SiContext siContext) throws SiVerifyException {
String script = command.getSiModelCommand().getTarget();
script = siContext.dynamic(script, "'", "'");
try {
Matcher m = p.matcher(script);
if (m.matches()) {
String name = m.group(1);
String value = m.group(2);
siContext.addVar(name, value);
} else {
String name = command.getSiModelCommand().getValue();
Object value = siContext.asJavascriptExecutor().executeScript(script);
if (null != name && !name.trim().isEmpty()) {
siContext.getReporter().reportMessage("name: " + name);
siContext.getReporter().reportMessage("value: " + value);
siContext.addVar(name, value);
}
}
} catch (Exception e) {
throw new RuntimeException("Fail to run script: " + script + " | " + e.getMessage());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy