Skip to content

Commit

Permalink
add fallback for screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jul 30, 2024
1 parent 5f3f142 commit f2c5d5e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,12 @@ def screenshot(self, filename: Optional[str] = None, format="pillow", display_id
"""
if display_id is None:
base64_data = self.jsonrpc.takeScreenshot(1, 80)
jpg_raw = base64.b64decode(base64_data)
pil_img = Image.open(io.BytesIO(jpg_raw))
# takeScreenshot may return None
if base64_data:
jpg_raw = base64.b64decode(base64_data)
pil_img = Image.open(io.BytesIO(jpg_raw))

Check warning on line 258 in uiautomator2/__init__.py

View check run for this annotation

Codecov / codecov/patch

uiautomator2/__init__.py#L257-L258

Added lines #L257 - L258 were not covered by tests
else:
pil_img = self._dev.screenshot(display_id=display_id)

Check warning on line 260 in uiautomator2/__init__.py

View check run for this annotation

Codecov / codecov/patch

uiautomator2/__init__.py#L260

Added line #L260 was not covered by tests
else:
pil_img = self._dev.screenshot(display_id=display_id)

Expand Down

0 comments on commit f2c5d5e

Please sign in to comment.