4

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
  • Are you using the Selenium class or the WebDriver class to control the browser in your tests? Commented Sep 15, 2011 at 11:44

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

2 Comments

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, in that case, I would assume that you are using Selenium Server, which can be provided with the -Dhttp.proxyHost=<proxyhostname> -Dhttp.proxyPort=<proxyPort> flags to get Selenium Server to forward the requests to the proxy instead of the application.

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.