Skip to content

Commit e4ea7a4

Browse files
authored
Merge pull request #923 from plotly/percy-runner
Percy runner
2 parents 9f1271b + e0519f3 commit e4ea7a4

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

dash/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Added
44

5+
- [#923](https://github.com/plotly/dash/pull/923) Adds one configuration `--percy-assets` in `pytest` to specify extra application assets path if needed
6+
57
- [#918](https://github.com/plotly/dash/pull/918) Adds `wait_for_element_by_id` and `visit_and_snapshot` APIs in browser, adds `raw_command` option (it also has higher priority than
68
the default waitress one) and optional `start_timeout` argument to handle large application within process runner
79

dash/testing/application_runners.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def start(
216216
except (OSError, ValueError):
217217
logger.exception("process server has encountered an error")
218218
self.started = False
219+
self.stop()
219220
return
220221

221222
self.started = True

dash/testing/browser.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def __init__(
3737
remote_url=None,
3838
headless=False,
3939
options=None,
40-
download_path=None,
40+
download_path="",
4141
percy_finalize=True,
42+
percy_assets_root="",
4243
wait_timeout=10,
4344
):
4445
self._browser = browser.lower()
@@ -67,14 +68,17 @@ def __init__(
6768
loader=percy.ResourceLoader(
6869
webdriver=self.driver,
6970
base_url="/assets",
70-
root_dir="tests/assets",
71+
root_dir=percy_assets_root,
7172
)
7273
)
7374
self.percy_runner.initialize_build()
7475

75-
logger.debug("initialize browser with arguments")
76-
logger.debug(" headless => %s", self._headless)
77-
logger.debug(" download_path => %s", self._download_path)
76+
logger.info("initialize browser with arguments")
77+
logger.info(" headless => %s", self._headless)
78+
logger.info(" download_path => %s", self._download_path)
79+
logger.info(
80+
" percy asset root => %s", os.path.abspath(percy_assets_root)
81+
)
7882

7983
def __enter__(self):
8084
return self
@@ -447,14 +451,21 @@ def reset_log_timestamp(self):
447451
if entries:
448452
self._last_ts = entries[-1]["timestamp"]
449453

450-
def visit_and_snapshot(self, resource_path, hook_id):
454+
def visit_and_snapshot(self, resource_path, hook_id, assert_check=True):
451455
try:
452-
self.driver.get(self.server_url + resource_path)
456+
path = resource_path.lstrip('/')
457+
if path != resource_path:
458+
logger.warning("we stripped the left '/' in resource_path")
459+
self.driver.get("{}/{}".format(self.server_url.rstrip('/'), path))
453460
self.wait_for_element_by_id(hook_id)
454-
self.percy_snapshot(resource_path)
461+
self.percy_snapshot(path)
462+
if assert_check:
463+
assert not self.driver.find_elements_by_css_selector(
464+
"div.dash-debug-alert"
465+
), "devtools should not raise an error alert"
455466
self.driver.back()
456467
except WebDriverException as e:
457-
logger.exception("snapshot at resource %s error", resource_path)
468+
logger.exception("snapshot at resource %s error", path)
458469
raise e
459470

460471
@property

dash/testing/plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ def pytest_addoption(parser):
4848
help="set this flag to run in headless mode",
4949
)
5050

51+
dash.addoption(
52+
"--percy-assets",
53+
action="store",
54+
default='tests/assets',
55+
help="configure how Percy will discover your app's assets"
56+
)
57+
5158
dash.addoption(
5259
"--nopercyfinalize",
5360
action="store_false",
@@ -117,6 +124,7 @@ def dash_br(request, tmpdir):
117124
headless=request.config.getoption("headless"),
118125
options=request.config.hook.pytest_setup_options(),
119126
download_path=tmpdir.mkdir("download").strpath,
127+
percy_assets_root=request.config.getoption("percy_assets"),
120128
percy_finalize=request.config.getoption("nopercyfinalize"),
121129
) as browser:
122130
yield browser
@@ -132,6 +140,7 @@ def dash_duo(request, dash_thread_server, tmpdir):
132140
headless=request.config.getoption("headless"),
133141
options=request.config.hook.pytest_setup_options(),
134142
download_path=tmpdir.mkdir("download").strpath,
143+
percy_assets_root=request.config.getoption("percy_assets"),
135144
percy_finalize=request.config.getoption("nopercyfinalize"),
136145
) as dc:
137146
yield dc
@@ -147,6 +156,7 @@ def dashr(request, dashr_server, tmpdir):
147156
headless=request.config.getoption("headless"),
148157
options=request.config.hook.pytest_setup_options(),
149158
download_path=tmpdir.mkdir("download").strpath,
159+
percy_assets_root=request.config.getoption("percy_assets"),
150160
percy_finalize=request.config.getoption("nopercyfinalize"),
151161
) as dc:
152162
yield dc

0 commit comments

Comments
 (0)