Open osdiab opened 1 year ago
Same issue with Cypress 12.9.0, Node: 18.13.0, Windows 10.0.19044, Built-in Electron. Reproduction is also inconsistent but when it happens, it involves cy.session().
@mirobo, @osdiab We would love to take a look at this issue. I know you said it's inconsistent and hard to reproduce but can either of you provide a reproducible example so we can investigate further?
I'll ask my colleagues to keep an eye out for when it happens to them and hopefully they can record a video or something of it happening, hopefully from that can divine the cause and some repro steps a little better.
@jordanpowell88 Following the code - this is likely coming from here where we are parsing the cookies from the response...
It would be interesting to understand typically when this error is hit since, to better account for what might be going on to see this error, but we likely need a safe-guard here as well to ensure the response is defined.
We see this error occasionally when running our component tests in CI (Jenkins).
Cannot read properties of undefined (reading 'cookies') Because this error occurred during a `before all` hook we are skipping all of the remaining tests.
TypeError: Cannot read properties of undefined (reading 'cookies')
Because this error occurred during a `before all` hook we are skipping all of the remaining tests.
at <embedded>:4649:284999
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
It would be interesting to understand typically when this error is hit since, to better account for what might be going on to see this error, but we likely need a safe-guard here as well to ensure the response is defined.
That certainly looks like the LOC @emilyrohrbough . Is anyone able to provide a reproducible example?
See the same issue popup intermittently in our component tests as @albinohrn mentioned. It happens in the beforeEach
block and we do nothing there with cookies. So not sure what is causing the issue.
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
Timed out waiting for the browser to connect. Retrying...
<i> [webpack-dev-middleware] wait until bundle finished: /__cypress/src/index.html
73 assets
1892 modules
webpack 5.48.0 compiled successfully in 115523 ms
No errors found.
Employee Notes
(Attempt 1 of 2) render loading state
1) "before each" hook for "render loading state"
0 passing (713ms)
1 failing
1) Employee Notes
"before each" hook for "render loading state":
TypeError: Cannot read properties of undefined (reading 'cookies')
Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `Employee Notes`
at <embedded>:4649:284999
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
The test itself is barely doing anything
import { EmployeeNotes } from '../../pages/EmployeeNotes/EmployeeNotes';
describe('Employee Notes', () => {
beforeEach(() => {
cy.clock(Date.UTC(2021, 2, 1), ['Date']);
});
it('render loading state', () => {
cy.mount(<EmployeeNotes />);
cy.findByTestId('employee-notes-loading-state').should('exist');
});
it('render notes', () => {
cy.interceptGetEmployeeNotesAPI();
cy.mount(<EmployeeNotes />);
cy.wait(['@getEmployeeNotes']);
cy.findByTestId('employee-notes-container').should('exist');
});
});
@blessanm86 Do you have a beforeEach
in your component test support file?
@warrensplayer No I don't. It's just a bunch of commands and interceptors. But I do import the following in there. Not sure if they do something.
import '@testing-library/cypress/add-commands';
import { configure } from '@testing-library/cypress';
@warrensplayer We have the same issue and we do have a global beforeEach that sets some fixture data.
@warrensplayer So I tried enabling cypress logs and take a dump. Here is a link to the gist. I hope this can shed some light
I just experienced this issue as well. I'm also not doing anything with sessions or cookies. I restarted Cypress and the error disappeared.
For folks who experience this pretty consistently, if you change your e2e config to us testIsolation: false
does that prevent the issue from happening? It might have other side effects so I wouldn't recommend just setting that as a solution, but I wonder if something is happening in Cypress's own cleanup in-between specs, and this would point us in the right direction.
I'm also curious if there is a publicly-accessible URL I could test with, feel free to email me at mark@cypress.io if you are able to share something privately
This happens with us in gitlab ci as well, curiously it's always one particular test that runs into this error. This is the image we are using to test: cypress/browsers:node14.17.6-chrome100-ff98
.
Attempts to reproduce this locally have failed.
Cypress version: 12.11.0
Edit: we are not using any beforeeach.
@MDanialSaleem I'm curious with the testIsolation: false
configuration does that problem still occur in that specific test in CI?
Attempts to reproduce this locally have failed.
This must be frustrating. Any more details about what that specific test might be doing that others are not?
@MDanialSaleem I'm curious with the
testIsolation: false
configuration does that problem still occur in that specific test in CI?Attempts to reproduce this locally have failed.
This must be frustrating. Any more details about what that specific test might be doing that others are not?
We don't yet have e2e tests with cypress yet so I can't enable testIsolation. These are component tests (we're migrating over from jest, one of the prime reasons was the flakiness of jsdom based tests so it's kinda funny that's this is happening lol).
To answer your second question, no, all tests are pretty much the same, nothing special about this one. I'll try and create a reproducable example without any of our proprietary code if this issue persists. And if we're able to figure out a workaround/root cause, I'll update here as well.
Thanks! Even the information that this is a component test helps a lot as it rules out a lot of things.
After debugging a little bit, I think I have found at least where this is triggered, even if not the underlying cause:
If result
is undefined
in return normalizeGetCookies(result.cookies)
, I get this stack trace that matches what has been shown in this issue.
So for when this is picked up: it seems like this.sendDebuggerCommandFn('Network.getAllCookies')
must sometimes be able to resolve with undefined
as the result? I'm not familiar with this part of the code or exactly how this all works.
Stacktrace from forcing this to happen on develop
. Notice the last 5 lines.
TypeError: Cannot read properties of undefined (reading 'cookies')
at /path/to/cypress/packages/server/lib/browsers/cdp_automation.ts:227:40
at /path/to/cypress/packages/server/lib/automation/automation.ts:55:25
at Cookies.getCookies (/path/to/cypress/packages/server/lib/automation/cookies.ts:116:12)
at /path/to/cypress/packages/server/lib/automation/automation.ts:106:31
at Automation.normalize (/path/to/cypress/packages/server/lib/automation/automation.ts:101:25)
at /path/to/cypress/packages/server/lib/automation/automation.ts:170:19
at processImmediate (node:internal/timers:466:22)
at Automation.request (/path/to/cypress/packages/server/lib/automation/automation.ts:169:6)
at automationRequest (/path/to/cypress/packages/server/lib/socket-base.ts:166:25)
at Socket.<anonymous> (/path/to/cypress/packages/server/lib/socket-base.ts:265:16)
at Socket.emit (node:events:527:29)
at Socket.emitUntyped (<embedded>:852852:21)
at <embedded>:853114:32
at processTicksAndRejections (node:internal/process/task_queues:78:12)
From previous event:
at $Cypress.automation (cypress:///../driver/src/cypress.ts:630:12)
at Object.getCookies (cypress:///../driver/src/cy/commands/sessions/manager.ts:121:29)
at Object.clearCookies (cypress:///../driver/src/cy/commands/sessions/manager.ts:127:77)
at Object.clearCurrentSessionData (cypress:///../driver/src/cy/commands/sessions/manager.ts:118:127)
at eval (cypress:///../driver/src/cy/commands/sessions/index.ts:41:110)
Note: routed this to both E2E and CT teams, since it affects both.
Hey team! Please add your planning poker estimate with Zenhub @astone123 @dkasper-was-taken @jordanpowell88 @lmiller1990 @marktnoonan @mike-plummer
I'm estimating based on a path forward where we add a check for undefined
and retry sendDebuggerCommandFn
until some timeout, then throw the error, since it's not something that makes sense to ignore if undefined
is found. Assuming the underlying cause is the CDP just dropping this.
I am estimating this based on the fact there is no reliable, minimal reproduction, meaning it will be hard to both debug, fix and test with confidence we are fixing the actual, underlying bug.
Estimating based on adding the check
I am facing this issue too, at the moment. For me, this issue occurs every time after I opened the URL from our Website in the Cypress GUI and closed it again.
Can you provide a minimal reproduction @AlessandroCaggiano ? Is it consistent?
It's a consistent error
Can you share some random test? Or, ideally, a minimal reproduction - if you can share a repository we can clone and use to reproduce the error consistently, that would make fixing this a whole lot easier.
Right now it's hard to be confident in any patch since we cannot consistently reproduce the error, but it sounds like you are able to do so.
Sorry, I can't share this repository.
In my case I got this error due to this code
cy.window().then(win => {
cy.stub(win, 'open').as('windowOpen');
});
called before the page actually loads after the cy.visit(...)
.
Still running into this issue. Has anyone implemented a fix or found a solution?
Hi all, I iave this problem also. its reproducable. The Error accurs, when a click on the UI opens a pdf file in a new tab. I tried to prevent it with .invoke('removeAttr', 'target', "_self") before clicking, but n the tests is always a new empty window opened. The Tests goes on but when restart the test later, this error accurs.
is there anybody on that?
Hi All,
Did someone already fixed this issue in some other PR or may be I can work on that?
Please respond asap, thanks..
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.
Current behavior
Not sure why, but every now and again multiple members of our team get the error above in the Cypress test window along with this stack trace:
looks like something in the cypress runner that clears session between tests is failing.
Desired behavior
No response
Test code to reproduce
it's inconsistent when it happens, so it's hard for me to make a clear repro. But here is our cypress config:
Cypress Version
12.9.0
Node version
16.16.0
Operating System
macOS 13.2.1
Debug Logs
No response
Other
No response