10

I am trying to start selenium and selenium's browser with proxy but not getting success. I have used two methods:

        Properties sysProps = System.getProperties();
        sysProps.put("proxySet", "true");
        sysProps.put("proxyHost", "190.249.188.220");
        sysProps.put("proxyPort", "81");

and

java -jar lib/selenium-server.jar proxyHost=22.52.50.228 proxyPort=80

but both are not supporting.

is anyone able to help me to start selenium's browser with proxy.

blank
  • 17,852
  • 20
  • 105
  • 159
Khoyendra Pande
  • 1,627
  • 5
  • 25
  • 42

2 Answers2

13

You can use this:

String PROXY = "localhost:8080";

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
     .setFtpProxy(PROXY)
     .setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);

WebDriver driver = new InternetExplorerDriver(cap);

For more detail, refer here

Hai Nguyen
  • 1,675
  • 19
  • 14
2

try

java -Dhttp.proxyHost=HOSTNAME -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USER -Dhttp.proxyPassword=PASSWORD -jar selenium-server.jar

* Dhttp.proxyHost – proxy IP address
* Dhttp.proxyPort – proxy port
* Dhttp.proxyUser – user name if HTTP-proxy authentication required;
* Dhttp.proxyPassword – user password if HTTP-proxy authentication required.
Alex Stybaev
  • 4,623
  • 3
  • 30
  • 44
  • No, I think its also not supporting because when I am putting wrong proxy (e.i. I am putting my name) then too its opening browser. It should not be open when I am putting wrong proxy. – Khoyendra Pande Mar 27 '12 at 07:24
  • Like Alex said, http://seleniumhq.org/docs/05_selenium_rc.html#proxy-configuration. If you want to implement some mechanism that checks whether the given properties are good or bad, you would have to do that on your own. Selenium just takes what you give to it and tries to use it. – Petr Janeček Mar 27 '12 at 09:03