This project demonstrates how to test a website with only NodeJS, Selenium, Protractor and WebdriverIO using Cucumber or Mocha/Chai. Depending on your needs this project can serve as just a reference or a tutorial on how to setup automated testing.
You can run tests against different browsers locally or remote using Browserstack even in parallel.
To make it all a bit more challenging, the demo-test site is protected with Basic Authentication :)
Checkout this article for an in-depth discussion plus examples of how to run all this code.
To start the demo-site you will need docker! Docker is awesome and it will only take you three commands to get our site up and running
$> docker network create my-test-network
$> docker run -d --network=my-test-network --name web dockercloud/hello-world
$> docker run -d -p 80:80 --network=my-test-network --name auth beevelop/nginx-basic-auth
or just one if docker-compose
is used
$> docker-compose up -d
or simply do
$> yarn serve
The demo site can be accessed via http://localhost
with username foo
and password bar
.
When you're done testing make sure to clean up
$> yarn cleanup // Stop and remove all docker containers
$> docker rmi $(docker images -q) // Remove all docker images
Run the following command to install all node dependencies
$> yarn install
Running tests on your laptop or pc will not just work out of the box, but you have a couple of options to fix that.
You can use the browser-drivers directly
Put the drivers in the root of this project. Using the geckodriver
was for me the only way to test
locally with firefox.
The second way is with the selenium standalone server, which can be started as follows
$> yarn selenium
And the third way is a combination of both combined in a docker image
$> docker run -p 127.0.0.1:4444:4444 selenium/standalone-chrome:latest
or
$> docker run -p 127.0.0.1:4444:4444 selenium/standalone-firefox:latest
It's like headless testing, all made possible thanks to XVFB.
If you don't have a Browserstack account yet you can sign-up for free.
This will give you access to endless time of testing fun. To run these automated tests you will need the automation credentials,
which can be found here: Account -> Settings
at the bottom of the page!
Because the demo site is running locally, you have to enable Local Testing
on Browserstack first. Finally, download the BrowserStackLocal
binary and run it
$> ./BrowserStackLocal --key <access-key>
As you can see at the top of this README, Browserstack has a badge, which is nice and it informs you about the status of your tests. If a test session fails, the badge will become red. Which is a good thing of course. However, it will remain red forever until you remove the failed session or you update the session and pass it yourself.
So, a test-run on browserstack is called a session, which are grouped in a build and builds belong to a project. A badge belongs to a project and sessions can pass or fail.
Now, with all that in place, lets checkout the tasks available:
To remove a project with all its builds and session simply do
$> ./tasks/clean-browserstack-project --browserstack-user <user> --browserstack-key <access-key> [--project project name]
but you can also update/delete failing sessions within a project
$> ./tasks/process-failed-sessions --browserstack-user <user> --browserstack-key <key> [--project project name]
If you would like a badge for a project do
$> ./tasks/badge.js --browserstack-user <user> --browserstack-key <key> [--project project name]
it will output the badge code in Markdown and HTML.
- Firefox doesn't work with the selenium standalone server