I have the following acceptance test suite written using CodeceptJS and it is working fine. I am using Before
to log in before each of the steps. The problem is that the Before
function is equivalent to Mocha's beforeEach
, not Mocha's before
, and what I really want is to have some code just run once, as this login step takes some time to complete.
I hope to end up with a function that will run once and gets me a loginToken from javascript, and then I can use a Before
function to set this before each test that follows. Any clues on how to do this?
Feature('Top level-routes');
Before((I) => {
const loginBtnText = 'LOG IN';
I.amOnPage('/login');
I.fillField('username', 'root');
I.fillField('password', 'mypass');
I.see(loginBtnText);
I.seeElementInDOM('[name=loginBtn]');
I.click('loginBtn');
// I don't understand why I need to wait for the click to register
// but nothing happens unless I do ...
I.wait(1);
I.dontSee(loginBtnText);
});
Scenario('a page to add a new encounter should be rendered', (I) => {
I.amOnPage('/encounter/new');
I.wait(2);
I.see('First');
I.see('Last');
});
Scenario('a page to add a new user should be rendered', (I) => {
I.amOnPage('/user/new');
I.wait(2);
I.see('Personalia');
})
P.S. I do realize I can probably hack around this using some outer state to check if the function has run before, but haven't been able to do it yet. Props to the least hacky answer :)
You can have a Customized CodeceptJS helper, there you can make use of these following methods,
_init - before all tests, _before - before a test