I want to change the proxy of selenium server from my Java application. When I set the proxy the common way the Selenium server doesn't use this setting. I mean when I start the selenium browser and I go to an IP checking service (search google for "what is my ip") I want that the proxy IP to appear and not my IP address.
1 Answers
If you are using the WebDriver
API in Selenium 2.0, to control the browser, you may configure the browser to use a proxy, using the org.openqa.selenium.Proxy
class to define the proxy, and specify it as a Capability
when starting the WebDriver
instance. The Selenium FAQ addresses it in a question:
Q: I need to use a proxy. How do I configure that?
A: Proxy configuration is done via the org.openqa.selenium.Proxy class like so:
Proxy proxy = new Proxy(); proxy.setProxyAutoconfigUrl("http://youdomain/config"); // We use firefox as an example here. DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.PROXY, proxy); // You could use any webdriver implementation here WebDriver driver = new FirefoxDriver(capabilities);
If you are using Selenium RC (of Selenium 1; the API is available in Selenium 2 for backward compatibility), then you will need to configure Selenium Server to use the proxy. This is because Selenium Server is itself configured as the proxy for the browser, and therefore, it is Selenium Server that will have to forward the HTTP requests to the web-application via the proxy. Proxy details can be provided as JVM startup flags to Selenium Server, as noted in the Selenium documentation:
Proxy Configuration
If your AUT is behind an HTTP proxy which requires authentication then you should configure http.proxyHost, http.proxyPort, http.proxyUser and http.proxyPassword using the following command.
$ java -jar selenium-server-standalone-<version-number>.jar -Dhttp.proxyHost=proxy.com -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=password

- 76,006
- 17
- 150
- 174
-
This answer will help me only if I decide to use WebDriver...I'm using Selenium RC...actually is an alfa release 2.0..I don't want to switch to WebDriver soon – edi66 Sep 15 '11 at 15:06
-
@edi66, in that case, I would assume that you are using Selenium Server, which can be provided with the `-Dhttp.proxyHost=
-Dhttp.proxyPort= – Vineet Reynolds Sep 16 '11 at 17:01` flags to get [Selenium Server to forward the requests to the proxy instead of the application](http://seleniumhq.org/docs/05_selenium_rc.html#proxy-configuration).