I cannot get value cookies if i use typescript.
If i use javascript, and use code in my test cy.getCookie('JSESSIONID').value i can get value, but if i use this code in typescript i get error Error:(19, 54) TS2339: Property 'value' does not exist on type 'Chainable<Cookie>'.
It is strange, because cy.getCookie('') return to me chainable, and not cookie
Like in javascript. I want get cookie by name. cy.getCookie('').value should return value for cookie
I have error in my IDE, because cy.getCookie('').value return Chainable
For example You can clone this project https://github.com/basarat/cypress-ts and write this code in file cypress/integration/example.ts
describe('test describe', function () {
it('test', function () {
cy.getCookie('').value
})
})
"dependencies": {
"@cypress/webpack-preprocessor": "4.1.0",
"cypress": "3.3.2",
"ts-loader": "6.0.4",
"typescript": "3.5.2",
"webpack": "4.35.2"
},
"devDependencies": {
"@types/node": "^12.7.5",
"Faker": "^0.7.2"
}
MacOS 10.14.6
If it can may help, my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": [
"dom",
"esnext"
],
"jsx": "react",
"types": [
"cypress",
"node"
],
"typeRoots": [
"node_modules/@types"
],
"esModuleInterop": true,
"experimentalDecorators": true
},
"compileOnSave": false
}
I think you can fix this problem like this:
in
cypress / types / index.d.ts
In the following lines:
getCookie (name: string, options ?: Partial <Loggable & Timeoutable>): Chainable <Cookie | null>
...聽聽聽聽
getCookies (options ?: Partial <Loggable & Timeoutable>): Chainable <Cookie [] | null;>
...
interface Cookie {
You change them to:
聽getCookie (name: string, options ?: Partial <Loggable & Timeoutable>): Cookie | null
聽...聽
getCookies (options ?: Partial <Loggable & Timeoutable>): Cookie [] | null
...
interface Cookie extends Chainable {
Or, you can just edit getCookie return type
getCookie(name: string, options?: Partial<Loggable & Timeoutable>): Chainable<Cookie | null> & (Cookie | null)
By the way, according to the official guideline, you have to use .then() for such task. E.g.:
cy.getCookie('SESSION').then(cookie => cookie.value);
@jennifer-shehane RFC
.value is not a valid chainer off of any cypress command, neither the cy.getCookie() command, as the TypeScript error describes. You would do this the way @Mkots described:
cy.getCookie('SESSION').then(cookie => cookie.value);
@jennifer-shehane
.valueis not a valid chainer off of any cypress command, neither thecy.getCookie()command, as the TypeScript error describes. You would do this the way @Mkots described:cy.getCookie('SESSION').then(cookie => cookie.value);
Please update your documentation https://docs.cypress.io/api/commands/getcookie.html#Yields because it says:
cy.getCookie()yields a cookie object with the following properties:
...
value
cy.getCookie() yields an object with the value property. So you have to access that object then that property. cy.getCookie().value() is invalid. The documentation is correct in this case.
Most helpful comment
I think you can fix this problem like this:
in
In the following lines:
You change them to:
Or, you can just edit getCookie return type
By the way, according to the official guideline, you have to use .then() for such task. E.g.:
@jennifer-shehane RFC