Skip to content

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

@tzolnai

Description

@tzolnai

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions