You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: webqa_agent/llm/prompt.py
+72-3Lines changed: 72 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -83,13 +83,44 @@ class LLMPrompt:
83
83
- All plans must reflect actual context in screenshot.
84
84
- Always output strict **valid JSON**. No comments or markdown.
85
85
86
+
## Navigation Strategy Guidelines (CRITICAL)
87
+
88
+
### Action Selection Priority for Navigation
89
+
When planning navigation actions, follow this STRICT priority order:
90
+
91
+
1. **GoToPage (HIGHEST RELIABILITY - PREFERRED)**
92
+
- Use when: Target URL is known or can be determined
93
+
- Best for: Returning to original tabs/pages, switching between known pages, going to homepage
94
+
- Reliability: 100% - Direct URL manipulation, no UI dependency
95
+
- Example: Returning to original tab with known URL
96
+
97
+
2. **GoBack (HIGH RELIABILITY)**
98
+
- Use when: Browser history navigation is appropriate
99
+
- Best for: Sequential backward navigation
100
+
- Reliability: 95% - Browser-native functionality
101
+
- Example: Returning to previous form after submission
102
+
103
+
3. **Tap/Click (LOWER RELIABILITY - USE WITH CAUTION)**
104
+
- Use when: Target URL is unknown AND element interaction is required
105
+
- Best for: Discovering new pages, triggering dynamic content
106
+
- Reliability: 60-80% - Depends on element state, page load, icon behavior
107
+
- Example: Clicking unexplored menu items
108
+
109
+
### Critical Decision Rule
110
+
**IF you know the target URL → ALWAYS use GoToPage over Tap**
111
+
- This includes: returning to original tab, going to homepage, switching between tabs
112
+
- Rationale: URL navigation is deterministic, UI element clicks are probabilistic
113
+
86
114
## Actions
87
115
88
116
Each action includes `type` and `param`, optionally with `locate`.
89
117
90
118
Each action has a
91
-
- type: 'Tap', tap the located element
119
+
- type: 'Tap', tap the located element [USE ONLY WHEN URL UNKNOWN]
92
120
* {{ locate: {{ id: string }}, param: null }}
121
+
* WARNING: Less reliable for navigation - UI elements may fail or behave inconsistently
122
+
* Use ONLY when: target URL is unknown AND you need to discover new pages
123
+
* Do NOT use for: returning to known pages, switching tabs when URLs are available
93
124
- type: 'Hover', move mouse over to the located element
94
125
* {{ locate: {{ id: string }}, param: null }}
95
126
- type: 'Input', replace the value in the input field
@@ -116,9 +147,12 @@ class LLMPrompt:
116
147
- type: 'GetNewPage', get the new page
117
148
* {{ param: null }}
118
149
* use this action when the instruction is a "get new page" statement or "open in new tab" or "open in new window".
119
-
- type: 'GoToPage', navigate directly to a specific URL
150
+
- type: 'GoToPage', navigate directly to a specific URL [PREFERRED FOR RELIABLE NAVIGATION]
120
151
* {{ param: {{ url: string }} }}
121
-
* use this action when you need to navigate to a specific web page URL, useful for returning to homepage or navigating to known pages.
152
+
* CRITICAL: This is the MOST RELIABLE navigation method - use whenever target URL is known
153
+
* PREFERRED for: returning to original tab/page, switching between known pages, going to homepage
154
+
* AVOID clicking UI elements (logos, icons) for navigation when URL is available
155
+
* Example: To return to original tab, use GoToPage with the original URL instead of clicking browser tabs or page icons
122
156
- type: 'GoBack', navigate back to the previous page
123
157
* {{ param: null }}
124
158
* use this action when you need to go back to the previous page in the browser history, similar to clicking the browser's back button.
@@ -412,6 +446,41 @@ class LLMPrompt:
412
446
}
413
447
```
414
448
449
+
#### Example 8: Return to Original Tab/Page (CRITICAL PATTERN)
450
+
"Return to the original tab/page where we started"
451
+
```json
452
+
{
453
+
"actions": [
454
+
{
455
+
"type": "GoToPage",
456
+
"thought": "Using GoToPage for guaranteed navigation back to original URL. This is more reliable than clicking UI elements which may fail or behave unpredictably.",
- Include recovery steps taken for future test improvement
222
269
- Maintain clear audit trail of all actions performed
223
270
271
+
## Structured Error Reporting Protocol
272
+
273
+
**Critical Rule**: For failures that should immediately stop test execution, you MUST use structured error tags to ensure reliable detection.
274
+
275
+
### Critical Error Format
276
+
When encountering critical failures, include structured tags: **[CRITICAL_ERROR:category]** followed by detailed description.
277
+
278
+
### Critical Error Categories
279
+
- **ELEMENT_NOT_FOUND**: Target element cannot be located, accessed, or interacted with
280
+
- **NAVIGATION_FAILED**: Page navigation, loading, or routing failures
281
+
- **PERMISSION_DENIED**: Access, authorization, or security restriction issues
282
+
- **PAGE_CRASHED**: Browser crashes, page errors, or unrecoverable page states
283
+
- **NETWORK_ERROR**: Network connectivity, timeout, or server communication issues
284
+
- **SESSION_EXPIRED**: Authentication session, login, or credential issues
285
+
286
+
### Critical Error Examples
287
+
**Element Access Failure**:
288
+
`[CRITICAL_ERROR:ELEMENT_NOT_FOUND] The language selector dropdown could not be located in the navigation bar. The element was not found in the page buffer and cannot be interacted with.`
289
+
290
+
**Navigation Issue**:
291
+
`[CRITICAL_ERROR:NAVIGATION_FAILED] Page navigation to the target URL failed due to network timeout. The page is not accessible and the test cannot continue.`
292
+
293
+
**Permission Issue**:
294
+
`[CRITICAL_ERROR:PERMISSION_DENIED] Access to the admin panel was denied. User lacks sufficient privileges to proceed with the test.`
295
+
296
+
### Non-Critical Failures
297
+
Standard failures that allow test continuation should use the regular `[FAILURE]` format without structured tags. These include:
298
+
- Validation errors that can be corrected
299
+
- Dropdown option mismatches with alternatives available
300
+
- Minor UI state changes that don't block core functionality
0 commit comments