Advanced Examples
Explore advanced testing scenarios and learn how to handle complex interactions with Chekov.
Complex Form Handling
Handle multi-step forms with validation and dynamic content:
1import { test } from '@playwright/test';2import { ai } from '@chekov/core';34test('complete multi-step registration form', async ({ page }) => {5await page.goto('/register');67// Step 1: Personal Information8await ai([9'Type "John Doe" in the full name field',10'Type "john@example.com" in the email field',11'Select "United States" from the country dropdown',12'Type "123 Main St" in the address field'13], { page, parallelism: 2 });1415await ai('Click the Next button', { page });16await ai('Verify we are on step 2', { page });1718// Step 2: Account Setup19await ai([20'Type "securepass123" in the password field',21'Type "securepass123" in the confirm password field',22'Check the terms and conditions checkbox',23'Select "Developer" from the role dropdown'24], { page, parallelism: 2 });2526await ai('Click the Next button', { page });27await ai('Verify we are on step 3', { page });2829// Step 3: Preferences30await ai([31'Select all notification preferences',32'Choose "Dark" theme from the theme selector',33'Select "GMT-8" from the timezone dropdown'34], { page, parallelism: 3 });3536await ai('Click the Complete Registration button', { page });37await ai('Verify the registration success message is shown', { page });38});
Dynamic Content Handling
Handle loading states, dynamic updates, and async content:
1test('handle dynamic data loading', async ({ page }) => {2await page.goto('/dashboard');34// Wait for initial load5await ai('Wait for the dashboard to fully load', { page });67// Load more data8await ai('Click the Load More button', { page });9await ai('Wait for new items to appear', { page });1011// Verify dynamic updates12await ai([13'Verify at least 10 items are visible',14'Verify the loading indicator is hidden',15'Verify the total count has increased'16], { page, parallelism: 3 });1718// Real-time updates19await ai([20'Click the Enable Real-time Updates toggle',21'Wait for the live data indicator to appear'22], { page });2324// Verify real-time updates25await ai('Verify new items appear automatically', { page });26});
Complex Interactions
Handle drag-and-drop, file uploads, and rich text editing:
1test('complex UI interactions', async ({ page }) => {2await page.goto('/editor');34// Rich text editing5await ai([6'Click the Rich Text Editor field',7'Type "Hello, World!" in the editor',8'Select the text we just typed'9], { page });1011await ai([12'Click the Bold button in the toolbar',13'Click the Text Color button',14'Select the red color from the color picker'15], { page });1617// File upload with preview18await page.setInputFiles('input[type="file"]', 'test-files/image.jpg');19await ai([20'Verify the image preview is visible',21'Verify the file name is shown',22'Verify the file size is displayed'23], { page, parallelism: 3 });2425// Drag and drop26await ai([27'Drag the image preview to the gallery section',28'Verify the image appears in the gallery',29'Verify the upload section is empty'30], { page });31});
State Management
Handle complex application states and side effects:
1test('manage complex application state', async ({ page }) => {2await page.goto('/app');34// Initialize app state5await ai([6'Open the settings panel',7'Enable experimental features',8'Enable dark mode',9'Set language to Spanish'10], { page, parallelism: 2 });1112// Verify state persistence13await ai('Reload the page', { page });14await ai([15'Verify experimental features are still enabled',16'Verify dark mode is still active',17'Verify language is still set to Spanish'18], { page, parallelism: 3 });1920// Handle side effects21await ai('Click the Clear Cache button', { page });22await ai([23'Verify the success message appears',24'Verify the cache size shows 0 bytes',25'Verify the last cleared timestamp is updated'26], { page });27});
Error Scenarios
Test various error conditions and recovery mechanisms:
1test('handle error scenarios', async ({ page }) => {2await page.goto('/dashboard');34// Simulate offline mode5await page.context().setOffline(true);6await ai([7'Click the Refresh Data button',8'Verify the offline error message is shown',9'Verify the retry button is visible'10], { page });1112// Test retry mechanism13await page.context().setOffline(false);14await ai('Click the Retry button', { page });15await ai('Verify the data is loaded successfully', { page });1617// Test error boundaries18await ai('Click the Trigger Error button', { page });19await ai([20'Verify the error boundary message is shown',21'Verify the error details are visible',22'Verify the reset button is available'23], { page, parallelism: 3 });2425// Recovery26await ai('Click the Reset Application button', { page });27await ai('Verify the application is back to normal state', { page });28});
Advanced Tips
- Use parallel actions for independent operations
- Implement proper error handling and recovery
- Test edge cases and error scenarios
- Verify state persistence and side effects
- Handle dynamic and asynchronous content
