Skip to content

Commit b1a2f0c

Browse files
authored
Merge pull request LambdaTest#1364 from JeeveshJ7/stage
SmartUI Capture Browser Queries Support
2 parents f19d043 + 10ee787 commit b1a2f0c

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

docs/smartui-cli.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Please read the following table for more information about the configuration fil
208208
| Config Key | Description | Usage |
209209
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------- | --------- |
210210
| browsers | You can add all the supported browsers brands here to run your tests for SmartUI. <br/> Ex: `"chrome", "firefox", "safari", "edge", etc..` | Mandatory |
211-
| resolutions | You can add all the supported browser viewpoints here to run your tests for SmartUI <br/> Ex: `[1920, 1080],[width, height] etc..` <br/> | Mandatory |
211+
| viewports | You can add all the supported browser viewpoints here to run your tests for SmartUI <br/> Ex: `[1920, 1080],[width, height] etc..` <br/> | Mandatory |
212212

213213

214214
## **Step 5:** Execute the Tests on SmartUI Cloud using CLI
@@ -219,6 +219,47 @@ You can now execute tests for `Visual Regression Testing` using the following op
219219
npx smartui capture urls.json --config .smartui.json
220220
```
221221

222+
## Executing browser scripts using the Capture Command
223+
224+
SmartUI CLI provides the flexibility to execute custom JavaScript code on target URLs at specific stages of the snapshot process. This feature is crucial for:
225+
226+
- Interacting with dynamic elements
227+
- Managing loading states
228+
- Modifying page content
229+
- Validating page states
230+
- Performing actions like accepting cookies, clicking on buttons, etc.
231+
These capabilities ensure that your visual tests accurately capture the true representation of your web pages.
232+
233+
You can execute any valid JavaScript code that you would typically run inside a browser. For example, to simulate a button click, you might use:
234+
235+
```js
236+
document.querySelector('.my-button-example').click();
237+
```
238+
239+
### Execute Option Keys
240+
241+
The `execute` option accepts an object with the following keys:
242+
243+
- **afterNavigation**: This function is called after the page navigates to the specified URL. It is useful for actions that need to occur once the page has loaded.
244+
245+
- **beforeSnapshot**: This function is called just before SmartUI captures a snapshot. It is ideal for final adjustments or interactions needed to prepare the page for capture.
246+
247+
Example usage in a configuration:
248+
249+
```json
250+
{
251+
"name": "Example Page",
252+
"url": "https://example.com/",
253+
"waitForTimeout": 3000,
254+
"execute": {
255+
"afterNavigation": "await page.waitForSelector('.loading', { hidden: true })",
256+
"beforeSnapshot": "document.querySelector('.cookie-banner').click()"
257+
}
258+
}
259+
```
260+
261+
This example waits for a loading element to disappear after navigation and clicks a cookie banner before taking a snapshot.
262+
222263
## Fetch results
223264

224265
You can fetch build results by adding the `--fetch-results` flag to your test execution command. Here are different ways to use this feature:

0 commit comments

Comments
 (0)