You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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
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.
318
320
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.
321
322
322
323
Modify your `acceptance.suite.yml` file:
323
324
@@ -327,24 +328,24 @@ modules:
327
328
enabled:
328
329
- WebDriver:
329
330
url: {{your site URL}}
330
-
browser: firefox
331
+
browser: chrome
331
332
- \Helper\Acceptance
332
333
```
333
334
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).
336
337
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,
341
339
but it will also check that element is actually visible to the user:
342
340
343
341
```php
344
342
<?php
345
343
$I->seeElement('#modal');
346
344
```
347
345
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
+
348
349
#### Wait
349
350
350
351
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
472
473
473
474
The AngularJS module extends WebDriver so that all the configuration options from it are available.
474
475
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
-
496
476
### Debugging
497
477
498
478
Codeception modules can print valuable information while running.
* 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:
62
65
*
63
66
* ```yaml
64
67
* modules:
65
68
* enabled:
66
69
* - WebDriver:
67
70
* url: 'http://localhost/'
68
-
* browser: firefox
71
+
* browser: chrome
69
72
* ```
70
73
*
71
74
* ### PhantomJS
@@ -86,6 +89,17 @@
86
89
* browser: phantomjs
87
90
* ```
88
91
*
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
+
*
89
103
* ## Cloud Testing
90
104
*
91
105
* Cloud Testing services can run your WebDriver tests in the cloud.
@@ -160,7 +174,7 @@
160
174
* * `window_size` - Initial window size. Set to `maximize` or a dimension in the format `640x480`.
161
175
* * `clear_cookies` - Set to false to keep cookies, or set to true (default) to delete all cookies between tests.
162
176
* * `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.
164
178
* * `connection_timeout` - timeout for opening a connection to remote selenium server (30 seconds by default).
165
179
* * `request_timeout` - timeout for a request to return something from remote selenium server (30 seconds by default).
166
180
* * `pageload_timeout` - amount of time to wait for a page load to complete before throwing an error (default 0 seconds).
0 commit comments