Codeception Testing Skill
Core Patterns
Acceptance Test (Cest)
<?php
// tests/Acceptance/LoginCest.php
class LoginCest
{
public function _before(AcceptanceTester $I)
{
$I->amOnPage('/login');
}
public function loginWithValidCredentials(AcceptanceTester $I)
{
$I->fillField('email', 'user@test.com');
$I->fillField('password', 'password123');
$I->click('Login');
$I->see('Dashboard');
$I->seeInCurrentUrl('/dashboard');
$I->seeElement('.welcome-message');
}
public function loginWithInvalidCredentials(AcceptanceTester $I)
{
$I->fillField('email', 'wrong@test.com');
$I->fillField('password', 'wrong');
$I->click('Login');
$I->see('Invalid credentials');
$I->seeInCurrentUrl('/login');
}
}
Actor Methods (AcceptanceTester $I)
// Navigation
$I->amOnPage('/path');
$I->click('Button Text');
$I->click('#id');
$I->click(['xpath' => '//button']);
// Forms
$I->fillField('Name or Label', 'value');
$I->selectOption('Select', 'Option');
$I->checkOption('Checkbox');
$I->uncheckOption('Checkbox');
$I->attachFile('Upload', 'file.txt');
$I->submitForm('#form', ['email' => 'test@x.com']);
// Assertions
$I->see('Text');
$I->dontSee('Text');
$I->seeElement('#id');
$I->dontSeeElement('.error');
$I->seeInField('email', 'expected@value.com');
$I->seeInCurrentUrl('/dashboard');
$I->seeInTitle('Page Title');
$I->seeCheckboxIsChecked('#agree');
$I->seeNumberOfElements('li', 5);
// Grabbers
$text = $I->grabTextFrom('.element');
$attr = $I->grabAttributeFrom('#link', 'href');
$value = $I->grabValueFrom('#input');
Page Objects (Step Objects)
<?php
// tests/_support/Page/Login.php
namespace Page;
class Login
{
public static $url = '/login';
public static $emailField = '#email';
public static $passwordField = '#password';
public static $loginButton = 'button[type="submit"]';
protected $I;
public function __construct(\AcceptanceTester $I) { $this->I = $I; }
public function login(string $email, string $password): void
{
$this->I->amOnPage(self::$url);
$this->I->fillField(self::$emailField, $email);
$this->I->fillField(self::$passwordField, $password);
$this->I->click(self::$loginButton);
}
}
Cloud (TestMu AI)
Full setup: reference/cloud-integration.md. Capabilities reference: shared/testmu-cloud-reference.md.
Cloud Config (acceptance.suite.yml)
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost:3000'
host: 'hub.lambdatest.com'
port: 80
browser: chrome
capabilities:
'LT:Options':
user: '%LT_USERNAME%'
accessKey: '%LT_ACCESS_KEY%'
build: 'Codeception Build'
video: true
Setup: composer require --dev codeception/codeception codeception/module-webdriver
Init: php vendor/bin/codecept bootstrap
Run: php vendor/bin/codecept run acceptance
Deep Patterns
See reference/playbook.md for production-grade patterns:
| Section |
What You Get |
| §1 Project Setup |
Installation, codeception.yml, suite configurations |
| §2 Acceptance Tests |
Cest pattern, @dataProvider, WebDriver interactions |
| §3 API Tests |
REST module, CRUD operations, @depends, HttpCode |
| §4 Page Objects |
Page class with static selectors, reusable methods |
| §5 Database Testing |
haveInDatabase, seeInDatabase, updateInDatabase |
| §6 Custom Helpers |
Custom module extending Codeception Module |
| §7 CI/CD Integration |
GitHub Actions with MySQL, Selenium, coverage |
| §8 Debugging Table |
12 common problems with causes and fixes |
| §9 Best Practices |
14-item Codeception testing checklist |
1---
2name: codeception-skill
3description: >
4 Generates Codeception tests in PHP covering acceptance, functional, and unit
5 testing. BDD-style with Actor pattern. Use when user mentions "Codeception",
6 "$I->amOnPage", "$I->see", "Cest". Triggers on: "Codeception", "$I->amOnPage",
7 "AcceptanceTester", "Codeception PHP", "Cest".
8languages:
9 - PHP
10category: e2e-testing
11license: MIT
12metadata:
13 source: https://skillmd.com/skills/lambdatest/codeception-skill
14 author: TestMu AI
15 version: "1.0"
16---
17
18# Codeception Testing Skill
19
20## Core Patterns
21
22### Acceptance Test (Cest)
23
24```php
25<?php
26// tests/Acceptance/LoginCest.php
27
28class LoginCest
29{
30 public function _before(AcceptanceTester $I)
31 {
32 $I->amOnPage('/login');
33 }
34
35 public function loginWithValidCredentials(AcceptanceTester $I)
36 {
37 $I->fillField('email', 'user@test.com');
38 $I->fillField('password', 'password123');
39 $I->click('Login');
40 $I->see('Dashboard');
41 $I->seeInCurrentUrl('/dashboard');
42 $I->seeElement('.welcome-message');
43 }
44
45 public function loginWithInvalidCredentials(AcceptanceTester $I)
46 {
47 $I->fillField('email', 'wrong@test.com');
48 $I->fillField('password', 'wrong');
49 $I->click('Login');
50 $I->see('Invalid credentials');
51 $I->seeInCurrentUrl('/login');
52 }
53}
54```
55
56### Actor Methods (AcceptanceTester $I)
57
58```php
59// Navigation
60$I->amOnPage('/path');
61$I->click('Button Text');
62$I->click('#id');
63$I->click(['xpath' => '//button']);
64
65// Forms
66$I->fillField('Name or Label', 'value');
67$I->selectOption('Select', 'Option');
68$I->checkOption('Checkbox');
69$I->uncheckOption('Checkbox');
70$I->attachFile('Upload', 'file.txt');
71$I->submitForm('#form', ['email' => 'test@x.com']);
72
73// Assertions
74$I->see('Text');
75$I->dontSee('Text');
76$I->seeElement('#id');
77$I->dontSeeElement('.error');
78$I->seeInField('email', 'expected@value.com');
79$I->seeInCurrentUrl('/dashboard');
80$I->seeInTitle('Page Title');
81$I->seeCheckboxIsChecked('#agree');
82$I->seeNumberOfElements('li', 5);
83
84// Grabbers
85$text = $I->grabTextFrom('.element');
86$attr = $I->grabAttributeFrom('#link', 'href');
87$value = $I->grabValueFrom('#input');
88```
89
90### Page Objects (Step Objects)
91
92```php
93<?php
94// tests/_support/Page/Login.php
95namespace Page;
96
97class Login
98{
99 public static $url = '/login';
100 public static $emailField = '#email';
101 public static $passwordField = '#password';
102 public static $loginButton = 'button[type="submit"]';
103
104 protected $I;
105 public function __construct(\AcceptanceTester $I) { $this->I = $I; }
106
107 public function login(string $email, string $password): void
108 {
109 $this->I->amOnPage(self::$url);
110 $this->I->fillField(self::$emailField, $email);
111 $this->I->fillField(self::$passwordField, $password);
112 $this->I->click(self::$loginButton);
113 }
114}
115```
116
117### Cloud (TestMu AI)
118
119Full setup: [reference/cloud-integration.md](reference/cloud-integration.md). Capabilities reference: [shared/testmu-cloud-reference.md](../shared/testmu-cloud-reference.md).
120
121### Cloud Config (acceptance.suite.yml)
122
123```yaml
124actor: AcceptanceTester
125modules:
126 enabled:
127 - WebDriver:
128 url: 'http://localhost:3000'
129 host: 'hub.lambdatest.com'
130 port: 80
131 browser: chrome
132 capabilities:
133 'LT:Options':
134 user: '%LT_USERNAME%'
135 accessKey: '%LT_ACCESS_KEY%'
136 build: 'Codeception Build'
137 video: true
138```
139
140## Setup: `composer require --dev codeception/codeception codeception/module-webdriver`
141## Init: `php vendor/bin/codecept bootstrap`
142## Run: `php vendor/bin/codecept run acceptance`
143
144## Deep Patterns
145
146See `reference/playbook.md` for production-grade patterns:
147
148| Section | What You Get |
149|---------|-------------|
150| §1 Project Setup | Installation, codeception.yml, suite configurations |
151| §2 Acceptance Tests | Cest pattern, @dataProvider, WebDriver interactions |
152| §3 API Tests | REST module, CRUD operations, @depends, HttpCode |
153| §4 Page Objects | Page class with static selectors, reusable methods |
154| §5 Database Testing | haveInDatabase, seeInDatabase, updateInDatabase |
155| §6 Custom Helpers | Custom module extending Codeception Module |
156| §7 CI/CD Integration | GitHub Actions with MySQL, Selenium, coverage |
157| §8 Debugging Table | 12 common problems with causes and fixes |
158| §9 Best Practices | 14-item Codeception testing checklist |