I am trying to set and then read a Cookie using the Selenium Webdriver.
Adding Cookie works fine.
However, when I am trying to read the cookie, an exception is thrown by Selenium.
- I am using the Java API for Selenium.
- The test cases are run using TestNG. ver 5.12
- Selenium webdriver-htmlunit version 0.9.7376
Test case code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.Cookie;
.
.
.
WebDriver driver = ....
// Now set the cookie. This one's valid for the entire domain
Cookie testCookie = new Cookie.Builder("myCookie", "cookieValue").domain("localhost").path("/").build();
//Works fine till here
driver.manage().addCookie(testCookie);
//breaks here
String cookieFromBrow = driver.manage().getCookieNamed("myCookie").toString();
System.out.println("Cookie :- [" + cookieFromBrow + "]");
Stacktrace
java.lang.NoSuchMethodError: org.openqa.selenium.internal.ReturnedCookie.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Date;Z)V
at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitOptions.getCookies(HtmlUnitDriver.java:851)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitOptions.getCookieNamed(HtmlUnitDriver.java:812)
at com.medomain.site.test.SampleResultPageIntlITCase.initTestPage(SampleResultPageIntlITCase.java:150)
at com.medomain.site.test.SampleResultPageIntlITCase.testFindCaseForm(SampleResultPageIntlITCase.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:702)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:768)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1022)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Any help will be really appreciated.
The problem is method
getSecure()onorg.apache.commons.httpclient.Cookiewhich appears to be missing.You seem to have entered the JAR hell and some of your libraries / dependencies in your project conflict with each other in the
org.apache.commons.httpclientversion. The WebDriver you use wants version 3.1. Check all the dependencies on your project, find the offending library and the version ofhttpclientthat really makes in into your classpath.Try to use the newer one of the two – if that doesn’t help, good luck :).