-
-
Save krmahadevan/1080409 to your computer and use it in GitHub Desktop.
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.Map; | |
import org.openqa.selenium.Capabilities; | |
import org.openqa.selenium.Proxy; | |
import org.openqa.selenium.WebDriverBackedSelenium; | |
import org.openqa.selenium.remote.CapabilityType; | |
import org.openqa.selenium.remote.Command; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.openqa.selenium.remote.Response; | |
import org.openqa.selenium.remote.SessionId; | |
import com.thoughtworks.selenium.Selenium; | |
public class ProxyServerSettingsWithRemoteWebDriver { | |
public static void main(String[] args) { | |
String proxyPacURL = "http://localhost/proxy.pac"; | |
String hubURL = "http://localhost:4444/wd/hub"; | |
String urlToLaunch = "http://www.google.com"; | |
try { | |
configureRemoteProxySettings(proxyPacURL, hubURL, urlToLaunch); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void configureRemoteProxySettings(String proxyPacURL, String hubURL, String urlToLaunch) | |
throws MalformedURLException, InterruptedException { | |
Proxy proxy = new Proxy(); | |
proxy.setProxyAutoconfigUrl(proxyPacURL); | |
DesiredCapabilities capability = DesiredCapabilities.internetExplorer(); | |
capability.setPlatform(null); | |
capability.setCapability(CapabilityType.PROXY, proxy); | |
RemoteWebDriver d = new MyDriver(new URL(hubURL), capability); | |
Selenium s = new WebDriverBackedSelenium(d, "http://www.google.com"); | |
s.open(urlToLaunch); | |
} | |
} | |
class MyDriver extends RemoteWebDriver { | |
public MyDriver(URL url, Capabilities capability) { | |
super(url, capability); | |
} | |
@Override | |
protected void log(SessionId sessionId, String commandName, Object toLog) { | |
if (sessionId != null) { | |
System.out.println("Session ID information"); | |
System.out.println(sessionId.toString()); | |
} | |
System.out.println("Command = " + commandName); | |
if (toLog != null) { | |
if (toLog instanceof Response) { | |
Response response = (Response) toLog; | |
System.out.println("Printing the response obtained"); | |
System.out.println("Session ID from response = " + response.getSessionId()); | |
System.out.println("Status from response = " + response.getStatus()); | |
System.out.println("Response value as below : [" + response.getValue() + "]"); | |
} | |
if (toLog instanceof Command) { | |
Command command = (Command) toLog; | |
Map<String, ?> params = command.getParameters(); | |
for (String key : params.keySet()) { | |
Object individualValue = params.get(key); | |
if (individualValue instanceof Capabilities) { | |
Capabilities c = (Capabilities) individualValue; | |
Proxy p = (Proxy) c.getCapability(CapabilityType.PROXY); | |
System.out.println("Printing proxy settings"); | |
System.out.println("Ftp proxy " + p.getFtpProxy()); | |
System.out.println("Http Proxy " + p.getHttpProxy()); | |
System.out.println("No Proxy " + p.getNoProxy()); | |
System.out.println("SSL Proxy " + p.getSslProxy()); | |
System.out.println("Proxy auto config url : " + p.getProxyAutoconfigUrl()); | |
System.out.println("Auto detection status " + p.isAutodetect()); | |
System.out.println("Proxy setting that is done : " + p.getProxyType().toString()); | |
}else{ | |
System.out.println("Individual key value " + individualValue); | |
} | |
} | |
} | |
} | |
} | |
} |
Following is the complete Stack Trace
Exception in thread "main" org.openqa.selenium.WebDriverException: Proxy autodetect is incompatible with manual settings
Build info: version: '2.0.0', revision: '12817', time: '2011-07-07 19:14:12'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_20'
Driver info: driver.version: ProxyServerSettingsWithRemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:402)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:101)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:84)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:92)
at com.paypal.MyDriver.(ProxyServerSettingsWithRemoteWebDriver.java:51)
at com.paypal.ProxyServerSettingsWithRemoteWebDriver.configureRemoteProxySettings(ProxyServerSettingsWithRemoteWebDriver.java:42)
at com.paypal.ProxyServerSettingsWithRemoteWebDriver.main(ProxyServerSettingsWithRemoteWebDriver.java:26)
Caused by: java.lang.IllegalStateException: Proxy autodetect is incompatible with manual settings
at org.openqa.selenium.Proxy.verifyProxyTypeCompatilibily(Proxy.java:153)
at org.openqa.selenium.Proxy.setFtpProxy(Proxy.java:101)
at org.openqa.selenium.Proxy.(Proxy.java:48)
at org.openqa.selenium.browserlaunchers.Proxies.extractProxy(Proxies.java:89)
at org.openqa.selenium.browserlaunchers.Proxies.newProxyPac(Proxies.java:102)
at org.openqa.selenium.browserlaunchers.Proxies.makeProxyPAC(Proxies.java:63)
at org.openqa.selenium.browserlaunchers.Proxies.makeProxyPAC(Proxies.java:55)
at org.openqa.selenium.browserlaunchers.WindowsProxyManager.changeRegistrySettings(WindowsProxyManager.java:163)
at org.openqa.selenium.ie.InternetExplorerDriver.prepareProxy(InternetExplorerDriver.java:125)
at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:68)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(null)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(null)
at java.lang.reflect.Constructor.newInstance(null)
at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructor(DefaultDriverFactory.java:87)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:81)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:154)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(null)
at java.util.concurrent.FutureTask.run(null)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(null)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(null)
at java.lang.Thread.run(null)
Following is how the output looks like :
Command = newSession
Printing proxy settings
Ftp proxy null
Http Proxy null
No Proxy null
SSL Proxy null
Proxy auto config url : http://localhost/proxy.pac
Auto detection status false
Proxy setting that is done : PAC
Command = newSession
Printing the response obtained
Session ID from response =
Status from response = 13
Response value as below : [{message=Proxy autodetect is incompatible with manual settings, localizedMessage=Proxy autodetect is incompatible with manual settings, cause=null, class=java.lang.IllegalStateException, hCode=11381618, stackTrace=[{fileName=Proxy.java, class=java.lang.StackTraceElement, lineNumber=153, className=org.openqa.selenium.Proxy, nativeMethod=false, methodName=verifyProxyTypeCompatilibily, hCode=1728445944}, {fileName=Proxy.java, class=java.lang.StackTraceElement, lineNumber=101, className=org.openqa.selenium.Proxy, nativeMethod=false, methodName=setFtpProxy, hCode=-1963968439}, {fileName=Proxy.java, class=java.lang.StackTraceElement, lineNumber=48, className=org.openqa.selenium.Proxy, nativeMethod=false, methodName=, hCode=-203824936}, {fileName=Proxies.java, class=java.lang.StackTraceElement, lineNumber=89, className=org.openqa.selenium.browserlaunchers.Proxies, nativeMethod=false, methodName=extractProxy, hCode=1884119507}, {fileName=Proxies.java, class=java.lang.StackTraceElement, lineNumber=102, className=org.openqa.selenium.browserlaunchers.Proxies, nativeMethod=false, methodName=newProxyPac, hCode=900009655}, {fileName=Proxies.java, class=java.lang.StackTraceElement, lineNumber=63, className=org.openqa.selenium.browserlaunchers.Proxies, nativeMethod=false, methodName=makeProxyPAC, hCode=-93135522}, {fileName=Proxies.java, class=java.lang.StackTraceElement, lineNumber=55, className=org.openqa.selenium.browserlaunchers.Proxies, nativeMethod=false, methodName=makeProxyPAC, hCode=-93135530}, {fileName=WindowsProxyManager.java, class=java.lang.StackTraceElement, lineNumber=163, className=org.openqa.selenium.browserlaunchers.WindowsProxyManager, nativeMethod=false, methodName=changeRegistrySettings, hCode=1121757824}, {fileName=InternetExplorerDriver.java, class=java.lang.StackTraceElement, lineNumber=125, className=org.openqa.selenium.ie.InternetExplorerDriver, nativeMethod=false, methodName=prepareProxy, hCode=-847606776}, {fileName=InternetExplorerDriver.java, class=java.lang.StackTraceElement, lineNumber=68, className=org.openqa.selenium.ie.InternetExplorerDriver, nativeMethod=false, methodName=, hCode=-2098680358}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-2, className=sun.reflect.NativeConstructorAccessorImpl, nativeMethod=true, methodName=newInstance0, hCode=513928194}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=sun.reflect.NativeConstructorAccessorImpl, nativeMethod=false, methodName=newInstance, hCode=-432498851}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=sun.reflect.DelegatingConstructorAccessorImpl, nativeMethod=false, methodName=newInstance, hCode=-2147429624}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=java.lang.reflect.Constructor, nativeMethod=false, methodName=newInstance, hCode=-1851634561}, {fileName=DefaultDriverFactory.java, class=java.lang.StackTraceElement, lineNumber=87, className=org.openqa.selenium.remote.server.DefaultDriverFactory, nativeMethod=false, methodName=callConstructor, hCode=-368088102}, {fileName=DefaultDriverFactory.java, class=java.lang.StackTraceElement, lineNumber=81, className=org.openqa.selenium.remote.server.DefaultDriverFactory, nativeMethod=false, methodName=newInstance, hCode=-1365021395}, {fileName=DefaultSession.java, class=java.lang.StackTraceElement, lineNumber=154, className=org.openqa.selenium.remote.server.DefaultSession$BrowserCreator, nativeMethod=false, methodName=call, hCode=2056168403}, {fileName=DefaultSession.java, class=java.lang.StackTraceElement, lineNumber=1, className=org.openqa.selenium.remote.server.DefaultSession$BrowserCreator, nativeMethod=false, methodName=call, hCode=2056168250}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=java.util.concurrent.FutureTask$Sync, nativeMethod=false, methodName=innerRun, hCode=1144956884}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=java.util.concurrent.FutureTask, nativeMethod=false, methodName=run, hCode=424519275}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=java.util.concurrent.ThreadPoolExecutor$Worker, nativeMethod=false, methodName=runTask, hCode=-1076768003}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=java.util.concurrent.ThreadPoolExecutor$Worker, nativeMethod=false, methodName=run, hCode=-166011880}, {fileName=null, class=java.lang.StackTraceElement, lineNumber=-1, className=java.lang.Thread, nativeMethod=false, methodName=run, hCode=1432591020}]}]