com.github.siwenyan.si.SiScriptEngine 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 javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class SiScriptEngine {
private static final ScriptEngineManager SEM = new ScriptEngineManager();
private static SiScriptEngine instance;
public static SiScriptEngine instance() {
if (null == instance) {
instance = new SiScriptEngine();
}
return instance;
}
private ScriptEngine jse;
private SiScriptEngine() {
jse = SEM.getEngineByExtension("js");
try {
this.init();
} catch (ScriptException e) {
throw new RuntimeException(e);
}
}
private void init() throws ScriptException {
try {
String name = "side/jse_init.js";
InputStream is = this.getClass().getClassLoader().getResourceAsStream(name);
InputStreamReader isr = new InputStreamReader(is);
this.jse.eval(isr);
} catch (Exception e) {
// do nothing
}
}
public Object executeScript(String js) {
try {
Object res = this.jse.eval(js);
return res;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy