0
votes

i'm writing tests in selenium and want to change proxy to auto-detect in firefox, default is proxy from system settings. How to do it?

I have code below:

public class SodirRejestracja {
String baseUrl = "http://google.pl"; 
String driverPath= "C:\\geckodriver.exe";
WebDriver driver;


@BeforeTest
public void beforeTest() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 2);
    System.setProperty("webdriver.gecko.driver", driverPath);
    driver=new FirefoxDriver(profile);
}
@Test
public void test(){
    driver.get("http://google.com");
}
}

Code above is from How do I set a proxy for firefox using Selenium webdriver with Java?

but in line driver=new FirefoxDriver(profile) i get: "The constructor FirefoxDriver(FirefoxProfile) is undefined"

2

2 Answers

0
votes

A sample (not tested but that compiles) that should do it

String proxyName = <yourProxyHost> + ":" + <yourProxyPort>;
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyName)
     .setFtpProxy(proxyName)
     .setSslProxy(proxyName);

DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
FirefoxOptions options = new FirefoxOptions(desiredCapabilities);
driver = new FirefoxDriver(options);
0
votes

This code works

Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.AUTODETECT);
    FirefoxOptions options = new FirefoxOptions();
    options.setProxy(proxy);
    driver = new FirefoxDriver(options);