New issue 3750 by lsjua...@gmail.com: WebdriverJS: Will get
NullPointerException exception when call addCookie
http://code.google.com/p/selenium/issues/detail?id=3750
What steps will reproduce the problem?
1. Call addCookie function with Webdriver javascript
What is the expected output? What do you see instead?
The cookie I want to add should be in the browser. But instead, I got an
exception on selenium server as following:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
org.openqa.jetty.jetty.servlet.ServletHandler - EXCEPTION
javax.servlet.ServletException: java.lang.NullPointerException
at
org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet .java:
590)
at
org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:
523)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at
org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:
490)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at
org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:
428)
at
org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:
677)
at
org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:
568)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:
820)
at
org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:
986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:
837)
at
org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:
243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:
357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:
534)
Caused by: java.lang.NullPointerException
at java.util.HashMap.<init>(Unknown Source)
at com.google.common.collect.Maps.newHashMap(Maps.java:138)
at
org.openqa.selenium.remote.server.handler.CookieHandler.setJsonParameters(C
ookieHandler.java:
45)
at
org.openqa.selenium.remote.server.rest.ResultConfig.setJsonParameters(Resul
tConfig.java:
267)
at
org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.jav
a:
187)
at
org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet .java:
586)
... 16 more
Selenium version:
Selenium-server: 2.15.0
WebdriverJS: Don't know how get the version of it.
OS: Any
Browser: Any
Browser version:
The root cause of this exception is the WebdriverJS didn't provide
correct format of the cookie parameter.
To fix this problem, I'd like to suggest to change the code of method
webdriver.WebDriver.Options.prototype.addCookie in ${selenium-source}/
javascript/webdriver/webdriver.js as following:
/**
* Schedules a command to add a cookie.
* @param {string} name The cookie name.
* @param {string} value The cookie value.
* @param {string=} opt_path The cookie path.
* @param {string=} opt_domain The cookie domain.
* @param {boolean=} opt_isSecure Whether the cookie is secure.
* @return {!webdriver.promise.Promise} A promise that will be
resolved when the
* cookie has been added to the page.
* @export
*/
webdriver.WebDriver.Options.prototype.addCookie = function(name,
value,
opt_path,
opt_domain,
opt_isSecure) {
// We do not allow '=' or ';' in the name.
if (/[;=]/.test(name)) {
throw Error('Invalid cookie name "' + name + '"');
}
// We do not allow ';' in value.
if (/;/.test(value)) {
throw Error('Invalid cookie value "' + value + '"');
}
var cookieString = name + '=' + value +
(opt_domain ? ';domain=' + opt_domain : '') +
(opt_path ? ';path=' + opt_path : '') +
(opt_isSecure ? ';secure' : ''),
cookiePara = {
name: name,
value: value,
domain: opt_domain||'',
path: opt_path||'',
secure: !!opt_isSecure
};
return this.driver_.schedule(
new webdriver.Command(webdriver.CommandName.ADD_COOKIE).
setParameter('cookie', cookiePara),
'WebDriver.manage().addCookie(' + cookieString + ')');
};
I've tested on my side, it works well. Please consider to do this code
update, thanks.
The attachment is the code update patch. Please take a look.
Attachments:
update.patch 1.1 KB
Comment #3 on issue 3750 by jml...@gmail.com: WebdriverJS: Will get
NullPointerException exception when call addCookie
http://code.google.com/p/selenium/issues/detail?id=3750
(No comment was entered for this change.)
Comment #4 on issue 3750 by jml...@gmail.com: WebdriverJS: Will get
NullPointerException exception when call addCookie
http://code.google.com/p/selenium/issues/detail?id=3750
This issue was closed by revision r16663.