0

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.

Florian Gössele
  • 4,376
  • 7
  • 25
  • 49
  • 1
    *"the local server did not start before running the tests"* - why did you expect that it *would*? Codecept's job is to run your tests, not your server. I'd suggest using something like [`concurrently`](https://www.npmjs.com/package/concurrently) to run the server and tests in parallel (a blog post I wrote on automation [here](https://blog.jonrshar.pe/2019/Feb/10/automation-for-the-people.html), with links to repos which have config you could reuse). Also note that, as the base URL is set, you could just do `I.amOnPage("/users");`. – jonrsharpe Feb 15 '19 at 17:18
  • I'm using `concurrently` now and it works fine, thank you! – Florian Gössele Feb 16 '19 at 09:16

0 Answers0