Skip to content
Open
40 changes: 22 additions & 18 deletions docs/AcceptanceTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,33 +361,37 @@ In the next section, we will overview the most popular solutions.

### Local Setup

### Selenium Server
Codeception can control browsers either through Selenium Server or directly through a browser driver
(ChromeDriver for Chrome, GeckoDriver for Firefox).

[Selenium](https://www.selenium.dev) is required to launch and control browsers from Codeception.
Selenium Server is required to be installed and started before running tests.
#### Selenium Server

The fastest way of getting Selenium is using [selenium-standalone](https://www.npmjs.com/package/selenium-standalone) NodeJS Package.
It automatically installs Selenium and all required dependencies and starts server. It requires **NodeJS and Java** to be installed.
[Selenium](https://www.selenium.dev) Server starts browser sessions and passes commands from Codeception to them.
It requires **Java** to be installed. [Download](https://www.selenium.dev/downloads/) the latest Selenium Server jar
and launch it in standalone mode in a separate terminal:

```
npm install selenium-standalone -g
selenium-standalone install
```bash
java -jar selenium-server-<version>.jar standalone
```

Launch this command in a separate terminal:
There is no need to install ChromeDriver or GeckoDriver separately:
[Selenium Manager](https://www.selenium.dev/documentation/selenium_manager/) downloads the matching driver for the installed browser automatically.

```
selenium-standalone start
Alternatively, run Selenium Server with a browser inside Docker using the [official image](https://github.com/SeleniumHQ/docker-selenium):

```bash
docker run --net=host --shm-size 2g selenium/standalone-chrome
```

![](https://raw.githubusercontent.com/webdriverio/selenium-standalone/HEAD/screencast.gif)
> The [RunProcess](https://codeception.com/extensions#RunProcess) extension can start and stop Selenium automatically.

Now, you are ready to run WebDriver tests using Codeception.

> Alternatively, Selenium Server can be installed manually. [Download it](https://www.selenium.dev/downloads/) from the official site and launch a server with Java: `java -jar selenium-server-....jar`. In this case ChromeDriver and GeckoDriver must be installed separately.
#### ChromeDriver or GeckoDriver

* For more information refer to [Installation Instructions](https://codeception.com/docs/modules/WebDriver#Selenium-Recommended)
* Enable [RunProcess](https://codeception.com/extensions#RunProcess) extension to start/stop Selenium automatically *(optional)*.
If you don't plan to use Selenium, tests can be executed directly through ChromeDriver or GeckoDriver.
In this case the driver must be installed and started before running tests.
See the [WebDriver module reference](https://codeception.com/docs/modules/WebDriver#Local-Chrome-andor-Firefox) for how to start each driver and configure the module.


### Configuration
Expand Down Expand Up @@ -557,7 +561,7 @@ For more options see [`performOn()` reference](https://codeception.com/docs/modu
When a web site acts unpredictably you may need to react to that change.
This happens if a site is configured for A/B testing, or shows different popups, based on environment.

Since Codeception 3.0 you can have some actions to fail silently, if they are errored.
You can have some actions to fail silently, if they are errored.
Let's say, you open a page and sometimes there is a popup which should be closed.
We may try to hit the "close" button but if this action fails (no popup on page) we just continue the test.

Expand Down Expand Up @@ -634,8 +638,8 @@ class AcceptanceTester extends \Codeception\Actor

### Cloud Testing

Some environments are hard to reproduce manually, testing Internet Explorer 6-8 on Windows XP may be a hard thing,
especially if you don't have Windows XP installed. This is where Cloud Testing services come to help you.
Some environments are hard to reproduce manually, testing Safari on macOS or browsers on mobile devices may be a hard thing,
especially if you don't have such a device. This is where Cloud Testing services come to help you.
Services such as [SauceLabs](https://saucelabs.com), [BrowserStack](https://www.browserstack.com/)
and [others](https://codeception.com/docs/modules/WebDriver#Cloud-Testing) can create virtual machines on demand
and set up Selenium Server and the desired browser. Tests are executed on a remote machine in a cloud,
Expand Down
4 changes: 2 additions & 2 deletions docs/BDD.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Scenario --

INCOMPLETE
Step definition for `I have product with $600 price in my cart` not found in contexts
Step definition for `I have product with $1000 price` not found in contexts
Step definition for `I have product with $1000 price in my cart` not found in contexts
Step definition for `I go to checkout process` not found in contexts
Step definition for `I should see that total number of products is 2` not found in contexts
Step definition for `my order amount is $1600` not found in contexts
Expand Down Expand Up @@ -292,7 +292,7 @@ class AcceptanceTester extends \Codeception\Actor
```

Please note that `:num1` placeholder can be used for strings and numbers (may contain currency sign).
In current case `:num1` matches `$600` and `$num1` is assigned to be 600. If you need to receive exact string, wrap the value into quotes: `"600$"`
In current case `:num1` matches `$600` and `$num1` is assigned to be 600. If you need to receive exact string, wrap the value into quotes: `"$600"`

By default they throw Incomplete exceptions to ensure test with missing steps won't be accidentally marked as successful. We will need to implement those steps. As we are in acceptance suite we are probably using [PhpBrowser](https://codeception.com/docs/modules/PhpBrowser) or [WebDriver](https://codeception.com/docs/modules/WebDriver) modules. This means that we can use their methods inside Tester file, as we do with writing tests using `$I->`. You can use `amOnPage`, `click`, `see` methods inside a step definitions, so each Gherkin scenario step to be extended with basic Codeception steps. Let's show how it can be implemented in our case:

Expand Down
3 changes: 0 additions & 3 deletions docs/Codecoverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ That's ok for now. But what files should be present in final coverage report?
Pass an array of files or directory to include/exclude sections. The path ending with '\*' matches the directory.
Also you can use '\*' mask in a file name, i.e. `app/models/*Model.php` to match all models.

There is a shortcut if you don't need that complex filters:


```yaml
coverage:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion docs/ContinuousIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
8 changes: 6 additions & 2 deletions docs/Customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ you can execute all the tests in a single runner. Run the Codeception tests as u
php vendor/bin/codecept run
```

This will launch the test suites for all three applications and merge the reports from all of them.
This will launch the test suites for all included applications and merge the reports from all of them.
This is very useful when you run your tests on a Continuous Integration server
and you want to get a single report in JUnit and HTML format. The code coverage report will be merged too.

Expand Down Expand Up @@ -119,6 +119,8 @@ All listed events are available as constants in `Codeception\Events` class.

| Event | When? | Triggered by
|:--------------------:| --------------------------------------- | --------------------------:
| `module.init` | Before modules are initialized | [Suite, Settings](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/SuiteEvent.php)
| `suite.init` | After modules are initialized | [Suite, Settings](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/SuiteEvent.php)
| `suite.before` | Before suite is executed | [Suite, Settings](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/SuiteEvent.php)
| `test.start` | Before test is executed | [Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php)
| `test.before` | At the very beginning of test execution | [Codeception Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php)
Expand All @@ -129,6 +131,8 @@ All listed events are available as constants in `Codeception\Events` class.
| `test.error` | After test ended with error | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php)
| `test.incomplete` | After executing incomplete test | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php)
| `test.skipped` | After executing skipped test | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php)
| `test.warning` | After test ended with warning | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php)
| `test.useless` | After test performed no assertions | [Test, Fail](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/FailEvent.php)
| `test.success` | After executing successful test | [Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php)
| `test.after` | At the end of test execution | [Codeception Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php)
| `test.end` | After test execution | [Test](https://github.com/Codeception/Codeception/blob/main/src/Codeception/Event/TestEvent.php)
Expand Down Expand Up @@ -234,7 +238,7 @@ extensions:

The passed in configuration is accessible via the `config` property: `$this->config['param']`.

Check out a very basic extension [Notifier](https://github.com/Codeception/Notifier).
Check out the [extensions shipped with Codeception](https://github.com/Codeception/Codeception/tree/main/ext) for examples.

### Custom Commands

Expand Down
2 changes: 1 addition & 1 deletion docs/Data.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ modules:

Doctrine is also a popular ORM, unlike some others it implements the DataMapper pattern and is not bound to any framework.
The [Doctrine](https://codeception.com/docs/modules/Doctrine) module requires an `EntityManager` instance to work with.
It can be obtained from a Symfony framework or Zend Framework (configured with Doctrine):
It can be obtained from a Symfony framework or Laminas (configured with Doctrine):

```yaml
modules:
Expand Down
2 changes: 2 additions & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,10 @@ There are plenty of useful Codeception commands:
* `generate:helper` *filename* - Generates a sample Helper File
* `generate:pageobject` *suite* *filename* - Generates a sample Page object
* `generate:stepobject` *suite* *filename* - Generates a sample Step object
* `generate:snapshot` *suite* *filename* - Generates a sample Snapshot class
* `generate:environment` *env* - Generates a sample Environment configuration
* `generate:groupobject` *group* - Generates a sample Group Extension
* `generate:scenarios` *suite* - Generates text representation for all scenarios

## Conclusion

Expand Down
13 changes: 10 additions & 3 deletions docs/ModulesAndHelpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ Use `$this->config['parameter']` to get its value.

Modules can be dynamically configured from environment variables.
Parameter storage should be specified in the global `codeception.yml` configuration inside the `params` section.
Parameters can be loaded from environment vars, from yaml (Symfony format), .env (Laravel format), ini, or php files.
Parameters can be loaded from environment vars, from yaml (Symfony format), .env (Laravel format), ini, php, or xml files.

Use the `params` section of the global configuration file `codeception.yml` to specify how to load them.
You can specify several sources for parameters to be loaded from.
Expand All @@ -413,11 +413,11 @@ params:
- env # load params from environment vars
```

Example: load parameters from YAML file (Symfony):
Example: load parameters from YAML file:

```yaml
params:
- app/config/parameters.yml
- config/parameters.yml
```

Example: load parameters from php file (Yii)
Expand All @@ -427,6 +427,13 @@ params:
- config/params.php
```

Example: load parameters from XML file:

```yaml
params:
- config/parameters.xml
```

Example: load parameters from .Env files (Laravel):

```yaml
Expand Down
6 changes: 3 additions & 3 deletions docs/ParallelExecution.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In this guide we will overview possible options.
## Sharding

Minimal setup can be implemented by executing several independent CI jobs, each running a part of the tests.
Sharding in Codeception allows to combine stages 1 and 2 so tests could be split by groups on the fly.
Sharding in Codeception allows to combine the splitting and running stages (see [Building Pipeline](#Building-Pipeline)) so tests could be split by groups on the fly.
In this case a pipeline could be simplified to one stage with several jobs.

![](/images/codeception-sharding.png)
Expand Down Expand Up @@ -142,7 +142,7 @@ parallel:merge-results

#### Step 1: Split Tests

Codeception can organize tests into [groups](https://codeception.com/docs/AdvancedUsage#Groups). Starting from 2.0 it can load information about a group from a file. Sample text file with a list of file names can be treated as a dynamically configured group. Take a look into sample group file:
Codeception can organize tests into [groups](https://codeception.com/docs/AdvancedUsage#Groups). It can load information about a group from a file. Sample text file with a list of file names can be treated as a dynamically configured group. Take a look into sample group file:


```bash
Expand Down Expand Up @@ -212,7 +212,7 @@ php vendor/bin/codecept run Acceptance -g paracept_2

#### Step 2: Running Tests

At this point you should decide if tests are executed on the same job or use multiple jobs for them. We recommend using multiple jobs, as in this case the burden of parallelization goes to CI server. This makes a lot of sense as a single machine has limited resources. If you split tests into CI jobs, you are limited only to the number of agents (build servers) that the CI can provide. For cloud-based services like GitHub Actions, GitLab CI, CircleCI, etc, this number is unlimited.
At this point you should decide if tests are executed on the same job or use multiple jobs for them. We recommend using multiple jobs, as in this case the burden of parallelization goes to CI server. This makes a lot of sense as a single machine has limited resources. If you split tests into CI jobs, you are limited only to the number of agents (build servers) that the CI can provide. For cloud-based services like GitHub Actions, GitLab CI, CircleCI, etc, this number depends on your plan.

> Please refer to documentation of your CI platform to learn how to set up multiple jobs running in parallel. Then proceed to merging of results.

Expand Down
4 changes: 1 addition & 3 deletions docs/Reporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ layout: doc
title: Reporting - Codeception Docs
---



## Reporting
# Reporting

Clear reports give a picture of the current state of the system. Which tests are passed, which tests are failed, and if failed what was the reason. Reports may vary on the level of detail and by the technical information collected. Codeception provides built-in reporters and a customizable API to create your own reporter.

Expand Down
4 changes: 2 additions & 2 deletions docs/ReusingTestCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ This trait was created by running `codecept build` and is regenerated each time

## PageObjects

For acceptance and functional testing, we will not only need to have common actions being reused across different tests,
For acceptance testing, we will not only need to have common actions being reused across different tests,
we should have buttons, links and form fields being reused as well. For those cases we need to implement
the [PageObject pattern](https://www.selenium.dev/documentation/test_practices/encouraged/page_object_models/),
which is widely used by test automation engineers. The PageObject pattern represents a web page as a class
and the DOM elements on that page as its properties, and some basic interactions as its methods.
PageObjects are very important when you are developing a flexible architecture of your acceptance or functional tests.
PageObjects are very important when you are developing a flexible architecture of your acceptance tests.
Do not hard-code complex CSS or XPath locators in your tests but rather move them into PageObject classes.

Codeception can generate a PageObject class for you with command:
Expand Down
9 changes: 7 additions & 2 deletions docs/UnitTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ you will have issues figuring out what tests will be affected by the introductio
That's why it's pretty important not just to cover your application with unit tests, but make unit tests self-explanatory.
We do this for scenario-driven acceptance and functional tests, and we should do this for unit and integration tests as well.

For this case we have a stand-alone project [Specify](https://github.com/Codeception/Specify)
(which is included in the phar package) for writing specifications inside unit tests:
For this case we have a stand-alone project [Specify](https://github.com/Codeception/Specify) for writing specifications inside unit tests:

> Specify supports only PHPUnit 8 and 9.

```php
<?php
Expand Down Expand Up @@ -445,6 +446,8 @@ will not be reflected in other code blocks as it is marked with `@specify` annot
The more complicated your domain is the more explicit your tests should be. With [DomainAssert](https://github.com/Codeception/DomainAssert)
library you can easily create custom assertion methods for unit and integration tests.

> DomainAssert supports only PHPUnit 7 to 9.

It allows to reuse business rules inside assertion methods:

```php
Expand All @@ -471,6 +474,8 @@ With custom assertion methods you can improve readability of your tests and keep
Static methods, class methods, date and time functions can be easily replaced with AspectMock.
For instance, you can test singletons!

> The latest AspectMock release requires PHP 7.4 and PHPUnit 9, so it can't be installed together with Codeception 5.

```php
<?php
use AspectMock\Test as test;
Expand Down
Loading