mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
DOC Update docs to reflect changes in CLI interaction (#282)
This commit is contained in:
parent
4c1654d63a
commit
975ff8dd81
@ -1,16 +1,16 @@
|
|||||||
#Setting up CircleCI and Behat
|
#Setting up CircleCI and Behat
|
||||||
If you'd like to run SilverStripe Behat tests on CircleCI, this can be achieved (along with screenshot artifacts on
|
If you'd like to run SilverStripe Behat tests on CircleCI, this can be achieved (along with screenshot artifacts on
|
||||||
error) reasonably easily.
|
error) reasonably easily.
|
||||||
|
|
||||||
The below extract is a full `circle.yml` configuration file that gets the environment setup and running for Behat tests.
|
The below extract is a full `circle.yml` configuration file that gets the environment setup and running for Behat tests.
|
||||||
Please review it thoroughly as there are a few things you'll need to change for your individual project. Notably:
|
Please review it thoroughly as there are a few things you'll need to change for your individual project. Notably:
|
||||||
|
|
||||||
* If you already have a behat.yml, you should ensure your local requirements are reflected as the following script will
|
* If you already have a behat.yml, you should ensure your local requirements are reflected as the following script will
|
||||||
overwrite the behat.yml file in order to ensure screenshot failures are stored in a CircleCI-appropriate directory,
|
overwrite the behat.yml file in order to ensure screenshot failures are stored in a CircleCI-appropriate directory,
|
||||||
even if you don't store screenshots locally.
|
even if you don't store screenshots locally.
|
||||||
* There is one variable required below (`REPO-NAME`) that you need to fill out yourself depending on the name of your
|
* There is one variable required below (`REPO-NAME`) that you need to fill out yourself depending on the name of your
|
||||||
repository (CircleCI will check out your code into a sub-directory of the user's homedir based on the repository name).
|
repository (CircleCI will check out your code into a sub-directory of the user's homedir based on the repository name).
|
||||||
* This assumes your Behat fixtures are located under the mysite/ directory. If not, check the `test.override` section
|
* This assumes your Behat fixtures are located under the mysite/ directory. If not, check the `test.override` section
|
||||||
below.
|
below.
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -23,17 +23,17 @@ dependencies:
|
|||||||
- ~/.composer/cache
|
- ~/.composer/cache
|
||||||
|
|
||||||
pre:
|
pre:
|
||||||
# Enable xdebug - this is for code coverage and may not be necessary for you. Remove if you don't need it, it can
|
# Enable xdebug - this is for code coverage and may not be necessary for you. Remove if you don't need it, it can
|
||||||
# drastically slow down tests
|
# drastically slow down tests
|
||||||
- sed -i 's/^;//' ~/.phpenv/versions/$(phpenv global)/etc/conf.d/xdebug.ini
|
- sed -i 's/^;//' ~/.phpenv/versions/$(phpenv global)/etc/conf.d/xdebug.ini
|
||||||
|
|
||||||
# We found that some machines have outdated composer versions, so we self-update before running install just in case
|
# We found that some machines have outdated composer versions, so we self-update before running install just in case
|
||||||
- sudo composer self-update
|
- sudo composer self-update
|
||||||
- composer install --prefer-source --no-interaction
|
- composer install --prefer-source --no-interaction
|
||||||
|
|
||||||
# Behat and SilverStripe often require a reasonably large amount of memory, tune to your specific needs
|
# Behat and SilverStripe often require a reasonably large amount of memory, tune to your specific needs
|
||||||
- echo "memory_limit = 512M" > ~/.phpenv/versions/$(phpenv global)/etc/conf.d/memory.ini
|
- echo "memory_limit = 512M" > ~/.phpenv/versions/$(phpenv global)/etc/conf.d/memory.ini
|
||||||
|
|
||||||
# Setup the _ss_environment.php file per https://docs.silverstripe.org/en/3.4/getting_started/environment_management
|
# Setup the _ss_environment.php file per https://docs.silverstripe.org/en/3.4/getting_started/environment_management
|
||||||
- |
|
- |
|
||||||
cat << 'EOF' > _ss_environment.php
|
cat << 'EOF' > _ss_environment.php
|
||||||
@ -43,7 +43,7 @@ dependencies:
|
|||||||
define('SS_DATABASE_USERNAME', 'ubuntu');
|
define('SS_DATABASE_USERNAME', 'ubuntu');
|
||||||
define('SS_DATABASE_PASSWORD', '');
|
define('SS_DATABASE_PASSWORD', '');
|
||||||
define('SS_ENVIRONMENT_TYPE', 'dev');
|
define('SS_ENVIRONMENT_TYPE', 'dev');
|
||||||
|
|
||||||
global $_FILE_TO_URL_MAPPING;
|
global $_FILE_TO_URL_MAPPING;
|
||||||
$_FILE_TO_URL_MAPPING['/home/ubuntu/REPO-NAME'] = 'http://localhost:8080/';
|
$_FILE_TO_URL_MAPPING['/home/ubuntu/REPO-NAME'] = 'http://localhost:8080/';
|
||||||
EOF
|
EOF
|
||||||
@ -69,7 +69,7 @@ dependencies:
|
|||||||
- a2enmod rewrite
|
- a2enmod rewrite
|
||||||
- sudo service apache2 restart
|
- sudo service apache2 restart
|
||||||
|
|
||||||
# Get Selenium setup - we currently do this everytime but ideally we could store in the cache_directories and only
|
# Get Selenium setup - we currently do this everytime but ideally we could store in the cache_directories and only
|
||||||
# grab if it doesn't exist to save time - an exercise left to the reader!
|
# grab if it doesn't exist to save time - an exercise left to the reader!
|
||||||
- wget http://selenium-release.storage.googleapis.com/2.52/selenium-server-standalone-2.52.0.jar
|
- wget http://selenium-release.storage.googleapis.com/2.52/selenium-server-standalone-2.52.0.jar
|
||||||
- 'java -jar selenium-server-standalone-2.52.0.jar > /dev/null 2>&1':
|
- 'java -jar selenium-server-standalone-2.52.0.jar > /dev/null 2>&1':
|
||||||
@ -85,7 +85,7 @@ dependencies:
|
|||||||
|
|
||||||
# Create assets directory and add group perms
|
# Create assets directory and add group perms
|
||||||
- if [ ! -d assets ]; then mkdir assets && chmod 777 assets; fi
|
- if [ ! -d assets ]; then mkdir assets && chmod 777 assets; fi
|
||||||
|
|
||||||
# Setup behat.yml - you will need to merge your current behat.yml into this configuration
|
# Setup behat.yml - you will need to merge your current behat.yml into this configuration
|
||||||
- |
|
- |
|
||||||
cat > behat.yml <<EOF
|
cat > behat.yml <<EOF
|
||||||
@ -110,14 +110,14 @@ dependencies:
|
|||||||
browser: firefox
|
browser: firefox
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Create database via dev/build
|
# Create database and flush cache
|
||||||
- framework/sake dev/build flush=1
|
- sake db:build --flush
|
||||||
|
|
||||||
test:
|
test:
|
||||||
override:
|
override:
|
||||||
# We override the CircleCI defaults to run both PHPUnit and Behat tests
|
# We override the CircleCI defaults to run both PHPUnit and Behat tests
|
||||||
- vendor/bin/phpunit
|
- vendor/bin/phpunit
|
||||||
|
|
||||||
# You may need to change the @mysite below to the name of your Behat test base
|
# You may need to change the @mysite below to the name of your Behat test base
|
||||||
- vendor/bin/behat --verbose --out=null,$CIRCLE_ARTIFACTS/_behat_results/framework.html,$CIRCLE_ARTIFACTS/_behat_results --format=pretty,html,junit @mysite --tags="~@todo"
|
- vendor/bin/behat --verbose --out=null,$CIRCLE_ARTIFACTS/_behat_results/framework.html,$CIRCLE_ARTIFACTS/_behat_results --format=pretty,html,junit @mysite --tags="~@todo"
|
||||||
```
|
```
|
||||||
|
@ -22,7 +22,7 @@ and ensure it runs on your environment. Detailed installation instructions
|
|||||||
can be found in the [README](../README.md) of this module.
|
can be found in the [README](../README.md) of this module.
|
||||||
Once you've got the SilverStripe project running, make sure you've
|
Once you've got the SilverStripe project running, make sure you've
|
||||||
started ChromeDriver. With all configuration in place, initialise Behat
|
started ChromeDriver. With all configuration in place, initialise Behat
|
||||||
for
|
for
|
||||||
|
|
||||||
vendor/bin/behat --init @mysite
|
vendor/bin/behat --init @mysite
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ file since it reuses the one in the root folder.
|
|||||||
One major goal for "testing by example" through Behat is bringing
|
One major goal for "testing by example" through Behat is bringing
|
||||||
the tests closer to the whole team, by making them part of the agile
|
the tests closer to the whole team, by making them part of the agile
|
||||||
process and ideally have the customer write some tests in his own
|
process and ideally have the customer write some tests in his own
|
||||||
language (read more about this concept at
|
language (read more about this concept at
|
||||||
[dannorth.net](http://dannorth.net/whats-in-a-story/)).
|
[dannorth.net](http://dannorth.net/whats-in-a-story/)).
|
||||||
|
|
||||||
In this spirit, we'll start "from the outside in", and
|
In this spirit, we'll start "from the outside in", and
|
||||||
@ -58,7 +58,7 @@ Feature: Report Abuse
|
|||||||
Then I should see "Thanks for your submission"
|
Then I should see "Thanks for your submission"
|
||||||
```
|
```
|
||||||
|
|
||||||
The "syntax" conventions used here are called the
|
The "syntax" conventions used here are called the
|
||||||
["Gherkin" language](https://github.com/cucumber/cucumber/wiki/Gherkin).
|
["Gherkin" language](https://github.com/cucumber/cucumber/wiki/Gherkin).
|
||||||
It is fairly free-form, with only few rules about indentation and
|
It is fairly free-form, with only few rules about indentation and
|
||||||
keywords such as `Feature:`, `Scenario:` or `Given`.
|
keywords such as `Feature:`, `Scenario:` or `Given`.
|
||||||
@ -181,8 +181,8 @@ by placing it at the bottom of `themes/simple/templates/Layout/Page.ss`:
|
|||||||
```
|
```
|
||||||
|
|
||||||
You can try out this feature in your browser without Behat.
|
You can try out this feature in your browser without Behat.
|
||||||
Don't forget to rebuild the database (`dev/build`) and flush the
|
Don't forget to rebuild the database and flush the
|
||||||
template cache (`?flush=all`) first though. If its all looking good,
|
template cache (`sake db:build --flush`) first though. If its all looking good,
|
||||||
kick off another Behat run - it should pass now.
|
kick off another Behat run - it should pass now.
|
||||||
|
|
||||||
vendor/bin/behat @mysite
|
vendor/bin/behat @mysite
|
||||||
@ -190,7 +190,7 @@ kick off another Behat run - it should pass now.
|
|||||||
## Custom Step Definitions
|
## Custom Step Definitions
|
||||||
|
|
||||||
Can you see the flaw in our test? We haven't actually checked that a report record
|
Can you see the flaw in our test? We haven't actually checked that a report record
|
||||||
has been written, just that the user received a nice message after the form
|
has been written, just that the user received a nice message after the form
|
||||||
submission. In order to check this, we'll need to write some custom step
|
submission. In order to check this, we'll need to write some custom step
|
||||||
definitions. This is where the SilverStripe extension to Behat comes in
|
definitions. This is where the SilverStripe extension to Behat comes in
|
||||||
handy, since you're already connected to the same test database in Behat
|
handy, since you're already connected to the same test database in Behat
|
||||||
@ -220,8 +220,8 @@ public function thereShouldBeAnAbuseReportForWithReason($arg1, $arg2)
|
|||||||
```
|
```
|
||||||
|
|
||||||
This code can be placed in a "context" class which was created during our
|
This code can be placed in a "context" class which was created during our
|
||||||
module initialization. Its located in
|
module initialization. Its located in
|
||||||
`mysite/tests/behat/features/bootstrap/Context/FeatureContext.php`.
|
`mysite/tests/behat/features/bootstrap/Context/FeatureContext.php`.
|
||||||
The actual step implementation can vary quite a bit, and usually involves
|
The actual step implementation can vary quite a bit, and usually involves
|
||||||
triggering a browser action like clicking a button, or inspecting the
|
triggering a browser action like clicking a button, or inspecting the
|
||||||
current browser state, e.g. check that a button is visible.
|
current browser state, e.g. check that a button is visible.
|
||||||
|
@ -691,7 +691,7 @@ class FixtureContext implements Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an extension and runs dev/build?flush
|
* Adds an extension and visits /dev/build?flush
|
||||||
*
|
*
|
||||||
* @param $extension
|
* @param $extension
|
||||||
* @param $class
|
* @param $class
|
||||||
@ -704,7 +704,7 @@ class FixtureContext implements Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an extension, but doesn't run dev/build afterwards. Will still run ?flush
|
* Adds an extension, but doesn't visit /dev/build afterwards. Will still run ?flush
|
||||||
*
|
*
|
||||||
* @param $extension
|
* @param $extension
|
||||||
* @param $class
|
* @param $class
|
||||||
|
Loading…
Reference in New Issue
Block a user