|
48 | 48 | Take screenshots to confirm the page renders correctly: |
49 | 49 |
|
50 | 50 | ``` |
51 | | -vendor/bin/pest --ai="$this->visit('/')->screenshot(filename: 'homepage');" |
52 | | -vendor/bin/pest --ai="$this->visit('/dashboard')->screenshot(filename: 'dashboard', fullPage: true);" |
53 | | -vendor/bin/pest --ai="$this->visit('/')->screenshotElement('.hero', filename: 'hero-section');" |
| 51 | +vendor/bin/pest --ai="visit('/')->screenshot(filename: 'homepage');" |
| 52 | +vendor/bin/pest --ai="visit('/dashboard')->screenshot(filename: 'dashboard', fullPage: true);" |
| 53 | +vendor/bin/pest --ai="visit('/')->screenshotElement('.hero', filename: 'hero-section');" |
54 | 54 | ``` |
55 | 55 |
|
56 | 56 | Assert page content and element state: |
57 | 57 |
|
58 | 58 | ``` |
59 | | -vendor/bin/pest --ai="$this->visit('/')->assertSee('Welcome');" |
60 | | -vendor/bin/pest --ai="$this->visit('/login')->assertPresent('input[name=email]');" |
61 | | -vendor/bin/pest --ai="$this->visit('/')->assertVisible('.navbar');" |
| 59 | +vendor/bin/pest --ai="visit('/')->assertSee('Welcome');" |
| 60 | +vendor/bin/pest --ai="visit('/login')->assertPresent('input[name=email]');" |
| 61 | +vendor/bin/pest --ai="visit('/')->assertVisible('.navbar');" |
62 | 62 | ``` |
63 | 63 |
|
64 | 64 | Test responsiveness by emulating devices: |
65 | 65 |
|
66 | 66 | ``` |
67 | | -vendor/bin/pest --ai="$this->visit('/')->on()->mobile()->screenshot(filename: 'homepage-mobile');" |
68 | | -vendor/bin/pest --ai="$this->visit('/')->on()->iPhone14Pro()->screenshot(filename: 'homepage-iphone14pro');" |
69 | | -vendor/bin/pest --ai="$this->visit('/')->resize(375, 812)->screenshot(filename: 'homepage-375x812');" |
| 67 | +vendor/bin/pest --ai="visit('/')->on()->mobile()->screenshot(filename: 'homepage-mobile');" |
| 68 | +vendor/bin/pest --ai="visit('/')->on()->iPhone14Pro()->screenshot(filename: 'homepage-iphone14pro');" |
| 69 | +vendor/bin/pest --ai="visit('/')->resize(375, 812)->screenshot(filename: 'homepage-375x812');" |
70 | 70 | ``` |
71 | 71 |
|
72 | 72 | Verify interactions work: |
73 | 73 |
|
74 | 74 | ``` |
75 | | -vendor/bin/pest --ai="$this->visit('/')->click('Login')->assertPathIs('/login');" |
76 | | -vendor/bin/pest --ai="$this->visit('/contact')->type('email', 'test@example.com')->press('Send')->assertSee('Message sent');" |
| 75 | +vendor/bin/pest --ai="visit('/')->click('Login')->assertPathIs('/login');" |
| 76 | +vendor/bin/pest --ai="visit('/contact')->type('email', 'test@example.com')->press('Send')->assertSee('Message sent');" |
77 | 77 | ``` |
78 | 78 |
|
79 | 79 | Check for JavaScript errors and accessibility issues: |
80 | 80 |
|
81 | 81 | ``` |
82 | | -vendor/bin/pest --ai="$this->visit('/')->assertNoJavaScriptErrors();" |
83 | | -vendor/bin/pest --ai="$this->visit('/')->assertNoAccessibilityIssues();" |
| 82 | +vendor/bin/pest --ai="visit('/')->assertNoJavaScriptErrors();" |
| 83 | +vendor/bin/pest --ai="visit('/')->assertNoAccessibilityIssues();" |
84 | 84 | ``` |
85 | 85 |
|
86 | 86 | Visual regression testing to catch unintended UI changes: |
87 | 87 |
|
88 | 88 | ``` |
89 | | -vendor/bin/pest --ai="$this->visit('/')->assertScreenshotMatches();" |
| 89 | +vendor/bin/pest --ai="visit('/')->assertScreenshotMatches();" |
90 | 90 | ``` |
91 | 91 |
|
92 | 92 | ### Combining Browser and Backend Assertions |
|
95 | 95 | - **Important:** Always assert a frontend change first (e.g. `assertSee`, `assertPathIs`) to confirm the action was processed before checking backend side effects. |
96 | 96 |
|
97 | 97 | ``` |
98 | | -vendor/bin/pest --ai="\Illuminate\Support\Facades\Mail::fake(); $this->visit('/contact')->type('email', 'test@example.com')->type('message', 'Hello')->press('Send')->assertSee('Message sent'); \Illuminate\Support\Facades\Mail::assertSent(\App\Mail\ContactForm::class);" |
| 98 | +vendor/bin/pest --ai="\Illuminate\Support\Facades\Mail::fake(); visit('/contact')->type('email', 'test@example.com')->type('message', 'Hello')->press('Send')->assertSee('Message sent'); \Illuminate\Support\Facades\Mail::assertSent(\App\Mail\ContactForm::class);" |
99 | 99 | ``` |
100 | 100 |
|
101 | 101 | ``` |
102 | | -vendor/bin/pest --ai="\Illuminate\Support\Facades\Notification::fake(); $this->visit('/register')->type('name', 'John')->type('email', 'john@example.com')->type('password', 'password')->press('Register')->assertPathIs('/dashboard'); \Illuminate\Support\Facades\Notification::assertSentTo(\App\Models\User::first(), \App\Notifications\WelcomeNotification::class);" |
| 102 | +vendor/bin/pest --ai="\Illuminate\Support\Facades\Notification::fake(); visit('/register')->type('name', 'John')->type('email', 'john@example.com')->type('password', 'password')->press('Register')->assertPathIs('/dashboard'); \Illuminate\Support\Facades\Notification::assertSentTo(\App\Models\User::first(), \App\Notifications\WelcomeNotification::class);" |
103 | 103 | ``` |
104 | 104 |
|
105 | 105 | ``` |
106 | | -vendor/bin/pest --ai="$this->visit('/checkout')->type('card', '4242424242424242')->press('Pay')->assertSee('Transaction processed'); expect(\App\Models\Order::count())->toBe(1);" |
| 106 | +vendor/bin/pest --ai="visit('/checkout')->type('card', '4242424242424242')->press('Pay')->assertSee('Transaction processed'); expect(\App\Models\Order::count())->toBe(1);" |
107 | 107 | ``` |
0 commit comments