leeovery/laravel-playwright
Composer 安装命令:
composer require leeovery/laravel-playwright
包简介
Backend stuff for Playwright e2e tests
README 文档
README
Backend utilities for Playwright e2e tests. Provides HTTP endpoints and commands to control your Laravel application during testing - manage databases, factories, authentication, migrations, and environment configuration from your Playwright tests.
Requirements
- PHP 8.3+
- Laravel 11+
Installation
composer require leeovery/laravel-playwright --dev
Publish config and register service provider:
php artisan playwright:install
Configuration
The package config (config/playwright.php) includes:
- Environments: Control which environments expose the endpoints (default:
local,testing,playwright) - Route prefix: Customize the endpoint URL prefix (default:
__playwright__) - Middleware: Set middleware for routes (default:
web) - Environment files: Configure
.playwright.envfile handling - Factory settings: Map model aliases and configure factory behaviors
Create a .playwright.env file for test-specific environment variables.
Features
HTTP Endpoints
All endpoints are prefixed with __playwright__ (configurable) and protected by environment checks:
Database Management
POST /create-database- Create test databasePOST /drop-database- Drop test databasePOST /migrate- Run migrations (supports?fresh=1&seed=1)POST /truncate- Truncate specific tables
Factory & Authentication
POST /factory- Create model instances via factoriesPOST /login- Authenticate user (create or find existing)POST /logout- End sessionPOST /user- Get current authenticated user
Utilities
POST /artisan- Execute artisan commandsPOST /routes- Get application route listGET /csrf- Get CSRF tokenPOST /env-setup- Swap to.playwright.envPOST /env-teardown- Restore original.env
Artisan Commands
# Setup/teardown test environment php artisan playwright:env-setup php artisan playwright:env-teardown # Database operations php artisan db:create --database=playwright_test php artisan db:drop --database=playwright_test
Usage Example
From Playwright tests, interact with Laravel via HTTP:
// Setup environment await request.post("http://localhost/__playwright__/env-setup"); // Run migrations await request.post("http://localhost/__playwright__/migrate", { data: { fresh: true, seed: true }, }); // Create and login user const user = await request.post("http://localhost/__playwright__/factory", { data: { model: "User", state: ["verified"], attributes: { email: "test@example.com" }, }, }); await request.post("http://localhost/__playwright__/login", { data: { attributes: { email: "test@example.com" } }, }); // Teardown await request.post("http://localhost/__playwright__/env-teardown");
Factory State Parameters
Pass complex state parameters to factories:
// Fetch model and pass to state method data: { state: [ { createdBy: ["model.User:100"] }, // Fetch User with id=100 ]; } // Use param aliases (configure in config/playwright.php) data: { state: [{ endsAt: ["Carbon(2023-12-25 23:59:59)"] }]; }
Register param aliases in your service provider:
use Leeovery\LaravelPlaywright\Playwright; Playwright::paramAlias('Carbon', fn($date) => new Carbon($date));
Security
Important: This package exposes powerful endpoints that can manipulate your application. Only enable in non-production environments. The package includes middleware that blocks requests outside configured environments.
If you discover security issues, email me@leeovery.com.
Testing
composer test
composer test-coverage
Development
# Format code with Pint composer pint # Refactor code with Rector composer rector
Credits
License
MIT License. See License File for details.
leeovery/laravel-playwright 适用场景与选型建议
leeovery/laravel-playwright 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 176 次下载、GitHub Stars 达 8, 最近一次更新时间为 2022 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「leeovery」 「laravel-playwright」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 leeovery/laravel-playwright 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 leeovery/laravel-playwright 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 leeovery/laravel-playwright 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Mail driver for Laravel to send emails via the SendInBlue v3 API
Laravel Settings - Package for handling user settings with file based defaults and DB custom values.
Driver-based Newsletter provider for Laravel
Magic link generator for quick and safe auth with Laravel
A Laravel package to flash 1 or more messages to session, with the ability to override previous or future messages, and to cap messages so they only appear once per session, hour, day etc.
统计信息
- 总下载量: 176
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-26