关于 codeception-skill
codeception-skill 为使用 Codeception 的测试人员提供测试编写与项目配置指引,涵盖验收、API、数据库测试及云端配置。
主要功能
- 01Cest 验收测试模式
- 02Actor 导航与表单操作
- 03页面对象与可复用步骤
- 04API 和数据库测试指引
- 05套件配置及 CI/CD 集成
适用场景
- 01编写登录流程验收测试
- 02通过 REST 模块测试 API
- 03验证数据库记录变更
- 04配置 WebDriver 云端测试
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ lambdatest/ agent-skills --skill codeception-skill安装后在 Claude Code 中输入/codeception-skill确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
reference/advanced-patterns.mdcloud-integration.mdplaybook.md详细介绍
Codeception 测试技能
核心模式
验收测试(Cest)
<?php
// tests/Acceptance/LoginCest.php
class LoginCest
{
public function _before(AcceptanceTester $I)
{
$I->amOnPage('/login');
}
public function loginWithValidCredentials(AcceptanceTester $I)
{
$I->fillField('email', '[email protected]');
$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', '[email protected]');
$I->fillField('password', 'wrong');
$I->click('Login');
$I->see('Invalid credentials');
$I->seeInCurrentUrl('/login');
}
}
Actor 方法(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' => '[email protected]']);
// Assertions
$I->see('Text');
$I->dontSee('Text');
$I->seeElement('#id');
$I->dontSeeElement('.error');
$I->seeInField('email', '[email protected]');
$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');
页面对象(步骤对象)
<?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);
}
}
云端(TestMu AI)
完整设置:reference/cloud-integration.md。功能参考:shared/testmu-cloud-reference.md。
云端配置(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
设置:composer require --dev codeception/codeception codeception/module-webdriver
初始化:php vendor/bin/codecept bootstrap
运行:php vendor/bin/codecept run acceptance
深入了解模式
有关适用于生产环境的模式,请参阅 reference/playbook.md:
| 章节 | 内容 |
|---|---|
| §1 项目设置 | 安装、codeception.yml、测试套件配置 |
| §2 验收测试 | Cest 模式、@dataProvider、WebDriver 交互 |
| §3 API 测试 | REST 模块、CRUD 操作、@depends、HttpCode |
| §4 页面对象 | 包含静态选择器和可复用方法的页面类 |
| §5 数据库测试 | haveInDatabase、seeInDatabase、updateInDatabase |
| §6 自定义辅助工具 | 扩展 Codeception Module 的自定义模块 |
| §7 CI/CD 集成 | 使用 MySQL、Selenium 和覆盖率的 GitHub Actions |
| §8 调试表 | 12 个常见问题及其原因和修复方法 |
| §9 最佳实践 | 包含 14 项的 Codeception 测试清单 |
评论
支持 Markdown