question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress Clearing Cookies During Test Execution

See original GitHub issue
  • Operating System: OSX
  • Cypress Version: 1.0.2
  • Browser Version: CHROME Version 61.0.3163.100 (Official Build) (64-bit)

Is this a Feature or Bug?

This is a bug

Current behavior:

When cypress is executing tests, cypress for some reason clears the browser cookies. This is unexpected behavior and is making the Cypress un-useable.

Desired behavior:

For cypress not to touch browser cookies during testing.

How to reproduce:

See my code

Test code:

This is an angular 2 application.

/****** 
INDEX INTEGRATION TEST
- calls all of the test for testing a sub section of our application
- This is run after Jenkins builds the application or run on a local machine
*******/
"use strict";
import { _login } from '../../common/authenticate';
import { _navigate } from "../../common/navigate";
import * as headerTests from "./inc/header.spec";
import * as createFormModalTests from "./inc/create-form-modal.spec";
import * as showArchivedFormsTests from "./inc/show-archived-forms.spec";
import * as searchFormsTests from "./inc/search-forms.spec";
import * as tableSortingTests from "./inc/table-sorting.spec";
import * as tableActionTests from "./inc/table-actions.spec";
let formlist_url = "/administrator/index.php?option=com_mcform&view=ngformlist";
let orgid = "demo2";

context( "Authenticate", () => {
	_login( orgid );	
})
context( "Navigation", () => {
	_navigate( formlist_url );
})
context( "Forms List -> ", () => {
	describe( "Form List Header Toolbar ->", () =>{
		headerTests.executeCyTest();
	})
	describe( "Create Form Modal ->", () => {
		createFormModalTests.executeCyTest();
	})
	describe( "Show Archived Forms ->", () => {
		showArchivedFormsTests.executeCyTest();
	})	
	describe( "Search for Forms ->", () => {
		searchFormsTests.executeCyTest();
	})
        //HERE IS WHERE WE LOSE THE COOKIES
	describe( "Table sorting", () => {
		tableSortingTests.executeCyTest();
	});
})
/******
TABLE-ACTIONS.SPEC
- We use cypress to click a button which in turn calls a modal. 
- This modal executes an HTTP GET request
- By the time we open the modal, the cookies have been cleared, thus  the HTTP call fails due to dependencies on a token in the browser cookie. 
*********/
"use strict";
function cypressTest( path ){
	describe( "Table action should appear on hover", () => {
		it( "should show the action buttons on hover", () => {
			cy.get("table.td-data-table tr.td-data-table-row" ).eq( 1 )
				.find( "td.column6 > div button" ).eq( 1 ).click({ force : true })
		});
	})
}
module.exports = {
	executeCyTest : cypressTest
}

Additional Info (images, stack traces, etc)

A utility to turn off automatic cookie removal.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jtmgiocommented, Oct 17, 2017

@brian-mann Using the “defaults” method worked perfect. I attached my code for reference. Thanks again for the quick response.

describe( "Memberclicks Tests", () =>{
	
	beforeEach(() => {
		Cypress.Cookies.defaults({
			whitelist: [ "mcid_token", "serviceID" ]
		});
	})

	context( "Authenticate", () => {
	
		_login( orgid );	
	})

	context( "Navigation", () => {
		_navigate( formlist_url );
	})

	context( "Forms List -> ", () => {
		
		describe( "Form List Header Toolbar ->", () =>{
			headerTests.executeCyTest();
		})

		describe( "Create Form Modal ->", () => {
			createFormModalTests.executeCyTest();
		})
		
		describe( "Show Archived Forms ->", () => {
			showArchivedFormsTests.executeCyTest();
		})
		
		describe( "Search for Forms ->", () => {
			searchFormsTests.executeCyTest();
		})
		
		describe( "Table sorting", () => {
			tableSortingTests.executeCyTest();
		})

		describe( "Table Actions", () => {
			tableActionTests.executeCyTest();
		})
		
	})
})

0reactions
musicformellonscommented, Apr 10, 2018

Any idea why this does not work on headless mode?

Read more comments on GitHub >

github_iconTop Results From Across the Web

clearCookie - Cypress Documentation
Cypress automatically clears all cookies before each test to prevent state from being shared across tests when test isolation is enabled.
Read more >
Cypress clearCookies Command - ProgramsBuzz
Cypress clearCookies command is a way in Cypress to clear out browser cookies for the current domain and subdomain.To prevent the state from ......
Read more >
Use clearcookies in Cypress With Examples - LambdaTest
Use the clearcookies method in your next Cypress project with LambdaTest Automation Testing Advisor. Learn how to set up and run automated tests...
Read more >
How to clear cookies before running test using cypress?
cy.getCookies() // returns [{cookie1, cookie2}] cy.clearCookies() // clears both cookies cy.getCookies ...
Read more >
Cypress basics: Where did my cookies disappear? - Filip Hric
The reason is actually simple. Cypress clears out the state of browser in between tests. All your cookies are deleted from your app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found