2015-02-09 146 views
0
public class Test_One 
{ 
public static void main(String[] args) throws Exception { 
    ProxyServer server = new ProxyServer(8105); 
    server.start(); 
    server.setCaptureHeaders(true); 

    server.setCaptureContent(true); 
    server.newHar("test"); 
    DesiredCapabilities capabilities = new DesiredCapabilities(); 
    Proxy proxy = server.seleniumProxy(); 
    FirefoxProfile profile = new FirefoxProfile(); 
    profile.setAcceptUntrustedCertificates(true); 
    profile.setAssumeUntrustedCertificateIssuer(true); 
    profile.setPreference("network.proxy.http", "localhost"); 
    profile.setPreference("network.proxy.http_port", 8105); 
    profile.setPreference("network.proxy.ssl", "localhost"); 
    profile.setPreference("network.proxy.ssl_port", 8105); 
    profile.setPreference("network.proxy.type", 1); 
    profile.setPreference("network.proxy.no_proxies_on", ""); 
    //profile.setProxyPreferences(proxy); 
    profile.setPreference(key, value) 
    capabilities.setCapability(FirefoxDriver.PROFILE,profile); 
    capabilities.setCapability(CapabilityType.PROXY, proxy); 
    WebDriver driver = new FirefoxDriver(capabilities); 
    driver.get("http://www.google.com"); 
    Har har1 = server.getHar(); 
    } 
} 

我是新來的硒和broswermob。這是我的代碼。當我嘗試執行此操作並獲取錯誤The method setProxyPreferences(Proxy) is undefined for the type FirefoxProfile。如何解決這個問題?Browsermob不與硒webdriver工作

回答

0

您(通常)不需要手動配置FirefoxProfile設置。自述文件的Using With Selenium部分給出瞭如何使用代理與硒的例子:

// start the proxy 
ProxyServer server = new ProxyServer(4444); 
server.start(); 

// get the Selenium proxy object 
Proxy proxy = server.seleniumProxy(); 

// configure it as a desired capability 
DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.setCapability(CapabilityType.PROXY, proxy); 

// start the browser up 
WebDriver driver = new FirefoxDriver(capabilities); 

// create a new HAR with the label "yahoo.com" 
server.newHar("yahoo.com"); 

// open yahoo.com 
driver.get("http://yahoo.com"); 

// get the HAR data 
Har har = server.getHar(); 

如果不工作,它可能與你的Firefox和/或硒和/特定版本的問題或BrowserMob代理。你使用什麼版本?具有確切錯誤消息的堆棧跟蹤也將有所幫助。

0

嘗試去除能力的個人資料,並直接把它傳遞給FirefoxDriver:

driver = new FirefoxDriver(new FirefoxBinary(),profile,capabilities);