Sak*_*uma 17 selenium cross-browser browser-plugin
我正在编写一个webapp,它有一个浏览器插件组件,用于firefox和chrome.我目前的测试系统使用通过Selenium IDE创建的一系列Selenium测试.
是否有可能为firefox和chrome(也可能是其他浏览器)安装,激活和删除浏览器插件的selenium?
我认为最大的问题是安装/启用浏览器插件需要重新启动浏览器,我不确定是否会通过selenium关闭.
通过访问检测浏览器的php脚本的内部站点链接,可以轻松处理插件的获取.
Rob*_*b W 39
答案是肯定的,Selenium 2支持(远程)安装浏览器扩展.
Chrome和Firefox WebDriver远程支持扩展安装.以下是Chrome和Firefox的示例代码:
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Run Code Online (Sandbox Code Playgroud)
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Run Code Online (Sandbox Code Playgroud)
我还实现了Opera和Safari扩展的自动安装,它们已合并到上游:
此API类似于FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Run Code Online (Sandbox Code Playgroud)
此API类似于ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Run Code Online (Sandbox Code Playgroud)
祝好运.
归档时间: |
|
查看次数: |
10790 次 |
最近记录: |