简体   繁体   English

在Ubuntu机器上运行的Selenium服务器上的Firefox中启用Java插件

[英]Enable java plugin in Firefox on a selenium server running on a Ubuntu machine

I setup a selenium server to run on a ubuntu machine remotely. 我设置了一个硒服务器以在ubuntu机器上远程运行。 My test is written in Java and it looks like this: 我的测试是用Java编写的,看起来像这样:

(...)
// setup the WebDrive
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, setupBrowser());
mDriver = new RemoteWebDriver(new URL("http://MY-SERVER-IP:4444/wd/hub"), dc);
(...)

private FirefoxProfile setupBrowser() {
    FirefoxProfile fp = new FirefoxProfile();
    fp.setAcceptUntrustedCertificates(true);
    fp.setAssumeUntrustedCertificateIssuer(false);
    fp.setPreference("browser.download.folderList",2);//browser dir
    fp.setPreference("browser.download.dir", mExtractsDir);
    fp.setPreference("browser.helperApps.neverAsk.saveToDisk","text/plain");
    fp.setPreference("browser.helperApps.neverAsk.openFile","text/plain");
    fp.setPreference("plugin.default.state", 2);
    fp.setPreference("plugin.state.java", 2);
    fp.setPreference("security.enable_java", true);
    fp.setPreference("browser.helperApps.alwaysAsk.force", false);
    fp.setPreference("browser.download.manager.alertOnEXEOpen", false);
    fp.setPreference("browser.download.manager.focusWhenStarting", false);
    fp.setPreference("browser.download.manager.useWindow", false);
    fp.setPreference("browser.download.manager.showAlertOnComplete", false);
    fp.setPreference("browser.download.manager.closeWhenDone", false);
    return fp;
}
(...)

I then started a Selenium server in my remote machine running Ubuntu Linux in MY-SERVER-IP:4444 by executing this: 然后,通过执行以下命令,在运行MY-SERVER-IP:4444中的Ubuntu Linux的远程计算机中启动Selenium服务器:

$ Xvfb :0 -screen 0 1024x768x24 2>&1 >xvfb.log &
$ export DISPLAY=:0
$ nohup xvfb-run java -jar selenium-server-standalone-2.45.0.jar > selenium.log &

PROBLEM: The website that my test code is loading requires java plugin, but it is not loading. 问题:我的测试代码正在加载的网站需要Java插件,但未加载。 How to load the java plugin? 如何加载Java插件? I know that it is not loading because I used wdriver.get point to the official java test website and took a screenshot of the browser by using the following code and it was possible to see that the java test plugin is not being loaded: 我知道它没有加载,因为我使用wdriver.get指向官方的Java测试网站,并通过使用以下代码拍摄了浏览器的屏幕截图,并且有可能看到Java测试插件未加载:

Augmenter augmenter = new Augmenter(); 
TakesScreenshot ts = (TakesScreenshot) augmenter.augment(mDriver);
File srcFile = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("/tmp/firefoxstopped.png"));

QUESTION: How can I enable java plugin in the Firefox for this scenario? 问题:在这种情况下,如何在Firefox中启用Java插件?

Remember read about Java Applets embed in HTML. 记得阅读有关嵌入在HTML中的Java Applet的文章。 Can you share the code of your HTML? 您可以共享HTML代码吗? How you embed the plugin? 您如何嵌入插件?

You can see the plugins supported in the browser with navigator.plugins 您可以使用navigator.plugins查看浏览器中支持的插件

The NPAPI like Java Plugin going to be deprecate soon. 像Java Plugin这样的NPAPI将很快被弃用。

You can compile the browser like XULRunner o Firefox with the support of Java and load the jar files with JavaScript. 您可以在Java的支持下编译XULRunner o Firefox之类的浏览器,并使用JavaScript加载jar文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM