Skip to content
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

add two APIs #937

Merged
merged 6 commits into from
Sep 24, 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
6 changes: 6 additions & 0 deletions dash/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

### Added

- [#937](https://github.com/plotly/dash/pull/937) `dash.testing` adds two APIs `zoom_in_graph_by_ratio` and `click_at_coord_fractions` about advanced interactions using mouse `ActionChain`

## [1.3.1] - 2019-09-19
### Changed
- Bumped dash-core-components version from 1.2.0 to [1.2.1](https://github.com/plotly/dash-core-components/blob/master/CHANGELOG.md#120---2019-09-19)
Expand Down
37 changes: 34 additions & 3 deletions dash/testing/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains

from selenium.common.exceptions import WebDriverException, TimeoutException
from selenium.common.exceptions import (
WebDriverException,
TimeoutException,
MoveTargetOutOfBoundsException,
)

from dash.testing.wait import (
text_to_equal,
Expand Down Expand Up @@ -429,6 +433,33 @@ def clear_input(self, elem):
.send_keys(Keys.DELETE)
).perform()

def zoom_in_graph_by_ratio(
self, elem, start_fraction=0.5, zoom_box_fraction=0.2, compare=True
):
"""zoom out a graph with a zoom box fraction of component dimension
default start at middle with a rectangle of 1/5 of the dimension
use `compare` to control if we check the svg get changed
"""
prev = elem.get_attribute("innerHTML")
w, h = elem.size["width"], elem.size["height"]
try:
ActionChains(self.driver).move_to_element_with_offset(
elem, w * start_fraction, h * start_fraction
).drag_and_drop_by_offset(
elem, w * zoom_box_fraction, h * zoom_box_fraction
).perform()
except MoveTargetOutOfBoundsException:
logger.exception("graph offset outside of the boundary")
if compare:
assert prev != elem.get_attribute(
"innerHTML"
), "SVG content should be different after zoom"

def click_at_coord_fractions(self, elem, fx, fy):
ActionChains(self.driver).move_to_element_with_offset(
elem, elem.size["width"] * fx, elem.size["height"] * fy
).click().perform()

def get_logs(self):
"""return a list of `SEVERE` level logs after last reset time stamps
(default to 0, resettable by `reset_log_timestamp`. Chrome only
Expand All @@ -453,10 +484,10 @@ def reset_log_timestamp(self):

def visit_and_snapshot(self, resource_path, hook_id, assert_check=True):
try:
path = resource_path.lstrip('/')
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.driver.get("{}/{}".format(self.server_url.rstrip("/"), path))
self.wait_for_element_by_id(hook_id)
self.percy_snapshot(path)
if assert_check:
Expand Down