仅使用 ruby 运行相同的测试时,我获得了成功。当尝试使用 JRuby 从 java 运行相同的测试时,它找不到所需的文件,例如“watir-webdriver”、“rubygems”等。
红宝石文件:
require "rubygems"
require "watir-webdriver"
puts "Hello!!! test finished"
错误跟踪:
LoadError: no such file to load -- rubygems
require at org/jruby/RubyKernel.java:1054
(root) at /home/Oras/workspace/OptifyTestSuiteRuby/automation-watir/tes.rb:2
Exception in thread "main" org.jruby.embed.EvalFailedException: (LoadError) no such file to load -- rubygems
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1309)
at OptifyTest.com.Main.<init>(Main.java:18)
at OptifyTest.com.Main.main(Main.java:22)
Caused by: org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- rubygems
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1054)
at RUBY.(root)(/home/Oras/workspace/OptifyTestSuiteRuby/automation-watir/tes.rb:2)
Java 文件:
import java.util.ArrayList;
import java.util.List;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
public class Main {
private final static String jrubyhome = "/home/Oras/workspace/OptifyTestSuiteRuby/automation- watir";
private final String filename = jrubyhome + "/tes.rb";
private Main() {
ScriptingContainer container = new ScriptingContainer();
List<String> loadPaths = new ArrayList();
loadPaths.add(jrubyhome);
container.setLoadPaths(loadPaths);
container.runScriptlet(PathType.ABSOLUTE, filename);
}
public static void main(String[] args) {
new Main();
}
}