Created
January 28, 2026 19:25
-
-
Save celsowm/de3d084c359449735823b4a80a96d1b0 to your computer and use it in GitHub Desktop.
test.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require 'vendor/autoload.php'; | |
| use Playwright\Playwright; | |
| // Inicializa o Playwright | |
| $playwright = Playwright::create(); | |
| $browser = $playwright->chromium()->launch(['headless' => false]); // false para você ver o processo | |
| $context = $browser->newContext(); | |
| $page = $context->newPage(); | |
| try { | |
| // 1. Navega para o seu IP Local (ex: servidor de desenvolvimento ou roteador) | |
| // Pode ser http://localhost:8000, http://192.168.1.50, etc. | |
| $urlLocal = 'http://127.0.0.1:8000/login'; | |
| $page->goto($urlLocal); | |
| echo "Navegando para $urlLocal...\n"; | |
| // 2. Preenche as credenciais | |
| // Ajuste os seletores ('#email', 'input[name="password"]') conforme o seu HTML | |
| $page->fill('input[name="username"]', 'admin'); // ou o seletor ID: #username | |
| $page->fill('input[name="password"]', 'senha_secreta_123'); | |
| // 3. Clica no botão de entrar | |
| // Você pode usar o texto do botão ou o seletors CSS | |
| $page->click('button[type="submit"]'); | |
| // 4. Verificação pós-login | |
| // É importante esperar algo que só aparece depois do login (ex: um menu ou dashboard) | |
| $page->waitForSelector('.dashboard-welcome', ['timeout' => 5000]); | |
| // 5. Opcional: Verificar se a URL mudou para a home/dashboard | |
| if (str_contains($page->url(), '/dashboard')) { | |
| echo "Login realizado com sucesso! Atual: " . $page->url() . "\n"; | |
| } | |
| // Tira um print da área logada | |
| $page->screenshot(['path' => 'area_logada.png']); | |
| } catch (Exception $e) { | |
| echo "Erro durante o teste: " . $e->getMessage() . "\n"; | |
| $page->screenshot(['path' => 'erro_login.png']); | |
| } finally { | |
| $browser->close(); | |
| $playwright->close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment