Newbie to Selenium E2E with React Newbie to Selenium E2E with React selenium selenium

Newbie to Selenium E2E with React


Well, since you didn't find the time to update the question information with the NPM "scripts" object, then I'll try to give it a shot in the dark.

First of all, due to your wording, I can interpret your question two ways:

  • a.) you want to run your E2E tests separately, w/o your server running (which is started via npm start);
  • b.) you want to run your E2E tests via npm start, without triggering your server from starting;

a.) If you want to run your scripts separately, seeing as you are using Mocha, then you can trigger them via: ./node_modules/.bin/mocha <pathToTests>/<testFile>.

Now, since you stated in your question that you're using npm test script, then that should be the best switch to bind your E2E tests execution to:

package.json (Scripts object):

"scripts": {    "test": "mocha --reporter spec <pathToTests>/<testFile>",    "start": "node <yourServerName>.js"},

Please note that mocha <pathToTests>/<testFile> is equivalent to ./node_modules/.bin/mocha <pathToTests>/<testFile>, because NPM looks for binaries inside node_modules/.bin and when Mocha was installed, it installed it into this directory.

Note: Many packages have a bin, or .bin section, declaring scripts that can be called from NPM similar to Mocha. If you want to find out what other binaries you can run that way, just issue a ls node_modules/.bin.


b.) In this care, I think your issue might be due to NPM defaulting some script values based on package contents. Specifically, if you have a server.js file in the root of your package, then npm will default the start command to server.js.

So if you're starting your E2E tests via npm start, having this ("start": "mocha <pathToTests>/<testFile>") in your package.json and there is a server.js file in the root of your package, then npm will default the start command to node server.js.

In which case, you could either move your server script to another place in the project, or change the switch you're using to trigger the E2E tests (see section b.)).

Hope this solves your problem and if not, looking forward for that package.json "scripts" object so we can really see what's up. :)

Cheers!