Proxy server settings

318 views
Skip to first unread message

Paul Allen

unread,
Jun 9, 2008, 12:02:15 PM6/9/08
to webdriver
I am using WebDriver at a client site that uses a proxy server for
Internet access. The browsers (IE & FF) are configured to use the
proxy server. However, how do I configure WebDriver so that it can
deal with the corporate proxy server authentication (userid and
password)?

I suspect that this is an issue that I am encountering when I try the
GoogleTest example. Here is the console output:

Exception in thread "main" java.lang.RuntimeException:
org.json.JSONException: A JSONObject text must begin with '{' at
character 0 of
at com.googlecode.webdriver.firefox.Response.<init>(Response.java:27)
at
com.googlecode.webdriver.firefox.internal.AbstractExtensionConnection.nextResponse(AbstractExtensionConnection.java:
197)
at
com.googlecode.webdriver.firefox.internal.AbstractExtensionConnection.readLoop(AbstractExtensionConnection.java:
162)
at
com.googlecode.webdriver.firefox.internal.AbstractExtensionConnection.waitForResponseFor(AbstractExtensionConnection.java:
155)
at
com.googlecode.webdriver.firefox.internal.AbstractExtensionConnection.sendMessageAndWaitForResponse(AbstractExtensionConnection.java:
126)
at
com.googlecode.webdriver.firefox.FirefoxDriver.sendMessage(FirefoxDriver.java:
257)
at
com.googlecode.webdriver.firefox.FirefoxDriver.sendMessage(FirefoxDriver.java:
253)
at
com.googlecode.webdriver.firefox.FirefoxDriver.fixId(FirefoxDriver.java:
264)
at
com.googlecode.webdriver.firefox.FirefoxDriver.<init>(FirefoxDriver.java:
113)
at
com.googlecode.webdriver.firefox.FirefoxDriver.<init>(FirefoxDriver.java:
69)
at
com.googlecode.webdriver.firefox.FirefoxDriver.<init>(FirefoxDriver.java:
61)
at com.sp.utils.webdriver.GoogleSuggest.main(GoogleSuggest.java:14)
Caused by: org.json.JSONException: A JSONObject text must begin with
'{' at character 0 of
at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
at org.json.JSONObject.<init>(JSONObject.java:179)
at org.json.JSONObject.<init>(JSONObject.java:326)
at com.googlecode.webdriver.firefox.Response.<init>(Response.java:15)
... 11 more

Thanks,
Paul

Simon Stewart

unread,
Jun 10, 2008, 9:03:43 AM6/10/08
to webd...@googlegroups.com
Hi Paul,

How you set the proxy is very much dependant on the browser. IE and
Safari will both use the same proxy that they normally do. If you're
using a preprepared profile in the Firefox driver then if you've set
the proxy already, it'll use whatever you've configured for that.
Otherwise:

FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("network.proxy.http", '\"your.proxy.server\"");
profile.addAdditionalPreference("network.proxy.http_port", "8080");
profile.addAdditionalPreference("network.proxy.proxy.type", "1");
WebDriver driver = new FirefoxDriver(profile);

I'm not sure how the HtmlUnit driver can be configured once it's
instantiated, but you can always override the "newWebClient()" method
completely:

new HtmlUnitDriver() {
protected WebClient newWebClient() {
WebClient client = new WebClient(
BrowserVersion.INTERNET_EXPLORER_7_0,
"proxy host",
8080);
client.setThrowExceptionOnFailingStatusCode(true);
client.setJavaScriptEnabled(false);
client.setRedirectEnabled(true);
try {
client.setUseInsecureSSL(true);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
}
return client;
}
};

If there's demand for it, we can provide a mechanism to set the proxy
in a slightly more user-friendly fashion.

Regards,

Simon

Reply all
Reply to author
Forward
0 new messages