在Watir和Webdriver中使用配置文件

时间:2013-07-03 09:11:23

标签: google-chrome webdriver watir profile watir-webdriver

我的问题是关于修改默认配置文件设置以允许/拒绝我的网络应用程序访问麦克风和摄像头。这是代码 - 似乎被忽略了。

#!/usr/bin/ruby
require 'watir-webdriver'

profile = Selenium::WebDriver::Chrome::Profile.new
profile['content_settings.pattern_pairs.*,*.media-stream-mic'] = 1 
# if I put mysever.com into here (first asterix), the parsing must fail 
# as the '.' is used as delimiter by profile.rb - so *,* should work 

browser = Watir::Browser.new :chrome, :profile => profile 
browser.goto "http://webaudiodemos.appspot.com/input/index.html" 
# here a get media event is fired and the browser should proceed without(!)
# asking the user for permission - but the browser is always asking and 
# this element is not accessible for Watir (is it?).

我查看了profile.rb,其中只进行了解析 - 这在某种程度上也存在问题(请参阅注释内联)。

我也在网上搜索但找不到任何东西。

Holger

1 个答案:

答案 0 :(得分:0)

1. create a profile manually using the cmd :
 firefox -profilemanager
 set what you want on the browser of the new profile 
2.code example 

protected void initializeWebDriver() {  
        LoggerInfo.logger.info("Starting webdriver...");
        ProfilesIni allProfiles = new ProfilesIni();
        FirefoxProfile profile = allProfiles.getProfile("MyProfile");
//      FirefoxProfile profile = new FirefoxProfile();
        driver = new    DriverBuilder().using(Browser.FIREFOX).withFirefoxProfile(profile).build();
        LoggerInfo.logger.info("webdriver is up");
    }