-
-
Notifications
You must be signed in to change notification settings - Fork 728
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
How to skip a test by Helper / hooks? #661
Comments
@zordius But now you can use You should place your test for different browsers in different files and add tags in |
Ya, we already adopt this practice, but the practice can just skip a test file and I am looking for a way to control test case more programmatically. Here are some possible designs:
|
Maybe using decorators to tag features and scenarios is a interesting solution. Other tags, such as the mentioned |
Hi,
And it skipped the test. |
I'm using this for skipping of scenario (e.g. when the scenario is unreliable in Firefox): if (require("codeceptjs").config.get().helpers.WebDriver.browse == "firefox") {
return;
} It's placed at the begin of |
I think we should create method like |
Where/How do you add this? I'm familiar with Page Objects and Helper (extend codeceptjs.helper) but I'm not yet familiar with building hooks. |
@ryaxc , you just need to register a script to define your hooks and capture events. Just add the following block to your
and, inside the
Hope that helps. But it would be nice to introduce a proper |
Consider this as a workaround as well:
It's a bit ugly to read, but it works as expected. |
@ngraf This is good and I prefer to this way :) |
Does anyone know how do I skip an entire feature/suite in codeceptjs? event.dispatcher.on(event.suite.before, async (suite) => { |
I guess just simply add xFeature then the whole Scenarios inside that feature would be skipped tho. |
Thanks for the answer..I'm trying to do it dynamically - in run time |
I wound up doing the following: In codecept.conf.jsexports.config = {
hooks: ["./hooks/ccjs-skip.js"],
}; In hooks/ccjs-skip.jsfunction decideSkip(tags) {
if (testTags.includes("@skip")) {
return true;
}
}
module.exports = function () {
event.dispatcher.on(event.test.before, function (test) {
const skipThisTest = decideSkip(test.tags);
if (skipThisTest) {
test.run = function skip() {
this.skip();
};
return;
}
});
}; Then for bdd feature files
And for test filesScenario("Do a test @skip", async ({ I }) => {
await I.doSomethingHere();
}); I've got some additional |
Hi,Thank you! |
Good to know! I hadn't yet started running multiple threads but that's a near-term goal. I've started dabbling with writing some custom helpers extending the built-ins (Playwright so far), I wonder if there's something with |
I tried using #661 (comment) for skipping of a Feature for a selected browser, but it works in |
@mirao which one does work in both modes? I'm a bit confused. You stated the same 661. |
I don't know if this is as good as @ngraf or how it would perform with the different run styles, but I have iterated to also use the following custom helper: const { output } = require("codeceptjs");
const Helper = codeceptjs.helper;
class SkipperHelper extends Helper {
_before(test) {
this.currentTest = test;
}
/**
* Who knows when you want to do something with the test
*
*/
getMyTest() {
return this.currentTest;
}
/**
* Usage:
* await I.skipTest();
* return;
* Or:
* return I.skipTest();
*
* Use the "return;" if adding a conditional execution above a block of code
* This code will not immediately interrupt the full test scenario and is
* ideally used only in code-based Scenario() instead of the BDD step
* definitions.
*/
async skipTest() {
try {
if (!this.currentTest.tags.includes("@skip")) {
this.currentTest.tags.push("@skip");
}
// eslint-disable-next-line func-name-matching
this.currentTest.run = function skip() {
this.currentTest.skip();
};
await this.currentTest.skip();
} catch (error) {
output.log("Working around non-programmatic skip: ", error);
}
}
}
module.exports = SkipperHelper; Then in exports.config = {
/* ... */
helpers: {
/* ... */
Skipper: {
require: "../ui/helpers/skipper.js",
},
/* ... */
},
/* ... */
}; Then in a /* import, injects, dotenv constants including APP_ENVIRONMENT import/assignment */
Scenario(
"Execute a test @someRelevantTag",
async () => {
if (!APP_ENVIRONMENT.includes("staging")) {
await I.say(`Skipping test. Being executed on environment other than staging [${APP_ENVIRONMENT}]`);
return I.skipTest();
}
/* do some testing if not staging */
}
); |
What are you trying to achieve?
I try to create a helper to help me to skip some test cases for specific browser, but I can not find document about how to skip a test case. Any suggestion?
So far I can use beforeStep (step) to know what's the next step and the arguments, but I don't know how to skip the step (or all the steps) . <= this maybe anoterh way to help me skip "all steps in a test case" , not so good but may work.
Or, refer to Add a way of a programmatically skipping a test mochajs/mocha#1901 , is there any similiar api in codeceptjs?
The text was updated successfully, but these errors were encountered: