简体   繁体   中英

Browsermob is not working with selenium webdriver

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

I'm new to selenium and broswermob. This is my code. Whe I try to execute this and getting error The method setProxyPreferences(Proxy) is undefined for the type FirefoxProfile . How to solve this?

You (generally) don't need to configure the FirefoxProfile settings manually. The Using With Selenium section of the readme file gives an example of how to use the proxy 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();

If that doesn't work, it may be a problem with your specific version of Firefox and/or Selenium and/or BrowserMob Proxy. What versions are you using? A stack trace with the exact error message would also help.

尝试从功能中删除配置文件并将其直接传递给FirefoxDriver:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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