Я не могу установить cookie-файлы для ChromeDriver, работающего в автономном режиме - PullRequest
0 голосов
/ 17 июня 2019

Когда я запускаю свои тесты на селен, используя ChromeDriver в режиме без головы, вызов метода addCookie вызывает исключение; все тесты работают в обычном режиме

Моя версия браузера Chrome - 75.0.3770.90, а версия ChromeDriver - 75.0.3770.8. ОС Mac OS X 10.14.5

Исключение, которое я получаю:

    org.openqa.selenium.UnableToSetCookieException: unable to set cookie
    (Session info: headless chrome=75.0.3770.90)
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'A0353.local', ip: 'fe80:0:0:0:84c:de05:352a:4bcc%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.5', java.version: '1.8.0_45'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities {acceptInsecureCerts: false, browserName: chrome,         browserVersion: 75.0.3770.90, chrome: {chromedriverVersion: 75.0.3770.8 (681f24ea911fe7..., userDataDir: /var/folders/nc/gqkjhl8920j...}, goog:chromeOptions: {debuggerAddress: localhost:63795}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
    Session ID: db1528ca16e944bb6596563337e1ba40
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions.addCookie(RemoteWebDriver.java:682)
    at com.anatwine.testing.common.selenium.PageObject.addCookie(PageObject.java:187)
    at com.anatwine.testing.component.page.landingpage.LandingPage.addUsernameAndRolesCookies(LandingPage.java:54)
    at com.anatwine.testing.component.steps.portallandingpage.RoleBasedAuthorisationSteps.lambda$new$347(RoleBasedAuthorisationSteps.java:32)
    at com.anatwine.testing.component.steps.portallandingpage.RoleBasedAuthorisationSteps$$Lambda$494/785340693.accept(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at cucumber.runtime.Utils$1.call(Utils.java:26)
    at cucumber.runtime.Timeout.timeout(Timeout.java:16)
    at cucumber.runtime.Utils.invoke(Utils.java:20)
    at cucumber.runtime.java8.Java8StepDefinition.execute(Java8StepDefinition.java:112)
    at cucumber.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
    at cucumber.runner.TestStep.executeStep(TestStep.java:63)
    at cucumber.runner.TestStep.run(TestStep.java:49)
    at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:43)
    at cucumber.runner.TestCase.run(TestCase.java:44)
    at cucumber.runner.Runner.runPickle(Runner.java:40)
    at cucumber.runtime.Runtime$1.run(Runtime.java:84)
    at cucumber.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:220)
    at cucumber.runtime.Runtime.run(Runtime.java:81)
    at cucumber.api.cli.Main.run(Main.java:26)
    at cucumber.api.cli.Main.main(Main.java:8)
    at ✽.A user has 'ROLE_LANDING,ROLE_BRAND_ORDERSIM' roles(feature/component/portal-landingpage/PortalLandingPageRoleAuthorisations.feature:12)

Код, вызывающий проблему:

    driver.get(initialPageUrl);    
    Cookie cookie = new Cookie(cookieName, encode(cookieValue, "UTF-8"), "localhost","/", null);
    driver.manage().addCookie(cookie);

Ответы [ 2 ]

1 голос
/ 17 июня 2019

Возможно, вы добавили куки перед переходом на сайт. Сначала вы должны перейти на ваш URL

driver.get("yourWebPage");

и только после этого добавляйте куки

driver.manage().addCookie(cookie);

Для лучшего анализа того, что идет не так, если вышеперечисленное не поможет, вам нужно добавить больше кода своей программы.

Также возможно дубликат этого .

0 голосов
/ 04 июля 2019

Он выглядит в автономном режиме, который ДОЛЖЕН иметь протокол в URL страницы, в то время как в обычном режиме веб-драйвер по умолчанию использует http.Поэтому, как только мы заменили «localhost: 8080 / path» на «http://localhost:8080/path", это сработало.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...