2013-07-03 48 views
1

我的問題是關於修改默認配置文件設置以允許/拒絕我的web應用程序訪問麥克風和攝像頭。這是代碼 - 這似乎被忽略了。在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,即只有在解析發生 - 這也是莫名其妙問題(見註釋內聯)。

我也在網上搜索,但找不到任何東西。

霍爾格

回答

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"); 
    }