We want to implement some basic E2E tests in our Angular 7 application with codeceptJS Nightmare. The tests should be part of the CI pipeline. I followed the docs and set up a basicTest.e2e.js:
Feature('Basic');
Scenario('test if Users header appears', (I) => {
I.amOnPage('http://localhost:4200/users');
I.see('Users', 'h1');
});
as well as a codecept.json:
{
"tests": "./e2e/*.e2e.js",
"timeout": 10000,
"output": "./_tmptest",
"helpers": {
"Nightmare": {
"url": "http://localhost",
"show": false,
"restart": false
}
}
}
and execute it with codeceptjs run --steps
. However, this leads to an error:
CodeceptJS v1.3.2
Basic --
test if Users header appears
I am on page "http://localhost:4200/users"
✖ FAILED in 465ms
-- FAILURES:
1) Basic
test if Users header appears:
navigation error
Scenario Steps:
- I.amOnPage("http://localhost:4200/users") at Object.obj.(anonymous function).obj.(anonymous function) [as amOnPage] (node_modules/codeceptjs-nightmare/node_modules/codeceptjs/lib/actor.js:28:26)
Run with --verbose flag to see NodeJS stacktrace
FAIL | 0 passed, 1 failed // 1s
Executing the command with ng serve
running in another console works:
CodeceptJS v1.3.2
Basic --
test if Users header appears
I am on page "http://localhost:4200/users"
I see "Users", "h1"
✓ OK in 2173ms
so obviously the local server did not start before running the tests. I could not find a way to configure a codecept startup command, e.g. npm's http-server (as the project is already compiled at this point in the pipeline) in codecept.json.
Is there a way to start a local server, then run Codecept-Nightmare E2E-Tests and terminate the server afterwards?
I would also accept a hacky (scripting) solution (e.g. in package.json) as ng serve && codeceptjs run --steps
does obviously not work.