10000 Improved docs for acceptance testing. (#4128) · Codeception/Codeception@c17370c · GitHub
[go: up one dir, main page]

Skip to content

Commit c17370c

Browse files
authored
Improved docs for acceptance testing. (#4128)
* Improved docs for acceptance testing. * Added ChromeDriver mention to WebDriver docs * Added Docker as possible setup * Added link to WebDriver Local Testing from AcceptanceTesting guide * Removed Data section (we have special guide for it) in Acceptance Testing * updated acceptance tests
1 parent 3955bf1 commit c17370c

File tree

2 files changed

+30
-41
lines changed

2 files changed

+30
-41
lines changed

docs/03-AcceptanceTests.md

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,12 @@ $user_id = $I->grabFromCurrentUrl('~$/user/(\d+)/~');
313313

314314
## Selenium WebDriver
315315

316-
A nice feature of Codeception is that most scenarios can be easily ported between the testing backends.
317-
The PhpBrowser tests we wrote previously can be executed inside a real browser (or PhantomJS) with Selenium WebDriver.
316+
A nice feature of Codeception is that most scenarios are similar no matter of how they are executed.
317+
PhpBrowser was emulating browser requests but how to execute such test in a real browser like Chrome or Firefox?
318+
Selenium WebDriver can drive them so in our acceptance tests we can automate scenarios we used to test manually.
319+
Such tests we should concentrate more on **testing the UI** than on testing functionality.
318320

319-
The only thing we need to change is to reconfigure and rebuild the AcceptanceTester class,
320-
and to use **WebDriver** instead of PhpBrowser.
321+
To execute test in a browser we need to change suite configuration to use **WebDriver** instead of PhpBrowser.
321322

322323
Modify your `acceptance.suite.yml` file:
323324

@@ -327,24 +328,24 @@ modules:
327328
enabled:
328329
- WebDriver:
329330
url: {{your site URL}}
330-
browser: firefox
331+
browser: chrome
331332
- \Helper\Acceptance
332333
```
333334

334-
In order to run Selenium tests you need to [download Selenium Server](http://seleniumhq.org/download/)
335-
and get it running. Alternatively you may use [PhantomJS](http://phantomjs.org/) headless browser in `ghostdriver` mode.
335+
In order to run browser tests you will need Selenium Server or PhantomJS.
336+
WebDriver module contains a manual on [how to start them](http://codeception.com/docs/modules/WebDriver#Local-Testing).
336337

337-
If you run your acceptance tests with Selenium, Firefox will be started
338-
and all the actions will be performed step by step using the browser engine.
339-
340-
In this case `seeElement` won't just check that the element exists on a page,
338+
Please note that actions executed in a browser will behave differently. For instance, `seeElement` won't just check that the element exists on a page,
341339
but it will also check that element is actually visible to the user:
342340

343341
```php
344342
<?php
345343
$I->seeElement('#modal');
346344
```
347345

346+
While WebDriver duplicate the functionality of PhpBrowser it has its limitations: it can't check headers, perform HTTP requests, as browsers don't provide APIs for that.
347+
WebDriver also adds browser-specific functionality which will be listed in next sections.
348+
348349
#### Wait
349350

350351
While testing web application, you may need to wait for JavaScript events to occur. Due to its asynchronous nature,
@@ -472,27 +473,6 @@ before the previous actions are completed and uses the AngularJS API to check th
472473

473474
The AngularJS module extends WebDriver so that all the configuration options from it are available.
474475

475-
### Cleaning Things Up
476-
477-
While testing, your actions may change the data on the site. Tests will fail if trying to create
478-
or update the same data twice. To avoid this problem, your database should be repopulated for each test.
479-
Codeception provides a `Db` module for that purpose. It will load a database dump after each passed test.
480-
To make repopulation work, create an SQL dump of your database and put it into the `tests/_data` directory.
481-
Set the database connection and path to the dump in the global Codeception config.
482-
483-
```yaml
484-
# in codeception.yml:
485-
modules:
486-
config:
487-
Db:
488-
dsn: '[set PDO DSN here]'
489-
user: '[set user]'
490-
password: '[set password]'
491-
dump: tests/_data/dump.sql
492-
```
493-
494-
After we have configured the Db module, we should have it enabled in the `acceptance.suite.yml` configuration file.
495-
496476
### Debugging
497477

498478
Codeception modules can print valuable information while running.

src/Codeception/Module/WebDriver.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,19 @@
5656
*
5757
* ### Selenium
5858
*
59+
* To run Selenium Server you will need Java and Chrome or Firefox browser installed.
60+
*
5961
* 1. Download [Selenium Server](http://docs.seleniumhq.org/download/)
60-
* 2. Launch the daemon: `java -jar selenium-server-standalone-2.xx.xxx.jar`
61-
* 3. Configure this module (in acceptance.suite.yml) by setting url and browser:
62+
* 2. For Chrome browser install [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/getting-started), for Firefox browser install [GeckoDriver](https://github.com/mozilla/geckodriver).
63+
* 3. Launch the server: `java -jar selenium-server-standalone-3.xx.xxx.jar`. To locate Chromedriver binary use `-Dwebdriver.chrome.driver=./chromedriver` option. For Geckodriver use `-Dwebdriver.gecko.driver=`.
64+
* 4. Configure this module (in acceptance.suite.yml) by setting url and browser:
6265
*
6366
* ```yaml
6467
* modules:
6568
* enabled:
6669
* - WebDriver:
6770
* url: 'http://localhost/'
68-
* browser: firefox
71+
* browser: chrome
6972
* ```
7073
*
7174
* ### PhantomJS
@@ -86,6 +89,17 @@
8689
* browser: phantomjs
8790
* ```
8891
*
92+
* #### Headless Selenium in Docker
93+
*
94+
* Docker can ship Selenium Server with all its dependencies and browsers inside a single container.
95+
* Running tests inside Docker is as easy as pulling [official selenium image](https://github.com/SeleniumHQ/docker-selenium) and starting a container with Chrome:
96+
*
97+
* ```
98+
* docker run --net=host selenium/standalone-chrome
99+
* ```
100+
*
101+
* By using `--net=host` we allow selenium to access local websites.
102+
*
89103
* ## Cloud Testing
90104
*
91105
* Cloud Testing services can run your WebDriver tests in the cloud.
@@ -160,7 +174,7 @@
160174
* * `window_size` - Initial window size. Set to `maximize` or a dimension in the format `640x480`.
161175
* * `clear_cookies` - Set to false to keep cookies, or set to true (default) to delete all cookies between tests.
162176
* * `wait` - Implicit wait (default 0 seconds).
163-
* * `capabilities` - Sets Selenium2 [desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). Should be a key-value array.
177+
* * `capabilities` - Sets Selenium [desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). Should be a key-value array.
164178
* * `connection_timeout` - timeout for opening a connection to remote selenium server (30 seconds by default).
165179
* * `request_timeout` - timeout for a request to return something from remote selenium server (30 seconds by default).
166180
* * `pageload_timeout` - amount of time to wait for a page load to complete before throwing an error (default 0 seconds).
@@ -183,11 +197,6 @@
183197
* firefox_profile: '~/firefox-profiles/codeception-profile.zip.b64'
184198
* ```
185199
*
186-
* ### Status
187-
*
188-
* Stability: **stable**
189-
* Based on [facebook php-webdriver](https://github.com/facebook/php-webdriver)
190-
*
191200
* ## Usage
192201
*
193202
* ### Locating Elements

0 commit comments

Comments
 (0)
0