diff --git a/README.md b/README.md index c93f861..86fbf62 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,22 @@ This will start a Firefox browser by default. Other browsers and profiles can be For example, if you want to start a Chrome Browser you can following the instructions provided [here](docs/chrome-behat.md). +### Running with stand-alone command + +If running with `silverstripe/serve` and `chromedriver`, you can also use the following command +which will automatically start and stop these services for individual tests. + + vendor/bin/behat-ss @framework + +This automates: + - starting server + - starting chromedriver + - running behat + - shutting down chromedriver + - shutting down server + +Make sure you set `SS_BASE_URL` to `http://localhost:8080` in `.env` + ## Tutorials * [Tutorial: Testing Form Submissions](docs/tutorial.md) diff --git a/bin/behat-ss b/bin/behat-ss new file mode 100755 index 0000000..0bbfc3f --- /dev/null +++ b/bin/behat-ss @@ -0,0 +1,20 @@ +#!/bin/sh +echo "setting up /artifacts" +mkdir -p artifacts + +echo "starting chromedriver" +chromedriver &> artifacts/chromedriver.log 2> artifacts/chromedriver-error.log & +cd_pid=$! + +echo "starting webserver" +vendor/bin/serve &> artifacts/serve.log 2> artifacts/serve-error.log & +ws_pid=$! + +echo "starting behat" +vendor/bin/behat "$@" + +echo "killing webserver (PID: $ws_pid)" +pkill -TERM -P $ws_pid &> /dev/null + +echo "killing chromedriver (PID: $cd_pid)" +kill -9 $cd_pid &> /dev/null diff --git a/composer.json b/composer.json index 13402dd..6151555 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,9 @@ "3.x-dev": "3.1.x-dev" } }, + "bin": [ + "bin/behat-ss" + ], "scripts": { "lint": "phpcs --standard=PSR2 -n src/ tests/php/" },