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