Skip to content
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

afterEach hook is triggered after test runner was stopped. #8621

Closed
tzolnai opened this issue Sep 18, 2020 · 5 comments · Fixed by #8622
Closed

afterEach hook is triggered after test runner was stopped. #8621

tzolnai opened this issue Sep 18, 2020 · 5 comments · Fixed by #8622
Assignees

Comments

@tzolnai
Copy link

tzolnai commented Sep 18, 2020

I can't effectively stop the interactive test runner with the stop button (black rectangle). The test stops, but the interrupted command (e.g. cy.get(), cy.click()) hits a timeout and then afterEach hook is triggered.

In our environment, afterEach hook closes the site what we are testing, so If I stop the test runner I have only some seconds (defaultCommandTimeout) to check the DOM elements in the debugger tools until the interrupted command times out and the site is closed. I think the test runner should stop where it is, so I can interact with the site anytime.

For example in an environment, where there are iframes, I can't get the DOM state after the test finished, because cypress does not record it correctly. So it would be useful if I could stop the test and check the live site instead.

Current behavior:

Stoping a cy.get() or cy.click() command will time out and trigger afterEach hook.

Desired behavior:

Stoping a cy.get() or cy.click() command should not trigger afterEach hook, but should stop the test execution entirely.

Test code to reproduce

There is a simple test code bellow. Since there is no item with the ID #holy-grail you can easily stop the test runner while it is trying to find that item. Try to interrupt the cy.get() command. It stops, but it will time out. I can see also the time out progress bar moving. After the timeout, afterEach hook is run and the test leaves the original site, so I can't interact with it.

describe('Example test.', function() {
	afterEach(function() {
		cy.visit('https://googlechrome.github.io/samples/arrows-es6/');
	});

	it('Test 1.', function() {
		cy.visit('https://googlechrome.github.io/samples/picture-in-picture/');
		
		cy.get('#holy-grail')
			.click();
	});
});

Versions

cypress version: 5.1.0
browser: chromium 78.0.3904.108
OS: openSUSE Leap 15.0

@tzolnai
Copy link
Author

tzolnai commented Sep 18, 2020

A workaround suggestion would be also useful. If there is a way to programmatically check whether the test was stopped, then I could skip the code inside the afterEach method.

@kuceb
Copy link
Contributor

kuceb commented Sep 18, 2020

There's a PR up for a fix, as a workaround you can detect if the runner has been stopped via:

Cypress.mocha.getRunner().stopped

@tzolnai
Copy link
Author

tzolnai commented Sep 19, 2020

Thanks for the workaround idea! It works nicely.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Sep 24, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Sep 28, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 28, 2020

The code for this is done in cypress-io/cypress#8622, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 29, 2020

Released in 5.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.3.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants