I am setting the cookie for UI tests in a feature file using the existing login functionality implemented for API tests. Similar to what is described as 'hybrid approach' in karate docs and also in this thread - Karate UI - Maintain browser cookies/session/local storage variable value accorss different scnearios
My feature file is:
Feature: UI one time login test
Background:
# I am using the existing login functionality. I perform a onetime login in karate-config and store the cookie in a config variable and assign that to token variable defined below.
* def token = { value: '#(userAuthInfo.authSession)' }
# Then configure chromedriver
* configure driver = { type: 'chromedriver', showDriverLog: true, webDriverSession: { capabilities: { alwaysMatch: { acceptInsecureCerts: true } } } }
# Set the cookie
* driver 'about:blank'
* cookie({ name: 'SESSION', value: token.value, domain: 'localhost' })
Scenario: Visit url - 1
# webBaseUrl is defined in config
* driver webBaseUrl + 'url1'
When i run this feature and check the logs, I can see that correct request data is passed to /cookie endpoint and response from web driver api is error: 400 - invalid cookie domain. I also opened my site in chrome manually and checked how the cookie is set and its exactly the same as I am passing the json in cookie() method, including the domain. Even tried with a different domain on a different server and get the same error. Maybe it's not specific to domain as omitting the domain key in the request produces the same result.
Details below:
POST request to set cookie
14:06:36.495 [pool-1-thread-1] DEBUG com.intuit.karate - request:
4 > POST http://localhost:9515/session/c837c3e34a7dffa03fa4dc281ba0e3da/cookie
4 > Accept-Encoding: gzip,deflate
4 > Connection: Keep-Alive
4 > Content-Length: 97
4 > Content-Type: application/json; charset=UTF-8
4 > Host: localhost:9515
4 > User-Agent: Apache-HttpClient/4.5.11 (Java/1.8.0_262)
{"cookie":{"name":"SESSION","value":"cd02f1d7-6100-450b-bad9-edba8ead96b3","domain":"localhost"}}
Error 400 response:
14:06:36.501 [pool-1-thread-1] DEBUG com.intuit.karate - response time in milliseconds: 4.97
4 < 400
4 < Content-Length: 1696
4 < Content-Type: application/json; charset=utf-8
4 < cache-control: no-cache
{"value":{"error":"invalid cookie domain","message":"invalid cookie domain\n (Session info: chrome=86.0.4240.111)","stacktrace":"0 chromedriver 0x00000001080bbc29 chromedriver + 2464809\n1 chromedriver
Any ideas what could be going on?