我正在尝试使用 Selenium Webdriver 设置然后读取 Cookie。添加 Cookie 工作正常。但是,当我尝试读取 cookie 时,Selenium 会引发异常。
- 我正在使用 Selenium 的 Java API。
- 测试用例使用 TestNG 运行。5.12 版
- Selenium webdriver-htmlunit 版本 0.9.7376
测试用例代码
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 + "]");
堆栈跟踪
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)
任何帮助将不胜感激。