-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add BeforeStep / AfterStep hooks #997
Comments
@charlierudolph I would like to help here, but need some pointer on the appropriate way implement it. I believe there was syntactic sugar AfterStep for registerHandler which was removed recently. I looked at support_code_library_builder/define_helpers.js. But need some pointers on how to implement these hooks. |
A question here though is how does this effect the workflow? Can this edit the step result status or does it act as another step that can pass / fail? |
The use case that I have seen in one of the comments and which I also want to use is to create a screenshot after the step. In cucumber ruby I have used the AfterStep which provides access to the Scenario object. |
@charlierudolph I'm looking for a similar solution as well.
Now I don't have solution for this. |
Hi, I have seen in most threads i read regarding BeforeStep/AfterStep hook that the use-case is taking a printscreen. This is not my use-case and I just want to voice other use cases for these hooks: My project have used this.AfterStep hook in cucumber 1.x for:
All external links are then tested in a separate test-suit.
Currently using Cucumber 4.0.0 and Protractor 4.0.14 Side-note: Our use cases did not work properly with this.AfterStep() in Cucumber 1.x.x because it was not designed to have this type of code in it and we saw problems with race-conditions. So we have upgraded to Cucumber 4.0.0 and disabled AfterStep logic until there is proper support for it. |
Hi, any updates regarding this before/after step hooks? "attach" is not available for me because we have overridden the default World constructor https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md Thnx |
Hi @gajo4256, I'm using cucumber 4.0.0 and this snippet:
This will take a screenshot after every failed scenario. ( It works for me, because with cucumber, whenever a step fail, the whole scenario will fail, so it is almost identical with "after step fail". Hope it helps. |
Hi @mracz, thnx, I actually tried this (although after each step would it would be more suitable for me). Thnx |
Hi @gajo4256, This is what i have in my Custom world implementation:
|
@mracz, I currently do this for each step: When('I do something', function () {
return takeScreenshot(this, () => {
return $(...).click();
});
}); Where the screenshot taking function is this: export function takeScreenshot(world, stepToExecute: () => promise.Promise<any>): promise.Promise<any> {
return stepToExecute().then(() => {
return doTakeScreenshot(world);
}).catch((err) => {
return doTakeScreenshot(world).then(() => {
throw err;
});
});
}
function doTakeScreenshot(world) {
return browser.takeScreenshot().then((screenshot) => {
world.attach(screenshot, 'image/png');
}).catch((err) => {
console.warn('Could not create screenshot', err);
});
} I may have been too defensive about exceptions, but I did my best that the extra code does not interfere with the real test results. Best I can do right now, a working However, what the hook would probably not do is skipping screenshots when I'm making assertions that do not change the screen (thus the screenshot would be useless), e.g. |
Hello everyone. We are looking for a way to take screenshot from all our different steps. Don't know if it is the best possible way so please, don't hesitate to give your opinion about it ! |
For anyone struggling here's a way to do this with definition function wrapper: https://github.com/PeerioTechnologies/peerio-icebear/blob/dev/test/e2e/code/hooks.js#L28 |
Our main use case would be like others here: screenshots, but using it as more of a debugging tool so that we can see the output of each step if we turn on debugging mode in our configuration. Another use: we have a few modals that may appear after certain lengths of time on our website. If we run through a scenario, we would want to have checks in place for those modals being on the page after every step to ensure our tests aren't fragile because of these modals. Another use case: if someone wanted to create a reporting tool complete with dashboard (currently running test statuses, test cases that have been previously ran, etc), cucumber could post to the tool in the step hooks for an update on progress. It's an unusual example, I know, but it's something that I'm interested in looking into now that I've thought about it. |
KyleFairns, I need AfterStep for dashboard as you mentioned |
Hello, We want to check if there is any javascript error after each step. Not only the failed steps. |
I just discovered that WebDriverIO has beforeStep and afterStep hooks for cucumber which solves my problem. Hope that helps... |
Hi All, Any update on Step hooks? Or any work around for running some code before and/or after each step execution? |
Hi all, |
No updates. Still waiting for someone to submit a pull request for this. |
Is there any roadmap or anything to this? As this is one major painpoint to have this feature, maybe an official statement would be nice. @aslakhellesoy is there a checklist or something what a pull-request needs to implement? AFAIK #1058 and #1121 try to bring this feature, or some ways to workaround. |
Hey guys, |
@aslakhellesoy, I've created the above PR (#1198) to address this issue/feature request. Can you please take a look at it, or point me to someone I should contact? |
any updates? looking forward to have it as well :) |
@charlierudolph do you have a view on whether the functions registered against Like a few others here, I'm using |
I would expect that BeforeStep / AfterStep will run no matter what regardless of whether a step passes / fails (due to a timeout or otherwise) |
Just to add an additional use case to this which is not about screenshots. I am testing an event driven system and the tests cause events to be generated. Those events are then read and create changes to the system. The steps which follow validate the system is in the expected state which requires all events to have been processed. I would like the ability to ensure the queue has been fully processed and there is nothing in pending state before moving to the next step. Currently I am doing some polling of the event stream in validation steps, but it would be nice to just put it into a hook. As it is a ubiquitous requirement that the system is stable state before going to next step. |
@davidjgoss @charlierudolph Please can you help me with a sample example code of setDefinitionFunctionWrapper for to achieve the screenshots thing BeforeStep/AfterStep?, I am trying with Nightwatch JS |
Hi @RArkasali here's a snippet from a project I work on: import {setDefinitionFunctionWrapper} from "cucumber";
setDefinitionFunctionWrapper(function(fn) {
return async function(...args) {
try {
return await fn.apply(this, args);
} catch (ex) {
await this.takeScreenshot();
throw ex;
}
};
}); (Where So this will take a screenshot if there is an error (like an assertion failure) from within the step function. The fact that we return the result of a non-error one is important - I was confused for a while while a step with Hope this helps |
Hi all, |
This has been added as apart of #1416 |
Closing this issues since the hooks have been added in #1416 |
Useful for validations after every step ends.
this
should be the world instanceThe text was updated successfully, but these errors were encountered: