简体   繁体   English

我需要启用Java(tm)插件,以便在浏览器中安装小程序。在Web驱动程序中怎么可能

[英]I need to enable java (tm) plugin which installs applet in the browser.. How is it possible in Web Driver

I need to enable java (tm) plugin which installs applet in the browser.. How is it possible in Web Driver? 我需要启用在浏览器中安装小程序的java(tm)插件。在Web驱动程序中怎么可能? I am testing a web app where some functionality has to be verified by enabling java(ie, by installing applet) and also some functionality by disabling it. 我正在测试一个Web应用程序,其中必须通过启用Java(即,通过安装applet)来验证某些功能,并通过禁用它来验证某些功能。 If applet works fine, then I need some expected results and if applet is not installed, I need some other results.. so how do i enable/disable applets(ie,java tm plugin) before launching browser..?? 如果applet正常运行,那么我需要一些预期的结果,如果未安装applet,则我需要一些其他结果..那么在启动浏览器之前,如何启用/禁用applet(即java tm插件)。 Please Help.. 请帮忙..

Currently am using WebDriver... 目前正在使用WebDriver ...

Create a firefox profile to load firefox with the plugin which you want. 创建一个firefox配置文件以使用所需的插件加载firefox。 Use the below code and replace the plugin name with your plugin name. 使用以下代码,并将插件名称替换为您的插件名称。

   File file = new File("firebug-1.8.1.xpi");
   FirefoxProfile firefoxProfile = new FirefoxProfile();
   firefoxProfile.addExtension(file);
   firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen

   WebDriver driver = new FirefoxDriver(firefoxProfile);

Source: Click Here 来源: 点击这里

You can enable any Firefox plugin creating new profile and setting the preference. 您可以启用任何Firefox插件来创建新的配置文件并设置首选项。

For eg to enable java plugin 例如启用Java插件

profile.setPreference("plugin.state.java", 2);

To enable flash plugin 启用Flash插件

profile.setPreference("plugin.state.flash", 2);

Sample code: 样例代码:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("plugin.state.java", 2);

WebDriver driver = new FirefoxDriver(profile);

I presume the "2" activates the plugin. 我假设“ 2”激活插件。

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

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