End to End testing with Selenium on NodeJS
For my latest project I needed to add end to end tests to an Express/React application. The requirements were pretty straight-forward:
- The tests should be easy to setup and run.
- The tests should be able to run both on a desktop browser and on a headless environment.
- selenium-standalone takes care of installing and starting a selenium server for you.
The last piece of the puzzle was choosing a test framework, and getting both the selenium server and my app running before the test suite.
So, I went with Jasmine for the test framework (mostly because I was already familiar with it) and I wrote the following script for getting my tests running:
Now anyone can run the test suite with a simple
npm install &
Note the script will start both a selenium server and an instance of your app, but you can also pass in
TEST_WEB_SERVERas environment variables if you prefer to use your own.
You can take a look at the complete example here: https://github.com/alexishevia/blogExamples/tree/e2e_node