PHP code example of skylerkatz / phpunit-plugin-browser
1. Go to this page and download the library: Download skylerkatz/phpunit-plugin-browser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
skylerkatz / phpunit-plugin-browser example snippets
namespace Tests\Browser;
use SkylerKatz\PHPUnitBrowser\BrowserTestCase;
class ExampleTest extends BrowserTestCase
{
public function test_homepage(): void
{
$this->visit('http://localhost:8000')
->assertTitle('My App')
->assertSee('Welcome');
}
}
public function test_login(): void
{
$this->visit('http://localhost:8000/login')
->type('email', '[email protected]')
->type('password', 'secret')
->press('Sign In')
->assertUrlIs('http://localhost:8000/dashboard')
->assertSee('Welcome back');
}
public function test_form_fields(): void
{
$this->visit('http://localhost:8000/settings')
->select('country', 'US')
->check('terms')
->radio('plan', 'pro')
->press('Save');
}
use SkylerKatz\PHPUnitBrowser\Enums\Device;
public function test_mobile_layout(): void
{
$this->visit('http://localhost:8000')
->fromDevice(Device::IPHONE_15_PRO)
->assertVisible('.mobile-menu');
}
public function test_dark_mode(): void
{
$this->visit('http://localhost:8000')
->inDarkMode()
->assertScreenshotMatches();
}
public function test_visual_regression(): void
{
$this->visit('http://localhost:8000')
->assertScreenshotMatches();
// Full-page screenshot
$this->visit('http://localhost:8000')
->assertScreenshotMatches(fullPage: true);
}
public function test_javascript(): void
{
$this->visit('http://localhost:8000')
->script('return document.title')
->assertScript('window.appVersion', '2.0');
}
public function test_multiple_pages(): void
{
$this->visit([
'http://localhost:8000',
'http://localhost:8000/about',
])->assertSee('Welcome');
}
public function test_iframe_content(): void
{
$this->visit('http://localhost:8000')
->withinFrame('.iframe', function ($frame) {
$frame->assertSee('Frame content');
});
}
use SkylerKatz\PHPUnitBrowser\Playwright\Playwright;
use SkylerKatz\PHPUnitBrowser\Enums\BrowserType;
use SkylerKatz\PHPUnitBrowser\Enums\ColorScheme;
protected function setUp(): void
{
parent::setUp();
Playwright::headed();
Playwright::setTimeout(10000);
Playwright::setDefaultBrowserType(BrowserType::FIREFOX);
Playwright::setColorScheme(ColorScheme::DARK);
Playwright::setUserAgent('Custom User Agent');
}