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

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?

Alexander O'Mara
  • 52,993
  • 16
  • 139
  • 151
Ann
  • 1
  • 3

2 Answers2

0

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.

Jason Hoetger
  • 5,650
  • 2
  • 13
  • 14
0

Try removing profile from capabilities and passing it directly to FirefoxDriver:

driver = new FirefoxDriver(new FirefoxBinary(),profile,capabilities);
jpereira
  • 508
  • 6
  • 10