-
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
cy.task() calls do not fire in 'test:after:run' event block #4823
Comments
I thought about using an |
So, I figured out how to get this to work in an after hook by learning more about the context available in an
after(() => {
const findTests = suite => {
suite.tests.forEach(test => {
cy.task('logTestResults', {
title: `${test.parent.title}${test.title}`,
state: test.state,
});
});
if (suite.suites.length < 1) {
return;
}
suite.suites.forEach(nestedSuite => {
findTests(nestedSuite);
});
};
cy.state('runnable').parent.suites.forEach(suite => {
findTests(suite);
});
}); However I still feel that the |
I'm having same issue but with cy.writeFile(), it seems to be ignored. Nothing happens, no error... |
I observed that all cy commands are being ignored in test:after:run, i tried cy.writeFile, cy.exec and cy.task. They all seems to be ignored. Can anyone tell me if i need to do some 'magic' or this hsould just work? |
I'm having the same issue with running node commands (path.basename) in a task fired on "test:after:run". I can't find a way to get it to work so hopefully, the Cypress team picks this up soon. |
I also ran into this issue today. Here's a little more info that may or may not help. This does work if you have an empty Weird I know, but if you just add |
Here's a reproducible example: Steps:
Notice there is no output about
Notice there is a line that mentions
|
The I understand what you all are trying to do - getting access to the |
We got to add cy.state method to our typescript definitions even if just a few properties, then our docs would be enough for people to build whatever they want I think
…Sent from my iPhone
On Dec 12, 2019, at 19:11, Brian Mann ***@***.***> wrote:
The test:after:run event is synchronous and will not respect async cypress commands - and likely never will. Hooks before, beforeEach, afterEach, and after are the only places you'll be able to put cypress commands because of how Cypress must tie hooks + tests together.
I understand what you all are trying to do - getting access to the currentTest properties from inside of a hook. This data should already be available to you as cy.state('runnable').currentTest.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
That gets pretty much what I'd need, except I'm sending that test data to a service, which I have a node client for... I was making the request from within a Do you have an idea how I could accomplish this without using |
No. Use hooks and |
I'm confused by that answer - when I call a |
@drewbrend Brian means use |
This would be very helpful :) |
Unfortunately All tests and suites in the run do exist on the object but it's pretty ugly to navigate. I could seriously hack this by doing something like
But there can be multiple There's also the fact that you can't actually tell which test this All this to say:
|
For anyone that stumbles on this I ended up finding a decent way to handle parsing the tests from the
This is in const reportedTests: string[] = [];
function sendTestMetrics(test: Mocha.Test) {
if (test.pending || !test.state) {
// Test is either skipped or hasn't ran yet.
// We need to check this because all tests will show up in the hook every time
return;
}
reportedTests.push(test.fullTitle());
// parse some data from test and send it to an internal service
}
function sendSuite(suite: Mocha.Suite) {
suite.eachTest(test => {
if (!reportedTests.includes(test.fullTitle())) {
sendTestMetrics(test);
}
});
}
afterEach(() => {
const afterHook = cy.state("runnable");
if (afterHook.parent) {
sendSuite(afterHook.parent);
}
}); |
@drewbrend maybe a bit late, but as I can see you can reference the current test in afterEach(() => {
// @ts-ignore
const test = cy.state('runnable')?.ctx?.currentTest;
if (test) {
// stuffs here
}
}); |
@jennifer-shehane I want to implement the full capture of page when some failure happens. So I thought something like that:
But I cannot call any cypress command from events, as you said. How could I resolve it? |
Current behavior:
Attempting to fire
cy.task()
commands after a test completes appears to outright fail.Desired behavior:
At the end of each test, I would expect the
cy.task
command to fire, running a block of code within the task registered incypress/plugins/index.js
Steps to reproduce: (app code and test code)
Simple Test
In
cypress/support/index.js
I have the following event listener enabled:And that should fire this task in
cypress/plugins/index.js
:Through console logging I can tell that the
test:after:run
event listener is working, as console logs appear in the cypress runner's JS console. However console logs within the plugin task do not get written to my terminal.However, if I add a
cy.task
command DIRECTLY to my test like so:The task registered in the plugins file DOES catch the command and logs the faked details I pass it. Why is that same
cy.task
command not working in mytest:after:run
event listener?Versions
Cypress: 3.4.0
The text was updated successfully, but these errors were encountered: