|
1 | 1 | --- |
2 | 2 | title: "Verification Actions" |
3 | | -description: "Learn how to verify page content and state using Auto-Browse" |
| 3 | +description: "Learn how to verify element states and content using Auto-Browse's assertions" |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Verification Actions |
7 | 7 |
|
8 | | -Auto-Browse provides natural language commands for verifying page content, element states, and application behavior. This guide covers various verification scenarios and best practices. |
| 8 | +Auto-Browse provides a set of core assertions for verifying element states and content. These natural language commands make it easy to validate your application's behavior. |
9 | 9 |
|
10 | | -## Basic Verification |
| 10 | +## Supported Assertions |
11 | 11 |
|
12 | | -Verify page elements and content: |
| 12 | +Auto-Browse currently supports four fundamental assertion types: |
13 | 13 |
|
14 | | -```typescript |
15 | | -// Check element presence |
16 | | -await auto("verify the login button is visible"); |
17 | | -await auto("check if error message is displayed"); |
18 | | - |
19 | | -// Verify text content |
20 | | -await auto('verify page title is "Welcome"'); |
21 | | -await auto("check if success message contains order number"); |
22 | | -``` |
23 | | - |
24 | | -## Element State Verification |
25 | | - |
26 | | -### Visibility States |
27 | | - |
28 | | -```typescript |
29 | | -// Basic visibility |
30 | | -await auto("verify the menu is visible"); |
31 | | -await auto("check if loading spinner is hidden"); |
32 | | - |
33 | | -// Conditional visibility |
34 | | -await auto("verify tooltip appears on hover"); |
35 | | -await auto("check if dropdown opens when clicked"); |
36 | | -``` |
37 | | - |
38 | | -### Element Properties |
| 14 | +### Element Visibility |
39 | 15 |
|
40 | | -```typescript |
41 | | -// Attribute verification |
42 | | -await auto('verify submit button is "disabled"'); |
43 | | -await auto("check if input field is required"); |
44 | | - |
45 | | -// Class verification |
46 | | -await auto("verify error class is applied"); |
47 | | -await auto("check if menu item is active"); |
48 | | -``` |
49 | | - |
50 | | -### Input States |
| 16 | +Check if elements are visible on the page: |
51 | 17 |
|
52 | 18 | ```typescript |
53 | | -// Form field values |
54 | | -await auto('verify email field contains "user@example.com"'); |
55 | | -await auto("check if password field is empty"); |
| 19 | +// Verify element visibility |
| 20 | +await auto("verify the login button is visible"); |
| 21 | +await auto("check if error message is displayed"); |
56 | 22 |
|
57 | | -// Selection states |
58 | | -await auto('verify "Terms" checkbox is checked'); |
59 | | -await auto('check if "Express Shipping" is selected'); |
| 23 | +// Wait and verify |
| 24 | +await auto("wait for loading spinner to disappear"); |
| 25 | +await auto("verify success message becomes visible"); |
60 | 26 | ``` |
61 | 27 |
|
62 | | -## Content Verification |
63 | | - |
64 | 28 | ### Text Content |
65 | 29 |
|
| 30 | +Verify the text content of elements: |
| 31 | + |
66 | 32 | ```typescript |
67 | 33 | // Exact text matching |
68 | 34 | await auto('verify heading text is "Welcome"'); |
69 | | -await auto('check if error says "Invalid input"'); |
| 35 | +await auto('check if error message says "Invalid input"'); |
70 | 36 |
|
71 | | -// Partial text matching |
72 | | -await auto("verify message contains order ID"); |
73 | | -await auto("check if description includes product name"); |
| 37 | +// Dynamic content |
| 38 | +await auto("verify message contains order number"); |
| 39 | +await auto("check if username is displayed correctly"); |
74 | 40 | ``` |
75 | 41 |
|
76 | | -### Rich Content |
77 | | - |
78 | | -```typescript |
79 | | -// HTML content |
80 | | -await auto("verify formatted text is bold"); |
81 | | -await auto("check if link contains correct href"); |
82 | | - |
83 | | -// Media content |
84 | | -await auto("verify image is loaded"); |
85 | | -await auto("check if video is playing"); |
86 | | -``` |
| 42 | +### Element State |
87 | 43 |
|
88 | | -## Page State Verification |
89 | | - |
90 | | -### URL Verification |
91 | | - |
92 | | -```typescript |
93 | | -// Basic URL checks |
94 | | -await auto("verify URL is /dashboard"); |
95 | | -await auto("check if URL contains user ID"); |
96 | | - |
97 | | -// Query parameters |
98 | | -await auto('verify search parameter is "active"'); |
99 | | -await auto("check if filter parameters are correct"); |
100 | | -``` |
101 | | - |
102 | | -### Document State |
| 44 | +Check if elements are enabled: |
103 | 45 |
|
104 | 46 | ```typescript |
105 | | -// Page load state |
106 | | -await auto("verify page is fully loaded"); |
107 | | -await auto("check if all resources are loaded"); |
| 47 | +// Button states |
| 48 | +await auto("verify submit button is enabled"); |
| 49 | +await auto("check if save button is clickable"); |
108 | 50 |
|
109 | | -// Document properties |
110 | | -await auto("verify page title is correct"); |
111 | | -await auto("check if meta description is set"); |
| 51 | +// Input field states |
| 52 | +await auto("verify email field is enabled"); |
| 53 | +await auto("check if password field is active"); |
112 | 54 | ``` |
113 | 55 |
|
114 | | -## Dynamic Content Verification |
| 56 | +### Checkbox/Radio State |
115 | 57 |
|
116 | | -### Loading States |
| 58 | +Verify if checkboxes or radio buttons are checked: |
117 | 59 |
|
118 | 60 | ```typescript |
119 | | -// Loading indicators |
120 | | -await auto("verify loading state is complete"); |
121 | | -await auto("check if skeleton loader is hidden"); |
| 61 | +// Checkbox verification |
| 62 | +await auto('verify "Remember me" checkbox is checked'); |
| 63 | +await auto('check if "Terms" box is selected'); |
122 | 64 |
|
123 | | -// Content updates |
124 | | -await auto("verify new content is loaded"); |
125 | | -await auto("check if list is updated"); |
126 | | -``` |
127 | | - |
128 | | -### Async Operations |
129 | | - |
130 | | -```typescript |
131 | | -// Operation completion |
132 | | -await auto("verify form submission completed"); |
133 | | -await auto("check if data is saved"); |
134 | | - |
135 | | -// State transitions |
136 | | -await auto("verify transition is complete"); |
137 | | -await auto("check if animation finished"); |
| 65 | +// Radio button verification |
| 66 | +await auto('verify "Express shipping" is selected'); |
| 67 | +await auto('check if "Credit card" option is checked'); |
138 | 68 | ``` |
139 | 69 |
|
140 | 70 | ## Best Practices |
141 | 71 |
|
142 | | -### 1. Clear Assertions |
| 72 | +### 1. Clear and Specific Assertions |
143 | 73 |
|
144 | 74 | ```typescript |
145 | | -// Good - Specific and clear |
146 | | -await auto("verify login button shows 'Sign In'"); |
| 75 | +// Good - Clear what to verify |
| 76 | +await auto('verify login button shows "Sign In"'); |
| 77 | +await auto("check if error message is visible"); |
147 | 78 |
|
148 | 79 | // Less Clear - Ambiguous |
149 | | -await auto("check button text"); |
| 80 | +await auto("verify button"); |
| 81 | +await auto("check text"); |
150 | 82 | ``` |
151 | 83 |
|
152 | | -### 2. Proper Waiting |
| 84 | +### 2. Proper Wait States |
153 | 85 |
|
154 | 86 | ```typescript |
155 | 87 | // Good - Waits for state |
156 | | -await auto("verify data loads and table shows 10 rows"); |
| 88 | +await auto("wait for button to be enabled then verify"); |
| 89 | +await auto("verify message appears after loading"); |
157 | 90 |
|
158 | | -// Better - With explicit waiting |
159 | | -await auto("wait for table to load"); |
160 | | -await auto("verify table has 10 rows"); |
| 91 | +// Not Recommended - No wait |
| 92 | +await auto("verify button is enabled"); |
161 | 93 | ``` |
162 | 94 |
|
163 | | -### 3. Error Messages |
| 95 | +### 3. Error Handling |
164 | 96 |
|
165 | 97 | ```typescript |
166 | | -// Good - Descriptive error state |
167 | | -await auto('verify error shows "Please enter valid email"'); |
168 | | - |
169 | | -// Better - With state check |
170 | | -await auto("verify email field shows error state"); |
171 | | -await auto("check if error message is correct"); |
| 98 | +try { |
| 99 | + await auto("verify form submission succeeded"); |
| 100 | +} catch (error) { |
| 101 | + // Handle specific assertion failures |
| 102 | + if (error.message.includes("not visible")) { |
| 103 | + await auto("check if error message is shown"); |
| 104 | + } |
| 105 | +} |
172 | 106 | ``` |
173 | 107 |
|
174 | 108 | ## Common Patterns |
175 | 109 |
|
176 | 110 | ### 1. Form Validation |
177 | 111 |
|
178 | 112 | ```typescript |
179 | | -async function verifyFormValidation() { |
| 113 | +async function validateForm() { |
180 | 114 | // Check initial state |
181 | | - await auto("verify form is empty"); |
| 115 | + await auto("verify submit button is enabled"); |
182 | 116 |
|
183 | 117 | // Submit empty form |
184 | 118 | await auto("click submit"); |
185 | | - await auto("verify required field errors are shown"); |
186 | | - |
187 | | - // Fill invalid data |
188 | | - await auto('type "invalid" in email field'); |
189 | | - await auto("verify email format error is shown"); |
| 119 | + await auto("verify error message is visible"); |
| 120 | + await auto('check if error says "Required fields missing"'); |
190 | 121 | } |
191 | 122 | ``` |
192 | 123 |
|
193 | | -### 2. Navigation State |
| 124 | +### 2. Login Flow |
194 | 125 |
|
195 | 126 | ```typescript |
196 | | -async function verifyNavigation() { |
197 | | - // Check navigation state |
198 | | - await auto("verify current page is dashboard"); |
199 | | - await auto("check if active menu item is correct"); |
| 127 | +async function verifyLogin() { |
| 128 | + // Pre-login state |
| 129 | + await auto("verify login button is visible"); |
200 | 130 |
|
201 | | - // Verify breadcrumbs |
202 | | - await auto("verify breadcrumb shows correct path"); |
| 131 | + // After login |
| 132 | + await auto('type "user@example.com" in email'); |
| 133 | + await auto('type "password" in password'); |
| 134 | + await auto("click login"); |
| 135 | + await auto("verify welcome message is visible"); |
203 | 136 | } |
204 | 137 | ``` |
205 | 138 |
|
206 | | -### 3. Data Display |
| 139 | +### 3. Interactive Elements |
207 | 140 |
|
208 | 141 | ```typescript |
209 | | -async function verifyDataDisplay() { |
210 | | - // Check data loading |
211 | | - await auto("verify data table is populated"); |
212 | | - await auto("check if sorting is applied"); |
213 | | - |
214 | | - // Verify content |
215 | | - await auto("verify all columns are visible"); |
216 | | - await auto("check if data formatting is correct"); |
217 | | -} |
218 | | -``` |
| 142 | +async function verifyInteractions() { |
| 143 | + // Button states |
| 144 | + await auto("verify button is enabled"); |
| 145 | + await auto("click button"); |
219 | 146 |
|
220 | | -## Error Handling |
221 | | - |
222 | | -Handle verification failures: |
223 | | - |
224 | | -```typescript |
225 | | -try { |
226 | | - await auto("verify payment is processed"); |
227 | | -} catch (error) { |
228 | | - // Check for specific failure cases |
229 | | - await auto("check if payment is pending"); |
230 | | - await auto("verify no error message is shown"); |
| 147 | + // Checkbox interactions |
| 148 | + await auto("click remember me checkbox"); |
| 149 | + await auto("verify checkbox is checked"); |
231 | 150 | } |
232 | 151 | ``` |
233 | 152 |
|
234 | 153 | ## Troubleshooting |
235 | 154 |
|
236 | 155 | Common verification issues and solutions: |
237 | 156 |
|
238 | | -1. **Timing Issues** |
| 157 | +1. **Visibility Issues** |
239 | 158 |
|
240 | 159 | ```typescript |
241 | | -// Handle async content |
242 | | -await auto("wait for content to stabilize"); |
243 | | -await auto("verify content is updated"); |
| 160 | +// Handle element visibility |
| 161 | +await auto("scroll element into view"); |
| 162 | +await auto("verify element is visible"); |
244 | 163 | ``` |
245 | 164 |
|
246 | | -2. **State Inconsistencies** |
| 165 | +2. **Timing Issues** |
247 | 166 |
|
248 | 167 | ```typescript |
249 | | -// Reset and retry |
250 | | -await auto("refresh the page"); |
251 | | -await auto("verify expected state"); |
| 168 | +// Handle loading states |
| 169 | +await auto("wait for loading to complete"); |
| 170 | +await auto("verify content is visible"); |
252 | 171 | ``` |
253 | 172 |
|
254 | | -3. **Dynamic Content** |
| 173 | +3. **State Changes** |
255 | 174 |
|
256 | 175 | ```typescript |
257 | | -// Handle changing content |
258 | | -await auto("wait for dynamic content"); |
259 | | -await auto("verify content matches pattern"); |
| 176 | +// Handle dynamic states |
| 177 | +await auto("click to change state"); |
| 178 | +await auto("verify new state is correct"); |
260 | 179 | ``` |
261 | 180 |
|
262 | 181 | ## Next Steps |
263 | 182 |
|
264 | 183 | - Learn about [Form Actions](/actions/forms) |
265 | 184 | - Explore [Navigation](/actions/navigation) |
266 | | -- Check out [Error Handling](/actions/troubleshooting) |
| 185 | +- Check out other [Action Types](/actions/clicking) |
0 commit comments