Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dash/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Added

- [#923](https://github.com/plotly/dash/pull/923) Adds one configuration `--percy-assets` in `pytest` to specify extra application assets path if needed

- [#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
the default waitress one) and optional `start_timeout` argument to handle large application within process runner

Expand Down
1 change: 1 addition & 0 deletions dash/testing/application_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def start(
except (OSError, ValueError):
logger.exception("process server has encountered an error")
self.started = False
self.stop()
return

self.started = True
Expand Down
17 changes: 12 additions & 5 deletions dash/testing/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def __init__(
remote_url=None,
headless=False,
options=None,
download_path=None,
download_path="",
percy_finalize=True,
percy_assets_root="",
wait_timeout=10,
):
self._browser = browser.lower()
Expand Down Expand Up @@ -67,14 +68,17 @@ def __init__(
loader=percy.ResourceLoader(
webdriver=self.driver,
base_url="/assets",
root_dir="tests/assets",
root_dir=percy_assets_root,
)
)
self.percy_runner.initialize_build()

logger.debug("initialize browser with arguments")
logger.debug(" headless => %s", self._headless)
logger.debug(" download_path => %s", self._download_path)
logger.info("initialize browser with arguments")
logger.info(" headless => %s", self._headless)
logger.info(" download_path => %s", self._download_path)
logger.info(
" percy asset root => %s", os.path.abspath(percy_assets_root)
)

def __enter__(self):
return self
Expand Down Expand Up @@ -452,6 +456,9 @@ def visit_and_snapshot(self, resource_path, hook_id):
self.driver.get(self.server_url + resource_path)
self.wait_for_element_by_id(hook_id)
self.percy_snapshot(resource_path)
assert not self.driver.find_elements_by_css_selector(
"div.dash-debug-alert"
), "devtools should not raise an error alert"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though, might need an option to disable this in case someone wants to snapshot the errors

Copy link
Contributor Author

@byronz byronz Sep 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2019-09-13 at 11 54 45 PM
🎉 works like a charm

self.driver.back()
except WebDriverException as e:
logger.exception("snapshot at resource %s error", resource_path)
Expand Down
10 changes: 10 additions & 0 deletions dash/testing/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def pytest_addoption(parser):
help="set this flag to run in headless mode",
)

dash.addoption(
"--percy-assets",
action="store",
default='tests/assets',
help="configure how Percy will discover your app's assets"
)

dash.addoption(
"--nopercyfinalize",
action="store_false",
Expand Down Expand Up @@ -117,6 +124,7 @@ def dash_br(request, tmpdir):
headless=request.config.getoption("headless"),
options=request.config.hook.pytest_setup_options(),
download_path=tmpdir.mkdir("download").strpath,
percy_assets_root=request.config.getoption("percy_assets"),
percy_finalize=request.config.getoption("nopercyfinalize"),
) as browser:
yield browser
Expand All @@ -132,6 +140,7 @@ def dash_duo(request, dash_thread_server, tmpdir):
headless=request.config.getoption("headless"),
options=request.config.hook.pytest_setup_options(),
download_path=tmpdir.mkdir("download").strpath,
percy_assets_root=request.config.getoption("percy_assets"),
percy_finalize=request.config.getoption("nopercyfinalize"),
) as dc:
yield dc
Expand All @@ -147,6 +156,7 @@ def dashr(request, dashr_server, tmpdir):
headless=request.config.getoption("headless"),
options=request.config.hook.pytest_setup_options(),
download_path=tmpdir.mkdir("download").strpath,
percy_assets_root=request.config.getoption("percy_assets"),
percy_finalize=request.config.getoption("nopercyfinalize"),
) as dc:
yield dc