6

How can i do proxy configuration for selenium in Java?

I am connecting to selenium with:

Process p = Runtime.getRuntime().exec("java -jar lib/selenium-server.jar");
selenium = new DefaultSelenium("localhost", 4444, "*safari", "www.example.com");

I want to configure free proxy without username and password credentials for the same which would be running the selenium application in the safari browser.

I have tried the code below to set proxy for the tests

System.setProperty("http:proxyHost","207.229.122.162"); System.setProperty("http:proxyPort","3128");

but the above code is not working fine !! its even accepting null as arguments ,

Please suggest me some way to resolve the issue !!

Thanks in Advance !!

Aspirant
  • 2,238
  • 9
  • 31
  • 43
  • possible duplicate of [How to set Proxy Configuration in java code](http://stackoverflow.com/questions/5622547/how-to-set-proxy-configuration-in-java-code) – Zarkonnen Mar 28 '12 at 06:05
  • Hi! I think you can find the answer to your question at http://stackoverflow.com/questions/5622547/how-to-set-proxy-configuration-in-java-code - in short, use System.setProperty to set the proxy configuration. – Zarkonnen Mar 28 '12 at 06:06
  • Hey!! i have tried the System.setProperty("http.proxyHost","112.81.25.52"); System.setProperty("http.proxyPort","3128"); but still it doesn't work !! it is even accepting when i pass some random numbers or even null values ... – Aspirant Mar 28 '12 at 07:27
  • @Zarkonnen : is there any other way to config proxy in selenium ide other than System.setProperty() , and also working for safari browser in MAC os – Aspirant Mar 28 '12 at 09:47
  • @Aspirant could you share more java code and how do you read this property? – Sergii Tanchenko Nov 19 '14 at 21:57

3 Answers3

0

You could add the desired ip to the proxy bypass field in global network settings.

0

I prefer to define properties from console(using maven) then read it in java:

Define property:

mvn clean verify -Dserver_ip="127.0.0.1" -Dport="4444"

Read in java:

System.getProperty("server_ip");

It's more flexible than hardcoded values in code

Sergii Tanchenko
  • 702
  • 6
  • 18
0

You can customize run configuration under netbeans. Project Properties -> Run. Regards.

Łukasz Rzeszotarski
  • 5,791
  • 6
  • 37
  • 68
  • Hey i could not get your point of customizing Run configuration in Netbeans !! could you please be more specific regarding the same !! – Aspirant Apr 03 '12 at 12:32