mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-09-28 20:29:36 +02:00
DOC Update README.md for CMS 5
This commit is contained in:
parent
003745750e
commit
099fd6cd13
80
README.md
80
README.md
@ -38,27 +38,21 @@ Note: The extension has only been tested with the `selenium2` Mink driver.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Simply [install Silverstripe through Composer](http://doc.silverstripe.org/framework/en/installation/composer).
|
In a Silverstripe CMS project (see [getting started docs](https://docs.silverstripe.org/en/getting_started/)) add the Silverstripe Behat extension via Composer.
|
||||||
Skip this step if adding the module to an existing project.
|
|
||||||
|
|
||||||
composer create-project silverstripe/installer my-test-project 4.x-dev
|
```sh
|
||||||
|
|
||||||
Switch to the newly created webroot, and add the Silverstripe Behat extension.
|
|
||||||
|
|
||||||
cd my-test-project
|
|
||||||
composer require --dev silverstripe/behat-extension
|
composer require --dev silverstripe/behat-extension
|
||||||
|
```
|
||||||
|
|
||||||
Download the standalone [Google Chrome WebDriver](http://chromedriver.storage.googleapis.com/index.html?path=2.8/)
|
Download the standalone [Google Chrome WebDriver](https://chromedriver.storage.googleapis.com/index.html)
|
||||||
|
|
||||||
Now install the Silverstripe project as usual by opening it in a browser and following the instructions.
|
|
||||||
Protip: You can skip this step by using `[SS_DATABASE_CHOOSE_NAME]` in a global
|
|
||||||
[`.env`](https://docs.silverstripe.org/en/getting_started/environment_management/) file one level above the webroot.
|
|
||||||
|
|
||||||
Unless you have [`SS_BASE_URL`](http://doc.silverstripe.org/framework/en/topics/commandline#configuration) set up,
|
Unless you have [`SS_BASE_URL`](http://doc.silverstripe.org/framework/en/topics/commandline#configuration) set up,
|
||||||
you also need to specify the URL for your webroot. Either add it to the existing `behat.yml` configuration file
|
you also need to specify the URL for your webroot. Either add it to the existing `behat.yml` configuration file
|
||||||
in your project root, or set is as an environment variable in your terminal session:
|
in your project root, or set is as an environment variable in your terminal session:
|
||||||
|
|
||||||
|
```sh
|
||||||
export BEHAT_PARAMS="extensions[SilverStripe\BehatExtension\MinkExtension][base_url]=http://localhost/"
|
export BEHAT_PARAMS="extensions[SilverStripe\BehatExtension\MinkExtension][base_url]=http://localhost/"
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -66,17 +60,23 @@ in your project root, or set is as an environment variable in your terminal sess
|
|||||||
|
|
||||||
You can run the server locally in a separate Terminal session:
|
You can run the server locally in a separate Terminal session:
|
||||||
|
|
||||||
|
```sh
|
||||||
chromedriver
|
chromedriver
|
||||||
|
```
|
||||||
|
|
||||||
### Running the Tests
|
### Running the Tests
|
||||||
|
|
||||||
Now you can run the tests (for example for the `framework` module):
|
Now you can run the tests (for example for the `framework` module):
|
||||||
|
|
||||||
|
```sh
|
||||||
vendor/bin/behat @framework
|
vendor/bin/behat @framework
|
||||||
|
```
|
||||||
|
|
||||||
Or even run a single scenario by it's name (supports regular expressions):
|
Or even run a single scenario by it's name (supports regular expressions):
|
||||||
|
|
||||||
|
```sh
|
||||||
vendor/bin/behat --name 'My scenario title' @framework
|
vendor/bin/behat --name 'My scenario title' @framework
|
||||||
|
```
|
||||||
|
|
||||||
This will start a Chrome browser by default. Other browsers and profiles can be configured in `behat.yml`.
|
This will start a Chrome browser by default. Other browsers and profiles can be configured in `behat.yml`.
|
||||||
|
|
||||||
@ -85,7 +85,9 @@ This will start a Chrome browser by default. Other browsers and profiles can be
|
|||||||
If running with `silverstripe/serve` and `chromedriver`, you can also use the following 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.
|
which will automatically start and stop these services for individual tests.
|
||||||
|
|
||||||
|
```sh
|
||||||
vendor/bin/behat-ss @framework
|
vendor/bin/behat-ss @framework
|
||||||
|
```
|
||||||
|
|
||||||
This automates:
|
This automates:
|
||||||
- starting server
|
- starting server
|
||||||
@ -128,11 +130,12 @@ number that failed.
|
|||||||
|
|
||||||
Example: behat.yml
|
Example: behat.yml
|
||||||
|
|
||||||
|
```yml
|
||||||
default:
|
default:
|
||||||
suites:
|
suites:
|
||||||
framework:
|
framework:
|
||||||
paths:
|
paths:
|
||||||
- %paths.modules.framework%/tests/behat/features
|
- '%paths.modules.framework%/tests/behat/features'
|
||||||
contexts:
|
contexts:
|
||||||
- SilverStripe\Framework\Tests\Behaviour\FeatureContext
|
- SilverStripe\Framework\Tests\Behaviour\FeatureContext
|
||||||
- SilverStripe\Framework\Tests\Behaviour\CmsFormsContext
|
- SilverStripe\Framework\Tests\Behaviour\CmsFormsContext
|
||||||
@ -142,7 +145,7 @@ Example: behat.yml
|
|||||||
- SilverStripe\BehatExtension\Context\LoginContext
|
- SilverStripe\BehatExtension\Context\LoginContext
|
||||||
-
|
-
|
||||||
SilverStripe\BehatExtension\Context\FixtureContext:
|
SilverStripe\BehatExtension\Context\FixtureContext:
|
||||||
- %paths.modules.framework%/tests/behat/features/files/
|
- '%paths.modules.framework%/tests/behat/features/files/'
|
||||||
extensions:
|
extensions:
|
||||||
SilverStripe\BehatExtension\MinkExtension:
|
SilverStripe\BehatExtension\MinkExtension:
|
||||||
default_session: facebook_web_driver
|
default_session: facebook_web_driver
|
||||||
@ -151,7 +154,8 @@ Example: behat.yml
|
|||||||
browser: chrome
|
browser: chrome
|
||||||
wd_host: "http://127.0.0.1:9515" #chromedriver port
|
wd_host: "http://127.0.0.1:9515" #chromedriver port
|
||||||
SilverStripe\BehatExtension\Extension:
|
SilverStripe\BehatExtension\Extension:
|
||||||
screenshot_path: %paths.base%/artifacts/screenshots
|
screenshot_path: '%paths.base%/artifacts/screenshots'
|
||||||
|
```
|
||||||
|
|
||||||
## Module Initialisation
|
## Module Initialisation
|
||||||
|
|
||||||
@ -167,9 +171,11 @@ Since step definitions are quite domain specific, its likely that you'll need yo
|
|||||||
The Silverstripe Behat extension provides an initializer script which generates a template
|
The Silverstripe Behat extension provides an initializer script which generates a template
|
||||||
in the recommended folder structure:
|
in the recommended folder structure:
|
||||||
|
|
||||||
|
```sh
|
||||||
vendor/bin/behat --init @mymodule --namespace="MyVendor\MyModule"
|
vendor/bin/behat --init @mymodule --namespace="MyVendor\MyModule"
|
||||||
|
```
|
||||||
|
|
||||||
Note: namespace is mandatory
|
**Note: namespace is mandatory**
|
||||||
|
|
||||||
You'll now have a class located in `mymodule/tests/behat/src/FeatureContext.php`,
|
You'll now have a class located in `mymodule/tests/behat/src/FeatureContext.php`,
|
||||||
which will have a psr-4 class mapping added to composer.json by default.
|
which will have a psr-4 class mapping added to composer.json by default.
|
||||||
@ -182,7 +188,9 @@ The extension comes with several `BehatContext` subclasses come with some extra
|
|||||||
Some of them are just helpful in general website testing, other's are specific to SilverStripe.
|
Some of them are just helpful in general website testing, other's are specific to SilverStripe.
|
||||||
To find out all available steps (and the files they are defined in), run the following:
|
To find out all available steps (and the files they are defined in), run the following:
|
||||||
|
|
||||||
|
```sh
|
||||||
vendor/bin/behat @mymodule --definitions=i
|
vendor/bin/behat @mymodule --definitions=i
|
||||||
|
```
|
||||||
|
|
||||||
Note: There are more specific step definitions in the Silverstripe `framework` module
|
Note: There are more specific step definitions in the Silverstripe `framework` module
|
||||||
for interacting with the CMS interfaces (see `framework/tests/behat/features/bootstrap`).
|
for interacting with the CMS interfaces (see `framework/tests/behat/features/bootstrap`).
|
||||||
@ -207,6 +215,7 @@ scenario automatically.
|
|||||||
If you need more flexibility and transparency about which records are being created,
|
If you need more flexibility and transparency about which records are being created,
|
||||||
use the inline definition syntax. The following example shows some syntax variations:
|
use the inline definition syntax. The following example shows some syntax variations:
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Feature: Do something with pages
|
Feature: Do something with pages
|
||||||
As an site owner
|
As an site owner
|
||||||
I want to manage pages
|
I want to manage pages
|
||||||
@ -236,6 +245,7 @@ use the inline definition syntax. The following example shows some syntax variat
|
|||||||
Given I am logged in with "ADMIN" permissions
|
Given I am logged in with "ADMIN" permissions
|
||||||
And I go to "/admin/pages"
|
And I go to "/admin/pages"
|
||||||
Then I should see "Page 1" in CMS Tree
|
Then I should see "Page 1" in CMS Tree
|
||||||
|
```
|
||||||
|
|
||||||
* Fixtures are created where you defined them. If you want the fixtures to be created
|
* Fixtures are created where you defined them. If you want the fixtures to be created
|
||||||
before every scenario, define them in
|
before every scenario, define them in
|
||||||
@ -259,8 +269,10 @@ use the inline definition syntax. The following example shows some syntax variat
|
|||||||
As a convention, Silverstripe Behat tests live in a `tests/behat` subfolder
|
As a convention, Silverstripe Behat tests live in a `tests/behat` subfolder
|
||||||
of your module. You can create it with the following commands:
|
of your module. You can create it with the following commands:
|
||||||
|
|
||||||
|
```sh
|
||||||
mkdir -p mymodule/tests/behat/features/
|
mkdir -p mymodule/tests/behat/features/
|
||||||
mkdir -p mymodule/tests/behat/src/
|
mkdir -p mymodule/tests/behat/src/
|
||||||
|
```
|
||||||
|
|
||||||
### FeatureContext
|
### FeatureContext
|
||||||
|
|
||||||
@ -269,9 +281,9 @@ here as well. The only major difference is the base class from which
|
|||||||
to extend your own `FeatureContext`: It should be `SilverStripeContext`
|
to extend your own `FeatureContext`: It should be `SilverStripeContext`
|
||||||
rather than `BehatContext`.
|
rather than `BehatContext`.
|
||||||
|
|
||||||
Example: mymodule/tests/behat/src/FeatureContext.php
|
Example: `mymodule/tests/behat/src/FeatureContext.php`
|
||||||
|
|
||||||
<?php
|
```php
|
||||||
namespace MyModule\Test\Behaviour;
|
namespace MyModule\Test\Behaviour;
|
||||||
|
|
||||||
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
use SilverStripe\BehatExtension\Context\SilverStripeContext;
|
||||||
@ -279,6 +291,7 @@ Example: mymodule/tests/behat/src/FeatureContext.php
|
|||||||
class FeatureContext extends SilverStripeContext
|
class FeatureContext extends SilverStripeContext
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Screen Size
|
### Screen Size
|
||||||
|
|
||||||
@ -287,7 +300,9 @@ define the desired browser window size through a `capabilities` definition.
|
|||||||
By default, Selenium doesn't support this though, so we've added a workaround
|
By default, Selenium doesn't support this though, so we've added a workaround
|
||||||
through an environment variable:
|
through an environment variable:
|
||||||
|
|
||||||
|
```sh
|
||||||
BEHAT_SCREEN_SIZE=320x600 vendor/bin/behat
|
BEHAT_SCREEN_SIZE=320x600 vendor/bin/behat
|
||||||
|
```
|
||||||
|
|
||||||
### Inspecting PHP sessions
|
### Inspecting PHP sessions
|
||||||
|
|
||||||
@ -298,15 +313,18 @@ of the `TestSessionEnvironment`, in order to share it with Behat CLI.
|
|||||||
|
|
||||||
Example: Retrieve the currently logged-in member
|
Example: Retrieve the currently logged-in member
|
||||||
|
|
||||||
|
```php
|
||||||
use SilverStripe\TestSession\TestsessionEnvironment;
|
use SilverStripe\TestSession\TestsessionEnvironment;
|
||||||
|
|
||||||
$env = Injector::inst()->get(TestSessionEnvironment::class);
|
$env = Injector::inst()->get(TestSessionEnvironment::class);
|
||||||
$state = $env->getState();
|
$state = $env->getState();
|
||||||
|
|
||||||
if (isset($state->session['loggedInAs'])) {
|
if (isset($state->session['loggedInAs'])) {
|
||||||
$member = \Member::get()->byID($state->session['loggedInAs']);
|
$member = \Member::get()->byID($state->session['loggedInAs']);
|
||||||
} else {
|
} else {
|
||||||
$member = null;
|
$member = null;
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
@ -387,12 +405,16 @@ otherwise you'll always have an active debugging session in CLI, never in the br
|
|||||||
|
|
||||||
Then you can choose to enable XDebug for the current CLI run:
|
Then you can choose to enable XDebug for the current CLI run:
|
||||||
|
|
||||||
|
```sh
|
||||||
XDEBUG_CONFIG="idekey=macgdbp" vendor/bin/behat
|
XDEBUG_CONFIG="idekey=macgdbp" vendor/bin/behat
|
||||||
|
```
|
||||||
|
|
||||||
Or you can use the `TESTSESSION_PARAMS` environment variable to pass additional
|
Or you can use the `TESTSESSION_PARAMS` environment variable to pass additional
|
||||||
parameters to `dev/testsession/start`, and debug in the browser instead.
|
parameters to `dev/testsession/start`, and debug in the browser instead.
|
||||||
|
|
||||||
|
```sh
|
||||||
TESTSESSION_PARAMS="XDEBUG_SESSION_START=macgdbp" vendor/bin/behat @app
|
TESTSESSION_PARAMS="XDEBUG_SESSION_START=macgdbp" vendor/bin/behat @app
|
||||||
|
```
|
||||||
|
|
||||||
The `macgdbp` IDE key needs to match your `xdebug.idekey` php.ini setting.
|
The `macgdbp` IDE key needs to match your `xdebug.idekey` php.ini setting.
|
||||||
|
|
||||||
@ -410,6 +432,7 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
|
|
||||||
### Basics
|
### Basics
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/
|
Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/
|
||||||
- Checks, that page contains specified text.
|
- Checks, that page contains specified text.
|
||||||
|
|
||||||
@ -473,9 +496,11 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
Then /^the "([^"]*)" table should not contain "([^"]*)"$/
|
Then /^the "([^"]*)" table should not contain "([^"]*)"$/
|
||||||
|
|
||||||
Given /^I click on "([^"]*)" in the "([^"]*)" table$/
|
Given /^I click on "([^"]*)" in the "([^"]*)" table$/
|
||||||
|
```
|
||||||
|
|
||||||
### Navigation
|
### Navigation
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Given /^(?:|I )am on homepage$/
|
Given /^(?:|I )am on homepage$/
|
||||||
- Opens homepage.
|
- Opens homepage.
|
||||||
|
|
||||||
@ -496,9 +521,11 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
|
|
||||||
When /^(?:|I )move forward one page$/
|
When /^(?:|I )move forward one page$/
|
||||||
- Moves forward one page in history
|
- Moves forward one page in history
|
||||||
|
```
|
||||||
|
|
||||||
### Forms
|
### Forms
|
||||||
|
|
||||||
|
```cucumber
|
||||||
When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/
|
When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/
|
||||||
- Presses button with specified id|name|title|alt|value.
|
- Presses button with specified id|name|title|alt|value.
|
||||||
|
|
||||||
@ -562,9 +589,11 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
- Check an individual input button from a group of inputs
|
- Check an individual input button from a group of inputs
|
||||||
- Example: I select "Admins" from "Groups" input group
|
- Example: I select "Admins" from "Groups" input group
|
||||||
(where "Groups" is the title of the CheckboxSetField or OptionsetField form field)
|
(where "Groups" is the title of the CheckboxSetField or OptionsetField form field)
|
||||||
|
```
|
||||||
|
|
||||||
### Interactions
|
### Interactions
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Given /^I press the "([^"]*)" button$/
|
Given /^I press the "([^"]*)" button$/
|
||||||
|
|
||||||
Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element$/
|
Given /^I (click|double click) "([^"]*)" in the "([^"]*)" element$/
|
||||||
@ -582,9 +611,11 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
Given /^I confirm the dialog$/
|
Given /^I confirm the dialog$/
|
||||||
|
|
||||||
Given /^I dismiss the dialog$/
|
Given /^I dismiss the dialog$/
|
||||||
|
```
|
||||||
|
|
||||||
### Login
|
### Login
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Given /^I am logged in with "([^"]*)" permissions$/
|
Given /^I am logged in with "([^"]*)" permissions$/
|
||||||
- Creates a member in a group with the correct permissions.
|
- Creates a member in a group with the correct permissions.
|
||||||
|
|
||||||
@ -595,9 +626,11 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
Given /^I should see a log-in form$/
|
Given /^I should see a log-in form$/
|
||||||
|
|
||||||
Then /^I will see a "bad" log-in message$/
|
Then /^I will see a "bad" log-in message$/
|
||||||
|
```
|
||||||
|
|
||||||
### CMS UI
|
### CMS UI
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Then /^I should see an edit page form$/
|
Then /^I should see an edit page form$/
|
||||||
|
|
||||||
Then /^I should see the CMS$/
|
Then /^I should see the CMS$/
|
||||||
@ -619,9 +652,11 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
Given /^the preview contains "([^"]*)"$/
|
Given /^the preview contains "([^"]*)"$/
|
||||||
|
|
||||||
Given /^the preview does not contain "([^"]*)"$/
|
Given /^the preview does not contain "([^"]*)"$/
|
||||||
|
```
|
||||||
|
|
||||||
### Fixtures
|
### Fixtures
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/
|
Given /^(?:(an|a|the) )"(?<type>[^"]+)" "(?<id>[^"]+)" (:?which )?redirects to (?:(an|a|the) )"(?<targetType>[^"]+)" "(?<targetId>[^"]+)"$/
|
||||||
- Find or create a redirector page and link to another existing page.
|
- Find or create a redirector page and link to another existing page.
|
||||||
|
|
||||||
@ -663,14 +698,18 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
Given /^the CMS settings have the following data$/
|
Given /^the CMS settings have the following data$/
|
||||||
- Example: Given the CMS settings has the following data
|
- Example: Given the CMS settings has the following data
|
||||||
- Note: It only works with the Silverstripe CMS module installed
|
- Note: It only works with the Silverstripe CMS module installed
|
||||||
|
```
|
||||||
|
|
||||||
### Environment
|
### Environment
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Given /^the current date is "([^"]*)"$/
|
Given /^the current date is "([^"]*)"$/
|
||||||
Given /^the current time is "([^"]*)"$/
|
Given /^the current time is "([^"]*)"$/
|
||||||
|
```
|
||||||
|
|
||||||
### Email
|
### Email
|
||||||
|
|
||||||
|
```cucumber
|
||||||
Given /^there should (not |)be an email (to|from) "([^"]*)"$/
|
Given /^there should (not |)be an email (to|from) "([^"]*)"$/
|
||||||
|
|
||||||
Given /^there should (not |)be an email (to|from) "([^"]*)" titled "([^"]*)"$/
|
Given /^there should (not |)be an email (to|from) "([^"]*)" titled "([^"]*)"$/
|
||||||
@ -697,6 +736,7 @@ It's based on the `vendor/bin/behat -di @cms` output.
|
|||||||
|
|
||||||
When /^I click on the http link "([^"]*)" in the email$/
|
When /^I click on the http link "([^"]*)" in the email$/
|
||||||
- Example: When I click on the http link "http://localhost/changepassword" in the email
|
- Example: When I click on the http link "http://localhost/changepassword" in the email
|
||||||
|
```
|
||||||
|
|
||||||
### Transformations
|
### Transformations
|
||||||
|
|
||||||
@ -716,6 +756,6 @@ for example to cast any argument matching the `\d` regex into an actual PHP inte
|
|||||||
|
|
||||||
## Useful resources
|
## Useful resources
|
||||||
|
|
||||||
* [Silverstripe CMS architecture](http://doc.silverstripe.org/sapphire/en/trunk/reference/cms-architecture)
|
* [Silverstripe CMS architecture](https://docs.silverstripe.org/sapphire/en/trunk/reference/cms-architecture)
|
||||||
* [Silverstripe Framework Test Module](https://github.com/silverstripe-labs/silverstripe-frameworktest)
|
* [Silverstripe Framework Test Module](https://github.com/silverstripe-labs/silverstripe-frameworktest)
|
||||||
* [Silverstripe Unit and Integration Testing](http://doc.silverstripe.org/sapphire/en/trunk/topics/testing)
|
* [Silverstripe Unit and Integration Testing](https://docs.silverstripe.org/sapphire/en/trunk/topics/testing)
|
||||||
|
Loading…
Reference in New Issue
Block a user