MCPcopy Index your code
hub / github.com/plotly/dash / percy_snapshot

Method percy_snapshot

dash/testing/browser.py:137–222  ·  view source on GitHub ↗

percy_snapshot - visual test api shortcut to `percy_runner.snapshot`. It also combines the snapshot `name` with the Python version, args: - name: combined with the python version to give the final snapshot name - wait_for_callbacks: default False, whether to wait for

(
        self, name="", wait_for_callbacks=False, convert_canvases=False, widths=None
    )

Source from the content-addressed store, hash-verified

135 raise e
136
137 def percy_snapshot(
138 self, name="", wait_for_callbacks=False, convert_canvases=False, widths=None
139 ):
140 """percy_snapshot - visual test api shortcut to `percy_runner.snapshot`.
141 It also combines the snapshot `name` with the Python version,
142 args:
143 - name: combined with the python version to give the final snapshot name
144 - wait_for_callbacks: default False, whether to wait for Dash callbacks,
145 after an extra second to ensure that any relevant callbacks have
146 been initiated
147 - convert_canvases: default False, whether to convert all canvas elements
148 in the DOM into static images for percy to see. They will be restored
149 after the snapshot is complete.
150 - widths: a list of pixel widths for percy to render the page with. Note
151 that this does not change the browser in which the DOM is constructed,
152 so the width will only affect CSS, not JS-driven layout.
153 Defaults to [1280]
154 """
155 if widths is None:
156 widths = [1280]
157 try:
158 import asgiref # pylint: disable=unused-import, import-outside-toplevel # noqa: F401, C0415
159
160 name += "_async"
161 except ImportError:
162 pass
163
164 logger.info("taking snapshot name => %s", name)
165 try:
166 if wait_for_callbacks:
167 # the extra one second sleep adds safe margin in the context
168 # of wait_for_callbacks
169 time.sleep(1)
170 until(self._wait_for_callbacks, timeout=40, poll=0.3)
171 except TestingTimeoutError:
172 # API will log the error but this TimeoutError should not block
173 # the test execution to continue and it will still do a snapshot
174 # as diff reference for the build run.
175 logger.error(
176 "wait_for_callbacks failed => status of invalid rqs %s",
177 self.redux_state_rqs,
178 )
179
180 if convert_canvases:
181 self.driver.execute_script(
182 """
183 const stash = window._canvasStash = [];
184 Array.from(document.querySelectorAll('canvas')).forEach(c => {
185 const i = document.createElement('img');
186 i.src = c.toDataURL();
187 i.width = c.width;
188 i.height = c.height;
189 i.setAttribute('style', c.getAttribute('style'));
190 i.className = c.className;
191 i.setAttribute('data-canvasnum', stash.length);
192 stash.push(c);
193 c.parentElement.insertBefore(i, c);
194 c.parentElement.removeChild(c);

Calls 2

untilFunction · 0.90
errorMethod · 0.45