Skip to content

Commit 86e6d9a

Browse files
committed
widths param for percy_snapshot and visit_and_snapshot test methods
1 parent adf0c7e commit 86e6d9a

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

dash/testing/browser.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def visit_and_snapshot(
106106
convert_canvases=False,
107107
assert_check=True,
108108
stay_on_page=False,
109+
widths=None,
109110
):
110111
try:
111112
path = resource_path.lstrip("/")
@@ -119,6 +120,7 @@ def visit_and_snapshot(
119120
path,
120121
wait_for_callbacks=wait_for_callbacks,
121122
convert_canvases=convert_canvases,
123+
widths=widths,
122124
)
123125
if assert_check:
124126
assert not self.driver.find_elements_by_css_selector(
@@ -130,10 +132,26 @@ def visit_and_snapshot(
130132
logger.exception("snapshot at resource %s error", path)
131133
raise e
132134

133-
def percy_snapshot(self, name="", wait_for_callbacks=False, convert_canvases=False):
135+
def percy_snapshot(
136+
self, name="", wait_for_callbacks=False, convert_canvases=False, widths=None
137+
):
134138
"""percy_snapshot - visual test api shortcut to `percy_runner.snapshot`.
135-
It also combines the snapshot `name` with the Python version.
139+
It also combines the snapshot `name` with the Python version,
140+
args:
141+
- name: combined with the python version to give the final snapshot name
142+
- wait_for_callbacks: default False, whether to wait for Dash callbacks,
143+
after an extra second to ensure that any relevant callbacks have
144+
been initiated
145+
- convert_canvases: default False, whether to convert all canvas elements
146+
in the DOM into static images for percy to see. They will be restored
147+
after the snapshot is complete.
148+
- widths: a list of pixel widths for percy to render the page with. Note
149+
that this does not change the browser in which the DOM is constructed,
150+
so the width will only affect CSS, not JS-driven layout.
151+
Defaults to [375, 1280]
136152
"""
153+
if widths is None:
154+
widths = [375, 1280]
137155
snapshot_name = "{} - py{}.{}".format(
138156
name, sys.version_info.major, sys.version_info.minor
139157
)
@@ -172,7 +190,7 @@ def percy_snapshot(self, name="", wait_for_callbacks=False, convert_canvases=Fal
172190
"""
173191
)
174192

175-
self.percy_runner.snapshot(name=snapshot_name)
193+
self.percy_runner.snapshot(name=snapshot_name, widths=widths)
176194

177195
self.driver.execute_script(
178196
"""
@@ -189,7 +207,7 @@ def percy_snapshot(self, name="", wait_for_callbacks=False, convert_canvases=Fal
189207
)
190208

191209
else:
192-
self.percy_runner.snapshot(name=snapshot_name)
210+
self.percy_runner.snapshot(name=snapshot_name, widths=widths)
193211

194212
def take_snapshot(self, name):
195213
"""Hook method to take snapshot when a selenium test fails. The

0 commit comments

Comments
 (0)