Commit f0ec398e authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh
Browse files

helper script for one-liner testing

parent c7ca1f17
......@@ -25,3 +25,4 @@ beat/web/static/
doc/api/api/
html/
*.tar.bz2
nohup.out
# End-to-End Testing with Protractor
[Protractor](http://www.protractortest.org/#/) is an e2e (end-to-end) testing tool for web apps. Protractor runs tests through Selenium using a real browser, and as such needs a headed environment and a compatible browser installed.
NOTE: Protractor will open a new browser window in the foreground when it is started.
## Setup
Currently, testing the BEAT web platform with Protractor requires additional setup after successfully setting up the project locally:
......@@ -14,17 +16,31 @@ Currently, testing the BEAT web platform with Protractor requires additional set
./parts/buildout-node/node-*/bin/webdriver-manager update
```
## Running tests with the provided script
The `protractor.sh` script is a one-liner to run Protractor tests. It handles database creation/saving/restoring and manages the required local server processes. However, it assumes several things:
- It is being ran in the top directory of the `beat.web` repository
- The repository has already ran `./bin/buildout` successfully and with default development configuration
- Protractor's `.conf` file is `./protractor-conf.js`
- Default (no) additional arguments passed to `webdriver-manager` or Django `runserver`
- Django uses `./django.sql3` as the database
- If `./django.sql3` does not exist, the default database generated by `./bin/django install` is sufficient for testing
## Manual test running
If the `protractor.sh` script won't work, one can test manually.
The `webdriver-manager` must be running while testing. To run tests using a local BEAT web server, you must have the BEAT web server up as well.
### Starting the webdriver server
- Start the webdriver server in a separate shell (or append ` &` to run it as a background process in the current shell):
```sh
./parts/buildout-node/node-*/bin/webdriver-manager start
```
NOTE: You may only have 1 webdriver manager running at once.
- After the webdriver finishes initialization, you can run tests (*WARNING*: Protractor will open a new browser window in the foreground):
- After the webdriver finishes initialization, you can run tests:
```sh
./parts/buildout-node/node-*/bin/protractor protractor-conf.js
```
NOTE: To run tests using a local BEAT web server, you must have the web server running while Protractor executes tests.
- If you started your webdriver server as a background process, you can kill all webdriver processes:
```sh
......
###############################################################################
# e2e testing helper script
# Preconditions:
# - Ran in the top directory of the `beat.web` repository
# - `Buildout` has already been ran successfully
# - Default development environment configurations
# - $SHELL is BASH or ZSH
# Postconditions:
# - `nohup.out` file will exist in top directory
# - If there was not a `django.sql3` db file, there will be one
#
# SUGGESTION: The vast majority of the time is spent generating a fresh db via
# `./bin/django install`. You may have a file named `template.django.sql3`
# in the top dir that will be copied and used as the initial db to massively
# speed up testing.
###############################################################################
# make sure the beat web server and web manager arent running already
if [ $(ps aux | grep -c 'django runserver') -gt 1 ]
then
echo 'The BEAT web server is already running locally, aborting...'
exit -1
fi
if [ $(ps aux | grep -c 'webdriver-manager start') -gt 1 ]
then
echo 'The webdriver-manager is already running locally, aborting...'
exit -1
fi
# if db already exists, save it
if [ -a django.sql3 ]
then
echo 'Found existing django database,' \
'saving it to "old.django.sql3" and generating a fresh one...'
mv django.sql3 old.django.sql3
fi
# Either use a template db...
if [ -a template.django.sql3 ]
then
echo 'Found template django database, copying it...'
cp template.django.sql3 django.sql3
else
# ...or generate a new one
echo 'Found no template db ("template.django.sql3"),' \
'generating a new db....'
./bin/django install
fi
# run the web server
beat_cmd='./bin/django runserver'
# spin up web manager
webdriver_cmd='./parts/buildout-node/node-*/bin/webdriver-manager start'
# run tests
protractor_cmd='./parts/buildout-node/node-*/bin/protractor ./protractor-conf.js'
# start bg processes
echo 'Output from the BEAT web server &' \
'the Protractor webdriver-manager will be found in nohup.out'
nohup $beat_cmd &
beat_pid=$!
nohup $webdriver_cmd &
webdriver_pid=$!
# couple seconds to let them set up
sleep 2
echo 'Running Protractor....'
echo '----------------'
# run tests
$protractor_cmd
echo '----------------'
# if we saved a db, restore it
if [ -a old.django.sql3 ]
then
echo 'restoring old database...'
mv old.django.sql3 django.sql3
fi
# clean up any type of exit
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment