Skip to content

Commit 59c3097

Browse files
authored
Merge branch 'main' into sauce-visual-cli-fix
2 parents bc66102 + 2e7bcee commit 59c3097

File tree

2 files changed

+106
-6
lines changed

2 files changed

+106
-6
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Sauce Visual allows selective diffing that permits to ignore changes from a certain kind (_more information [here](/visual-testing/selective-diffing/)_).
22

33
:::warning
4-
Selective diffing is only availble with `Balanced` diffing method **AND** with DOM capture enabled.
4+
Selective diffing is only available with `Balanced` diffing method **AND** with DOM capture enabled.
55
:::

docs/visual-testing/integrations/python.md

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_label: Python
55
import EnvironmentVariables from '../_partials/_environment-variables.md';
66
import PythonIntro from '../_partials/_python-shared-intro.md';
77
import SelectiveDiffing from '../_partials/_selective-diffing.md';
8-
import SelectiveDiffingGlobal from '../_partials/_selective-diffing-global.md';
8+
import FullPageLimit from '../_partials/_fullpage-limit.md';
99
import SelectiveDiffingRegion from '../_partials/_selective-diffing-region.md';
1010

1111
# Python Integration
@@ -96,14 +96,108 @@ client.create_snapshot_from_webdriver(
9696
client.finish_build()
9797
```
9898

99-
## Advanced usage
99+
## Visual Snapshot Options & Examples
100100

101-
### Environment variables
102101

103-
Below are the environment variables available in the Sauce Visual Python plugin. Keep in mind that the variables defined in code / configuration have precedence over these.
102+
### Full Page Screenshots
104103

105-
<EnvironmentVariables />
104+
By default, only the current viewport is capture when taking a screenshot. By passing a `FullPageConfig` instance in the `full_page_config` named param you can enable and customize the behavior for our scroll-and-stitch snapshots. View the `FullPageConfig` class in our [visual SDKs](https://github.com/saucelabs/visual-sdks/blob/main/visual-python/src/saucelabs_visual/typing.py) for up to date inline docs for all properties.
105+
106+
<FullPageLimit />
107+
108+
```python
109+
from saucelabs_visual.typing import FullPageConfig
110+
# ...
111+
visual_client.create_snapshot_from_webdriver(
112+
"Inventory Page",
113+
session_id=session_id,
114+
full_page_config=FullPageConfig(
115+
# Can customize full page behavior by customizing values here. Or omit completely to
116+
# disable full page screenshots:
117+
# ex:
118+
# scrollLimit=10,
119+
# hideAfterFirstScroll=['.fixed-header', '#cookie-banner']
120+
# delayAfterScrollMs=200,
121+
),
122+
)
123+
```
124+
125+
### DOM Capture
126+
127+
You can use the `capture_dom` named param with a value of `True` to enable DOM capture during a snapshot.
128+
129+
```python
130+
visual_client.create_snapshot_from_webdriver(
131+
"Inventory Page",
132+
session_id=session_id,
133+
capture_dom=True,
134+
)
135+
```
136+
137+
### Clip to an Element
138+
139+
If you'd like to test a specific component or area of a page you can use the `clip_selector` named param in combination with a CSS selector to clip the screenshot and DOM comparison. When enabled, we'll crop the screenshot to the coordinates of the element and constrain our DOM comparison to that area. We accept any `document.querySelector` compatible string / CSS selector as the value.
140+
141+
```python
142+
visual_client.create_snapshot_from_webdriver(
143+
"Inventory Page",
144+
session_id=session_id,
145+
clip_selector='.my-css-selector',
146+
)
147+
```
148+
149+
Alternatively, you can also pass an element directly if you've already queried one from selenium using the `clip_element` named param:
106150

151+
```python
152+
add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '.btn_inventory')
153+
visual_client.create_snapshot_from_webdriver(
154+
"Inventory Page",
155+
session_id=session_id,
156+
clip_element=add_to_cart_button,
157+
)
158+
```
159+
160+
### Ignore Regions
161+
162+
You can ignore one or more areas on the page by using the `ignore_regions` named param. Ignore regions accepts an array of full region definitions (width, height, x & y coordinates). We also support passing elements directly using the `ignore_elements` named param to bypass region calculation / creation. See below for examples for both.
163+
164+
Regions:
165+
166+
```python
167+
from saucelabs_visual.typing import IgnoreRegion
168+
# ...
169+
visual_client.create_snapshot_from_webdriver(
170+
"Inventory Page",
171+
session_id=session_id,
172+
# Use coordinates on a page to create manual regions.
173+
ignore_regions=[
174+
IgnoreRegion(x=100, y=100, width=100, height=100)
175+
],
176+
)
177+
```
178+
179+
Elements:
180+
181+
```python
182+
from saucelabs_visual.typing import IgnoreElementRegion
183+
# ...
184+
add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '.btn_inventory')
185+
visual_client.create_snapshot_from_webdriver(
186+
"Inventory Page",
187+
session_id=session_id,
188+
# Ignore certain areas of a page using elements / selectors.
189+
ignore_elements=[
190+
IgnoreElementRegion(
191+
# Ignore one or more elements returned by find_elements/find_element.
192+
element=driver.find_elements(By.CSS_SELECTOR, '.inventory_item_img'),
193+
),
194+
IgnoreElementRegion(
195+
# Can also pass an element that has been previously found via the driver
196+
element=add_to_cart_button,
197+
),
198+
],
199+
)
200+
```
107201

108202
### Selective Diffing
109203

@@ -135,6 +229,12 @@ Example:
135229
)
136230
```
137231

232+
## Environment variables
233+
234+
Below are the environment variables available in the Sauce Visual Python plugin. Keep in mind that the variables defined in code / configuration have precedence over these.
235+
236+
<EnvironmentVariables />
237+
138238
## Examples
139239

140240
Example projects are available [here](https://github.com/saucelabs/visual-examples/tree/main/python).

0 commit comments

Comments
 (0)