Skip to content

Percy runner #923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 20 additions & 9 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 @@ -447,14 +451,21 @@ def reset_log_timestamp(self):
if entries:
self._last_ts = entries[-1]["timestamp"]

def visit_and_snapshot(self, resource_path, hook_id):
def visit_and_snapshot(self, resource_path, hook_id, assert_check=True):
try:
self.driver.get(self.server_url + resource_path)
path = resource_path.lstrip('/')
if path != resource_path:
logger.warning("we stripped the left '/' in resource_path")
self.driver.get("{}/{}".format(self.server_url.rstrip('/'), path))
self.wait_for_element_by_id(hook_id)
self.percy_snapshot(resource_path)
self.percy_snapshot(path)
if assert_check:
assert not self.driver.find_elements_by_css_selector(
"div.dash-debug-alert"
), "devtools should not raise an error alert"
self.driver.back()
except WebDriverException as e:
logger.exception("snapshot at resource %s error", resource_path)
logger.exception("snapshot at resource %s error", path)
raise e

@property
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