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

fix: Add waiting time for chart animation when screenshot #15610

Merged
merged 2 commits into from Jul 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/config.py
Expand Up @@ -493,6 +493,8 @@ def _try_json_readsha( # pylint: disable=unused-argument
SCREENSHOT_SELENIUM_RETRIES = 5
# Give selenium an headstart, in seconds
SCREENSHOT_SELENIUM_HEADSTART = 3
# Wait for the chart animation, in seconds
SCREENSHOT_SELENIUM_ANIMATION_WAIT = 5

# ---------------------------------------------------
# Image and file configuration
Expand Down
5 changes: 5 additions & 0 deletions superset/utils/webdriver.py
Expand Up @@ -120,6 +120,11 @@ def get_screenshot(
(By.CLASS_NAME, "slice_container")
)
)
selenium_animation_wait = current_app.config[
"SCREENSHOT_SELENIUM_ANIMATION_WAIT"
]
logger.debug("Wait %i seconds for chart animation", selenium_animation_wait)
sleep(selenium_animation_wait)
logger.info("Taking a PNG screenshot or url %s", url)
img = element.screenshot_as_png
except TimeoutException:
Expand Down
15 changes: 15 additions & 0 deletions tests/integration_tests/thumbnails_tests.py
Expand Up @@ -102,6 +102,21 @@ def test_screenshot_selenium_load_wait(self, mock_webdriver, mock_webdriver_wait
webdriver.get_screenshot(url, "chart-container", user=user)
assert mock_webdriver_wait.call_args_list[1] == call(ANY, 15)

@patch("superset.utils.webdriver.WebDriverWait")
@patch("superset.utils.webdriver.firefox")
@patch("superset.utils.webdriver.sleep")
def test_screenshot_selenium_animation_wait(
self, mock_sleep, mock_webdriver, mock_webdriver_wait
):
webdriver = WebDriverProxy("firefox")
user = security_manager.get_user_by_username(
app.config["THUMBNAIL_SELENIUM_USER"]
)
url = get_url_path("Superset.slice", slice_id=1, standalone="true")
app.config["SCREENSHOT_SELENIUM_ANIMATION_WAIT"] = 4
webdriver.get_screenshot(url, "chart-container", user=user)
assert mock_sleep.call_args_list[1] == call(4)


class TestThumbnails(SupersetTestCase):

Expand Down