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
A nice feature of Codeception is that most scenarios can be easily ported between the testing backends.
364
-
The PhpBrowser tests we wrote previously can be executed inside a real browser (or PhantomJS) with Selenium WebDriver.
363
+
A nice feature of Codeception is that most scenarios are similar no matter of how they are executed.
364
+
PhpBrowser was emulating browser requests but how to execute such test in a real browser like Chrome or Firefox?
365
+
Selenium WebDriver can drive them so in our acceptance tests we can automate scenarios we used to test manually.
366
+
Such tests we should concentrate more on **testing the UI** than on testing functionality.
365
367
366
-
The only thing we need to change is to reconfigure and rebuild the AcceptanceTester class,
367
-
and to use **WebDriver** instead of PhpBrowser.
368
+
To execute test in a browser we need to change suite configuration to use **WebDriver** instead of PhpBrowser.
368
369
369
370
Modify your `acceptance.suite.yml` file:
370
371
@@ -375,18 +376,15 @@ modules:
375
376
enabled:
376
377
- WebDriver:
377
378
url: {{your site URL}}
378
-
browser: firefox
379
+
browser: chrome
379
380
- \Helper\Acceptance
380
381
381
382
{% endhighlight %}
382
383
383
-
In order to run Selenium tests you need to [download Selenium Server](http://seleniumhq.org/download/)
384
-
and get it running. Alternatively you may use [PhantomJS](http://phantomjs.org/) headless browser in `ghostdriver` mode.
384
+
In order to run browser tests you will need Selenium Server or PhantomJS.
385
+
WebDriver module contains a manual on [how to start them](http://codeception.com/docs/modules/WebDriver#Local-Testing).
385
386
386
-
If you run your acceptance tests with Selenium, Firefox will be started
387
-
and all the actions will be performed step by step using the browser engine.
388
-
389
-
In this case `seeElement` won't just check that the element exists on a page,
387
+
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,
390
388
but it will also check that element is actually visible to the user:
391
389
392
390
{% highlight php %}
@@ -396,6 +394,9 @@ $I->seeElement('#modal');
396
394
397
395
{% endhighlight %}
398
396
397
+
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.
398
+
WebDriver also adds browser-specific functionality which will be listed in next sections.
399
+
399
400
#### Wait
400
401
401
402
While testing web application, you may need to wait for JavaScript events to occur. Due to its asynchronous nature,
@@ -535,29 +536,6 @@ before the previous actions are completed and uses the AngularJS API to check th
535
536
536
537
The AngularJS module extends WebDriver so that all the configuration options from it are available.
537
538
538
-
### Cleaning Things Up
539
-
540
-
While testing, your actions may change the data on the site. Tests will fail if trying to create
541
-
or update the same data twice. To avoid this problem, your database should be repopulated for each test.
542
-
Codeception provides a `Db` module for that purpose. It will load a database dump after each passed test.
543
-
To make repopulation work, create an SQL dump of your database and put it into the `tests/_data` directory.
544
-
Set the database connection and path to the dump in the global Codeception config.
545
-
546
-
{% highlight yaml %}
547
-
548
-
# in codeception.yml:
549
-
modules:
550
-
config:
551
-
Db:
552
-
dsn: '[set PDO DSN here]'
553
-
user: '[set user]'
554
-
password: '[set password]'
555
-
dump: tests/_data/dump.sql
556
-
557
-
{% endhighlight %}
558
-
559
-
After we have configured the Db module, we should have it enabled in the `acceptance.suite.yml` configuration file.
560
-
561
539
### Debugging
562
540
563
541
Codeception modules can print valuable information while running.
Behavior Driven Development is a popular methodology of software development. It is considered to be an extension to TDD, and is much inspired by [Agile](http://agilemanifesto.org/) practices. The main reason for choosing BDD for development process is breaking communication barer between business and technical teams. BDD encourages usage of automated testing to make all documented features of a project to be tested from the very beginning. This is why it is common to talk about BDD in the context of a test frameworks (like Codeception). However, BDD is much beyond the testing at all, and is more about managing the development process.
8
+
Behavior Driven Development (BDD) is a popular software development methodology. BDD is considered an extension of TDD, and is greatly inspired by [Agile](http://agilemanifesto.org/) practices. The primary reason to choose BDD as your development process is to break down communication barriers between business and technical teams. BDD encourages the use of automated testing to verify all documented features of a project from the very beginning. This is why it is common to talk about BDD in the context of test frameworks (like Codeception). The BDD approach, however, is about much more than testing - it is a common language for all team members to use during the development process.
2. Launch the daemon: `java -jar selenium-server-standalone-2.xx.xxx.jar`
21
-
3. Configure this module (in acceptance.suite.yml) by setting url and browser:
22
+
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).
23
+
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=`.
24
+
4. Configure this module (in acceptance.suite.yml) by setting url and browser:
22
25
23
26
{% highlight yaml %}
24
27
25
28
modules:
26
29
enabled:
27
30
- WebDriver:
28
31
url: 'http://localhost/'
29
-
browser: firefox
32
+
browser: chrome
30
33
31
34
{% endhighlight %}
32
35
@@ -50,6 +53,18 @@ It allows you to run Selenium tests on a server without a GUI installed.
50
53
51
54
{% endhighlight %}
52
55
56
+
##### Headless Selenium in Docker
57
+
58
+
Docker can ship Selenium Server with all its dependencies and browsers inside a single container.
59
+
Running tests inside Docker is as easy as pulling [official selenium image](https://github.com/SeleniumHQ/docker-selenium) and starting a container with Chrome:
60
+
61
+
{% highlight yaml %}
62
+
docker run --net=host selenium/standalone-chrome
63
+
64
+
{% endhighlight %}
65
+
66
+
By using `--net=host` we allow selenium to access local websites.
67
+
53
68
### Cloud Testing
54
69
55
70
Cloud Testing services can run your WebDriver tests in the cloud.
@@ -130,7 +145,7 @@ you should use a tunnel application provided by a service.
130
145
*`window_size` - Initial window size. Set to `maximize` or a dimension in the format `640x480`.
131
146
*`clear_cookies` - Set to false to keep cookies, or set to true (default) to delete all cookies between tests.
132
147
*`wait` - Implicit wait (default 0 seconds).
133
-
*`capabilities` - Sets Selenium2[desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). Should be a key-value array.
148
+
*`capabilities` - Sets Selenium[desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). Should be a key-value array.
134
149
*`connection_timeout` - timeout for opening a connection to remote selenium server (30 seconds by default).
135
150
*`request_timeout` - timeout for a request to return something from remote selenium server (30 seconds by default).
136
151
*`pageload_timeout` - amount of time to wait for a page load to complete before throwing an error (default 0 seconds).
@@ -155,11 +170,6 @@ Example (`acceptance.suite.yml`)
155
170
156
171
{% endhighlight %}
157
172
158
-
#### Status
159
-
160
-
Stability: **stable**
161
-
Based on [facebook php-webdriver](https://github.com/facebook/php-webdriver)
0 commit comments