plotly / plotly/dash

make `dash_duo.take_snapshot` more flexible

Open
#1,382 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

Is your feature request related to a problem? Please describe.

Seems like in dash.testing, calling dash_duo.take_snapshot enforces the directory name and the naming convention:
https://github.com/plotly/dash/blob/fed4a9123f5d0cf6213da157bb94f5e1900c3440/dash/testing/browser.py#L153-L171

Describe the solution you'd like

I think that giving the option to change the path and choose the exact name of the snapshot might be nice. Maybe something like this:

def take_snapshot(self, name, save_dir="/tmp/artifacts", append_session_id=True):
    """Hook method to take snapshot when a selenium test fails. The
    snapshot is placed under.
        - `/tmp/dash_artifacts` in linux
        - `%TEMP` in windows
    with a filename combining test case name and the
    running selenium session id
    """
    target = save_dir if not self._is_windows() else os.path.join(os.getenv("TEMP"), save_dir)
    try:
        os.makedirs(target, exist_ok=True)
    except OSError:
        logger.exception("cannot make artifacts")

    if append_session_id:
        name += str(self.session_id)
    
    name += ".png"

    self.driver.save_screenshot(
        os.path.join(target, name)
    )

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dash/testing/browser.py at the take_snapshot entry point linked in the issue, and read how the current directory and filename are assembled. Done means callers can choose the save path and exact snapshot name, with session ID appending remaining optional and the documented platform behavior preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.