Open jordiponsllaurado opened 6 years ago
I think you mixed the beforeSuite with Background of gherkin. For feature file, you can only add Background which is literally beforeSuite when you develop non gherkin style. Please check this document https://codecept.io/bdd/#advanced-gherkin
But then this force you to repeat again the same code on all the Given statements, like if you want to go to a specific URL for all the tests. No?
Background in Cucumber is used to define a step or series of steps which are common to all the tests in the feature file. It allows you to add some context to the scenarios for a feature where it is defined. A Background is much like a scenario containing a number of steps. But it runs before each and every scenario where for a feature in which it is defined.
That's how thing go when you go with Gherkin.
Yes I know but what if I don't want to add a background on each feature, is it possible to not do it?
In Ruby for example is possible to create hooks so you don't need to
Here is a snippet from documentation:
// inside step_definitions
Before((test) => {
// perform your code
test.retries(3); // retry test 3 times
});
It throws the following exception:
Could not include object Step Definition from ./step_definitions/users.steps.js from module 'XXXX' Before is not defined
I understood what Background is a better way to organize steps. Here is my point:
Thanks.
I'm not really understanding much the bdd implementation but I think you could achieve this by using event listeners
For example
const event = require('codeceptjs').event;
module.exports = function() { event.dispatcher.on(event.all.before, function () { console.log('--- I am before all --'); // your pre-requisite steps goes here }); }
What are you trying to achieve?
I want to implemente a Before/BeforeSuite hook for all my tests
What do you get instead?
BeforeSuite is not defined
Details