0

I need to set my Browser's proxy with Automatic Proxy configuration URL as shown in the screenshot below.

I am trying to achieve this using Selenium and Browserstack as test environment.

Set the proxy as shown below.

Proxy proxy = new Proxy();
proxy.setProxyAutoconfigUrl("http://pokgsa.ibm.com/gsa/pokgsa/home/j/m/jmit/web/public/proxy.pac");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(CapabilityType.PROXY, proxy);
caps.setCapability("browser", "Chrome");
caps.setCapability("browser_version", "63.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "7");
caps.setCapability("resolution", "1366x768");

enter image description here

Tried to set the proxy configuration locally and it works however it does not work on browserstack. I think the proxy is not getting set on the virtual browser.

1 Answer 1

1
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 2);
profile.setPreference("network.proxy.autoconfig_url", "http://pokgsa.ibm.com/gsa/pokgsa/home/j/m/jmit/web/public/proxy.pac");
capabilities.setCapability(FirefoxDriver.PROFILE, profile);

You need to pass the pac file details using Firefox profile.

Similarly for chrome, you may refer the following link: https://github.com/SeleniumHQ/docker-selenium/wiki/Corporate-Proxies#setting-a-proxy-for-running-chrome

Also please ensure proxies in the pac file do not need machine based authentication/entries since this may not work as your proxies would be required to be authenticated on all browserstack IPs

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Tried the same however the code is still timing out. I think the proxy is still not getting set. Code pasted below
< FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.type", 2); profile.setPreference("network.proxy.autoconfig_url", "pokgsa.ibm.com/gsa/pokgsa/home/j/m/jmitch/web/public/…); caps.setCapability("browser", "Firefox"); caps.setCapability("browser_version", "57.0"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("resolution", "1366x768");
Use the following code snippet instead. You are not passing the profile to capabilities: FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.type", 2); profile.setPreference("network.proxy.autoconfig_url", "pokgsa.ibm.com/gsa/pokgsa/home/j/m/jmit/web/public/…); caps.setCapability("browser", "Firefox"); caps.setCapability("browser_version", "57.0"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability(FirefoxDriver.PROFILE, profile); WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.