PHP code example of thelemon2020 / pest-plugin-pom
1. Go to this page and download the library: Download thelemon2020/pest-plugin-pom 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/ */
thelemon2020 / pest-plugin-pom example snippets
return [
'path' => 'tests/Browser/Pages',
];
namespace Tests\Browser\Pages;
use Thelemon2020\PestPom\Page;
use Thelemon2020\PestPom\Concerns\InteractsWithForms;
class LoginPage extends Page
{
use InteractsWithForms;
public static function url(): string
{
return '/login';
}
public function loginAs(string $email, string $password): static
{
return $this
->fillForm(['Email' => $email, 'Password' => $password])
->submitForm('Log in');
}
}
$page = page(LoginPage::class);
// or
$page = LoginPage::open();
class ProductPage extends Page
{
public static function url(): string
{
return '/products/{id}';
}
}
ProductPage::open(['id' => 42]);
$page->navigateTo(ProductPage::class, ['id' => 42]);
// explicit navigation
$page->navigateTo(DashboardPage::class);
// after a redirect
$page->submitForm('Log in')->nowOn(DashboardPage::class);
it('allows a user to log in', function () {
page(LoginPage::class)
->loginAs('[email protected]', 'password')
->assertSee('Dashboard');
});
namespace Tests\Browser\Components;
use Thelemon2020\PestPom\Component;
class SearchBarComponent extends Component
{
public static function selector(): string
{
return '#search-bar';
}
public function search(string $query): static
{
return $this
->fill('input[name=query]', $query)
->click('button[type=submit]');
}
}