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 are similar, no matter of how they are executed.
370
-
`PhpBrowser` was emulating browser requests but how to execute such test in a real browser like Chrome or Firefox?
370
+
`PhpBrowser` was emulating browser requests but how to execute such test in a real browser like Chrome or Firefox?
371
371
Selenium WebDriver can drive them so in our acceptance tests we can automate scenarios we used to test manually.
372
372
In such tests, we should concentrate more on **testing the UI** than on testing functionality.
373
373
374
374
"[WebDriver](https://www.w3.org/TR/webdriver/)" is the name of a protocol (specified by W3C)
375
-
to drive browsers automatically. This specification is implemented for all modern desktop and mobile browsers.
375
+
to drive browsers automatically. This specification is implemented for all modern desktop and mobile browsers.
376
376
Codeception uses [facebook/php-webdriver](https://github.com/facebook/php-webdriver) library from Facebook as PHP implementation of WebDriver protocol.
377
377
378
-
To control the browsers you need to use a program or a service to start/stop browser sessions.
378
+
To control the browsers you need to use a program or a service to start/stop browser sessions.
379
379
In the next section, we will overview the most popular solutions.
380
380
381
-
### Local Setup
382
-
381
+
### Local Setup
382
+
383
383
#### Selenium Server
384
384
385
-
[Selenium Server](http://www.seleniumhq.org/) is a de-facto standard for automated web and mobile testing.
385
+
[Selenium Server](http://www.seleniumhq.org/) is a de-facto standard for automated web and mobile testing.
386
386
It is a server that can launch and drive different browsers locally or remotely.
387
-
WebDriver protocol was initially created by Selenium before becoming a W3C standard.
388
-
This makes Selenium server the most stable complete implementation of WebDriver for today.
387
+
WebDriver protocol was initially created by Selenium before becoming a W3C standard.
388
+
This makes Selenium server the most stable complete implementation of WebDriver for today.
389
389
Selenium Server is also recommended by Codeception team.
390
390
391
391
To control browsers Selenium Server uses official tools maintained by browser vendors, like [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver) for Chrome or [GeckoDriver](https://github.com/mozilla/geckodriver) for Firefox.
@@ -409,12 +409,12 @@ And the most important: **PhantomJS is not maintained** anymore. So use it at yo
409
409
410
410
#### ChromeDriver
411
411
412
-
ChromeDriver was created by Google to control Chrome and Chromium browsers programmatically.
412
+
ChromeDriver was created by Google to control Chrome and Chromium browsers programmatically.
413
413
It can be paired with [Selenium Server](http://codeception.com/docs/03-AcceptanceTests#Selenium-Server) or used as a standalone tool to drive Chrome browser.
414
414
It is simpler to set up than Selenium Server, however, it has limited support for WebDriver protocol.
* Enable [RunProcess](http://codeception.com/extensions#RunProcess) extension to start/stop ChromeDriver automatically *(optional)*.
417
+
* Enable [RunProcess](http://codeception.com/extensions#RunProcess) extension to start/stop ChromeDriver automatically *(optional)*.
418
418
419
419
### Configuration
420
420
@@ -446,15 +446,13 @@ $I->seeElement('#modal');
446
446
447
447
{% endhighlight %}
448
448
449
-
While WebDriver duplicates the functionality of PhpBrowser, it has its limitations: It can't check headers since browsers don't provide APIs for that.
449
+
While WebDriver duplicates the functionality of PhpBrowser, it has its limitations: It can't check headers since browsers don't provide APIs for that.
450
450
WebDriver also adds browser-specific functionality:
451
451
452
-
453
-
454
452
#### Wait
455
453
456
454
While testing web application, you may need to wait for JavaScript events to occur. Due to its asynchronous nature,
457
-
complex JavaScript interactions are hard to test. That's why you may need to use waiters, actions with `wait` prefix.
455
+
complex JavaScript interactions are hard to test. That's why you may need to use waiters, actions with `wait` prefix.
458
456
They can be used to specify what event you expect to occur on a page, before continuing the test.
459
457
460
458
For example:
@@ -468,7 +466,7 @@ $I->click('#agree_button');
468
466
{% endhighlight %}
469
467
470
468
In this case, we are waiting for the 'agree' button to appear and then click it. If it didn't appear after 30 seconds,
471
-
the test will fail. There are other `wait` methods you may use, like [waitForText](http://codeception.com/docs/modules/WebDriver#waitForText),
469
+
the test will fail. There are other `wait` methods you may use, like [waitForText](http://codeception.com/docs/modules/WebDriver#waitForText),
472
470
[waitForElementVisible](http://codeception.com/docs/modules/WebDriver#waitForElementVisible) and others.
473
471
474
472
If you don't know what exact element you need to wait for, you can simply pause execution with using `$I->wait()`
@@ -484,7 +482,7 @@ $I->wait(3); // wait for 3 secs
484
482
485
483
*since 2.3.4 version*
486
484
487
-
It is possible to wait for elements pragmatically.
485
+
It is possible to wait for elements pragmatically.
488
486
If a test uses element which is not on a page yet, Codeception will wait for few extra seconds before failing.
489
487
This feature is based on [Implicit Wait](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#implicit-waits) of Selenium.
490
488
Codeception enables implicit wait only when searching for a specific element and disables in all other cases. Thus, the performance of a test is not affected.
@@ -502,7 +500,7 @@ With this config we have the following test:
502
500
{% highlight php %}
503
501
504
502
<?php
505
-
// we use wait: 5 instead of
503
+
// we use wait: 5 instead of
506
504
// $I->waitForElement(['css' => '#click-me'], 5);
507
505
// to wait for element on page
508
506
$I->click(['css' => '#click-me']);
@@ -534,7 +532,7 @@ $I->seeNumberOfElements(['css' => 'button.link'], 5); // DISABLED, can wait only
534
532
535
533
#### Wait and Act
536
534
537
-
To combine `waitForElement` with actions inside that element you can use the [performOn](http://codeception.com/docs/modules/WebDriver#performOn) method.
535
+
To combine `waitForElement` with actions inside that element you can use the [performOn](http://codeception.com/docs/modules/WebDriver#performOn) method.
538
536
Let's see how you can perform some actions inside an HTML popup:
539
537
540
538
{% highlight php %}
@@ -618,15 +616,13 @@ You just need to set the [WebDriver configuration](http://codeception.com/docs/m
618
616
* browser
619
617
* OS
620
618
621
-
622
619
We recommend using [params](http://codeception.com/docs/06-ModulesAndHelpers#Dynamic-Configuration-With-Params)
623
620
to provide authorization credentials.
624
621
625
622
It should be mentioned that Cloud Testing services are not free. You should investigate their pricing models
626
623
and choose one that fits your needs. They also may work painfully slowly if ping times between the local server
627
624
and the cloud is too high. This may lead to random failures in acceptance tests.
628
625
629
-
630
626
### AngularJS Testing
631
627
632
628
In the modern era of Single Page Applications, the browser replaces the server in creating the user interface.
@@ -662,23 +658,22 @@ Additional debugging features by Codeception:
662
658
663
659
* [pauseExecution](http://codeception.com/docs/modules/WebDriver#pauseExecution) method of WebDriver module allows pausing the test.
664
660
* [Recorder extension](http://codeception.com/addons#CodeceptionExtensionRecorder) allows to record tests step-by-steps and show them in slideshow
665
-
* [Interactive Console](http://codeception.com/docs/07-AdvancedUsage#Interactive-Console) is a REPL that allows to type and check commands for instant feedback.
666
-
661
+
* [Interactive Console](http://codeception.com/docs/07-AdvancedUsage#Interactive-Console) is a REPL that allows to type and check commands for instant feedback.
667
662
668
663
### Custom Browser Sessions
669
664
670
665
By default, WebDriver module is configured to automatically start browser before the test and stop afterward.
671
-
However, this can be switched off with `start: false` module configuration.
666
+
However, this can be switched off with `start: false` module configuration.
672
667
To start a browser you will need to write corresponding methods in Acceptance [Helper](http://codeception.com/docs/06-ModulesAndHelpers#Helpers).
673
668
674
669
WebDriver module provides advanced methods for the browser session, however, they can only be used from Helpers.
675
-
670
+
676
671
* [_initializeSession](http://codeception.com/docs/modules/WebDriver#_initializeSession) - starts a new browser session
677
672
* [_closeSession](http://codeception.com/docs/modules/WebDriver#_closeSession) - stops the browser session
678
673
* [_restart](http://codeception.com/docs/modules/WebDriver#_restart) - updates configuration and restarts browser
679
674
* [_capabilities](http://codeception.com/docs/modules/WebDriver#_capabilities) - set [desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities) programmatically.
680
675
681
-
Those methods can be used to create custom commands like `$I->startBrowser()` or used in [before/after](http://codeception.com/docs/06-ModulesAndHelpers#Hooks) hooks.
676
+
Those methods can be used to create custom commands like `$I->startBrowser()` or used in [before/after](http://codeception.com/docs/06-ModulesAndHelpers#Hooks) hooks.
0 commit comments