-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cypress version 4.3.0]TypeError: Cannot read property 'key' of undefined #6890
Comments
I was not able to replicate. I am able to visit the URL in my test runner on 4.3.0. Are you possible logged in on your version of Chrome? The error says the URL it is trying to visit is followed by /logout, so I'm thinking you are being redirected in some way. You may have better luck setting the |
@CypressCecelia I am also having the same issue. It appears that both my web site and https://onlinedoctor.lloydspharmacy.com/ are protected by Incapsula (https://www.imperva.com/imperva-incapsula-faq/). Incapsula generates cookies that Cypress fails to parse. Here is code from setCookiesOnBrowser: function(res, resUrl, automationFn) {
...
return Promise.map(cookies, function (cyCookie) {
var cookie, expiry;
cookie = tough.Cookie.parse(cyCookie, {
loose: true
});
debug('parsing cookie %o', {
cyCookie: cyCookie,
toughCookie: cookie
});
cookie.name = cookie.key; \\ <<<< This fails because cookie is undefined. Here is Cypress log (I changed some random values for security reasons):
As you can see |
@abasau-incomm @natkrish - Can you downgrade to Cypress 4.2.0 and verify if this fixes the issue? @natkrish (For my future notes - I had to VPN in to US because their website is blocked in my country). I'm not able to reproduce the error with the given code - please provide all @abasau-incomm I don't see an exact change to these lines of code, although I do see that tough-cookie was updated in 4.3.0 here: https://github.com/cypress-io/cypress/pull/6778/files#diff-8c42f42f65d0890e0bba62a07ab08042R108 Please also if you can provide a reproducible example - this would be helpful. |
@jennifer-shehane @abasau-incomm @CypressCecelia As per @abasau-incomm said my site is protected by Incapsula. I am not sure why this happens and every time I come across this type of issue on production - I then had to downgrade to 3.4.1 which is the only version that doesn't throw this error. cypress/plugins/index.js// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const cucumber = require('cypress-cucumber-preprocessor').default;
function getCliArgs(args) {
args = args.filter((arg) => {
return arg !== "--use-fake-ui-for-media-stream" && arg !== "--use-fake-device-for-media-stream"
});
args.push('--allow-file-access-from-files');
return args
}
module.exports = (on, config) => {
/** the rest of your plugins... **/
require('cypress-log-to-output').install(on);
on('file:preprocessor', cucumber());
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
on('before:browser:launch', (browser, args) => {
if (browser.family === 'chrome') {
// `args` is a list of all the arguments that will be passed to Chrome when it launchers
return getCliArgs(args)
} else if (browser.family === 'electron') {
// `args` is a `BrowserWindow` options object
// https://electronjs.org/docs/api/browser-window#new-browserwindowoptions
if (!args.webPreferences) {
args.webPreferences = {}
}
if (!args.webPreferences.additionalArguments) {
args.webPreferences.additionalArguments = []
}
args.webPreferences.additionalArguments = getCliArgs(args.webPreferences.additionalArguments);
return args
}
})
}; cypress.json{
"chromeWebSecurity": false,
"reporter": "mochawesome",
"reporterOptions": {
"overwrite": true,
"html": false,
"json": true,
"timestamp": "mmddyyyy_HHMMss"
},
"projectId": "4zqjtd",
"modifyObstructiveCode": false,
"pageLoadTimeout": 60000,
"baseUrl": "https://onlinedoctor.lloydspharmacy.com/",
"nodeVersion":"system"
} cypress/support/commands.jscypress/support/index.js// Import commands.js using ES2015 syntax:
import '@bahmutov/cy-api/support'
import './commands'
require('cypress-plugin-retries');
const addContext = require('mochawesome/addContext');
Cypress.on('test:after:run', (test, runnable) => {
if (test.state === 'failed') {
const screenshotFileName = `${runnable.parent.title} -- ${test.title} (failed).png`;
addContext({ test }, `assets/${Cypress.spec.name}/${screenshotFileName}`)
}
});
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
}); |
@jennifer-shehane I checked cypress 4.2.0 and a similar issue is reproducible there (#5602) - Cypress fails with Also I found a stable way to reproduce the issue. You will need to:
public static void OnBeforeResponse(Session oSession)
{
if (m_Hide304s && oSession.responseCode == 304)
{
oSession["ui-hide"] = "true";
}
oSession.oResponse["Set-Cookie"] = "___utmvaFvuoaRv=TkE\u0001sCvZ; path=/; Max-Age=900";
}
cy.request({ method: 'GET', url: 'https://onlinedoctor.lloydspharmacy.com/' }); |
I can definitely reproduce this within our code base. Here is the failing step on version 4.3.0: And here is the failing step on version 4.2.0 The same exact step is able to pass on version 3.4.1 Here is our code: Cypress.Commands.add("login", (email, password) => {
cy.request({
url: '/account/login',
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json;charset=UTF-8' },
body: {
EmailAddress: email,
Password: password
},
followRedirect: true
})
}) System info: Note: Our entire test site is behind Incapsula and NGINX but every other request/page is able to load just fine on v4.3.0 which contains fix #5988 that addressed #5602 which we originally posted as a parse error issue as well. I would not be surprised if there was some sort of correlation. P.S. I am not sure if this is caused by the exact same error.. If it is, the previous error message was clearer and I would expect to see that. The new error message had me debugging my VPN, Incapsula, and the actual code to see if one of my changes caused the request to abort prematurely. Thanks! Thanks! |
This issue occurs when
Even if
I was curious about how real browsers react to headers with invalid control characters, so I tried visiting this controller in Firefox and Chrome: app.get "/invalidControlCharCookie", (req, res) ->
## `http` lib throws an error if we use .setHeader to set this
res.connection.end("""
HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: ___utmvaFvuoaRv=TkE\u0001sCvZ; path=/; Max-Age=900
Set-Cookie: _valid=true; path=/; Max-Age=900
foo
""") Chrome 80 complains of invalid Set-Cookie headers and only sets the second cookie: Firefox 75 appears to receive the cookie, but fails to actually set it in storage: In light of this, I think the best way to resolve this issue is to make Cypress ignore invalid cookie values in requests, just like browsers do. |
* add invalid header char repro * ignore tough-cookie/automation failures see #6890 (comment) * restore snapshot * Update packages/server/lib/request.coffee * Update packages/server/lib/request.coffee Co-Authored-By: Jennifer Shehane <jennifer@cypress.io> Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
The code for this is done in cypress-io/cypress#6948, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
@flotwig
Current behavior:
So when I load our live site using cy.visit('https://onlinedoctor.lloydspharmacy.com') using cypress version 4.3.0 - I get the below error.
Desired behavior:
I expect to be able to load our public site without any issues.
Test code to reproduce
I think to repproduce this issue just simply access our live site using cy.visit('https://onlinedoctor.lloydspharmacy.com');
Please try and replicate with the version set up
Versions
Cypress version - 4.3.0
Chrome - 80
Windows 10 - 64 bit
Node 12.16.1
I was expecting for it to work after the bug fix for this ticket - #5602
The text was updated successfully, but these errors were encountered: