@@ -106,6 +106,7 @@ def visit_and_snapshot(
106
106
convert_canvases = False ,
107
107
assert_check = True ,
108
108
stay_on_page = False ,
109
+ widths = None ,
109
110
):
110
111
try :
111
112
path = resource_path .lstrip ("/" )
@@ -119,6 +120,7 @@ def visit_and_snapshot(
119
120
path ,
120
121
wait_for_callbacks = wait_for_callbacks ,
121
122
convert_canvases = convert_canvases ,
123
+ widths = widths ,
122
124
)
123
125
if assert_check :
124
126
assert not self .driver .find_elements_by_css_selector (
@@ -130,10 +132,26 @@ def visit_and_snapshot(
130
132
logger .exception ("snapshot at resource %s error" , path )
131
133
raise e
132
134
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
+ ):
134
138
"""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]
136
152
"""
153
+ if widths is None :
154
+ widths = [375 , 1280 ]
137
155
snapshot_name = "{} - py{}.{}" .format (
138
156
name , sys .version_info .major , sys .version_info .minor
139
157
)
@@ -172,7 +190,7 @@ def percy_snapshot(self, name="", wait_for_callbacks=False, convert_canvases=Fal
172
190
"""
173
191
)
174
192
175
- self .percy_runner .snapshot (name = snapshot_name )
193
+ self .percy_runner .snapshot (name = snapshot_name , widths = widths )
176
194
177
195
self .driver .execute_script (
178
196
"""
@@ -189,7 +207,7 @@ def percy_snapshot(self, name="", wait_for_callbacks=False, convert_canvases=Fal
189
207
)
190
208
191
209
else :
192
- self .percy_runner .snapshot (name = snapshot_name )
210
+ self .percy_runner .snapshot (name = snapshot_name , widths = widths )
193
211
194
212
def take_snapshot (self , name ):
195
213
"""Hook method to take snapshot when a selenium test fails. The
0 commit comments