Cypress runs commands twice when no baseUrl defined
See original GitHub issueCurrent behavior:
Right now, whenever you start Cypress it will kick off some of the commands twice.
This isnβt a problem most of the time as tests should be self contained anyway, but if you are using before hooks (for instance, to login and store cookies, as suggested by the docs) it becomes quite detrimental.
Desired behavior:
Cypress should only run once.
Steps to reproduce:
//__bug.spec.js
describe('Bug?', ()=>{
before(() =>{
cy.task('message', 'I\'m running!');
});
it('Should only log once', () => {
cy.visit('https://www.google.com');
});
});
//index.js
module.exports = (on) => {
on('task', {
message (args) {
console.log(args);
return null;
}
});
};
- Run the spec
- Results:
====================================================================================================
(Run Starting)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Cypress: 3.1.1 β
β Browser: Electron 59 (headless) β
β Specs: 1 found (__bug.spec.js) β
β Searched: cypress/integration/__bug.spec.js β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running: __bug.spec.js... (1 of 1)
Bug
I'm running!
I'm running!
β Should only log once (1159ms)
Note: this isnβt exclusive to hooks! The below spec will also print unwanted results:
describe('Bug', ()=>{
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
it('Should only log once', () => {
cy.task('message', 'I\'m running!');
cy.visit('https://www.google.com');
});
});
Results:
Running: __bug.spec.js... (1 of 1)
Bug
I'm running!
I'm running!
β Should only log once (1091ms)
I'm running!
β Should only log once (3876ms)
I'm running!
β Should only log once (992ms)
I'm running!
β Should only log once (1449ms)
If the commands are inverted (i.e., if you visit() before logging) then the results are fine, so maybe Cypress waits for visit then reboots?
Versions
Electron 59 headless Cypress 3.1.1 macOS High Sierra 10.13.6
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:24 (5 by maintainers)
Top Results From Across the Web
visit - Cypress Documentation
Visit local filesββ Cypress will automatically attempt to serve your files if you don't provide a host and baseUrl is not defined. The...
Read more >Cypress triggers cy.wait(1000) twice in separate tests
Cypress changes the parent domain to match the baseUrl, in order to avoid issues with navigating on a website that does not match...
Read more >Run Two Cypress Test Runners At The Same Time
The configuration files # Β· While running two Cypress instances, we are not using any plugins or custom commands, thus we disable the...
Read more >cypress-io/cypress - Gitter
@eXpLoD96 No you can't. integrationFolder in cypress.json created to define the root folder for all your tests. When you want to run specific...
Read more >How to Add Screenshot Testing with Cypress to Your Project
In this post, you will learn how to use Cypress to capture parts of pages of a website. ... The baseUrl is the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@jennifer-shehane I see that you have labeled this as the intended workaround. However, have you seen occasions where this workaround does not work? It seems like I am not the only one who is unable to get this duplicate behavior to stop even when setting a baseUrl in the
cypress.jsonfile@jennifer-shehane same behaviour is when
baseUrlis defined but I want to visit other page. Ie. I setbaseUrl='https://www.google.com/'and in my test will docy.visit('https://duckduckgo.com/')then all before commands will run twice.