Skip to content

Commit 0cc4a9c

Browse files
committed
Add filename to take_screenshot
- Add find_objects POST
1 parent a5fa4bd commit 0cc4a9c

File tree

4 files changed

+50
-33
lines changed

4 files changed

+50
-33
lines changed

.idea/runConfigurations/culebra__GUh.xml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/culebra__Guhc.xml

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/helper/screenshot.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /usr/bin/env python3
2+
"""
3+
Copyright (C) 2022 Diego Torres Milano
4+
Created on Jun 24, 2022
5+
6+
@author: diego
7+
"""
8+
9+
import sys
10+
11+
from com.dtmilano.android.viewclient import ViewClient
12+
13+
if len(sys.argv) != 2:
14+
sys.exit("usage: %s filename.png" % sys.argv[0])
15+
16+
filename = sys.argv.pop(1)
17+
helper = ViewClient(*ViewClient.connectToDeviceOrExit(), useuiautomatorhelper=True).uiAutomatorHelper
18+
helper.ui_device.take_screenshot(filename=filename)

src/com/dtmilano/android/uiautomator/uiautomatorhelper.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from __future__ import print_function
2222

23-
__version__ = '21.10.2'
23+
__version__ = '21.11.0'
2424

2525
import json
2626
import os
@@ -416,12 +416,18 @@ def find_object(self, **kwargs):
416416
def find_objects(self, **kwargs):
417417
"""
418418
Finds objects.
419+
Invokes GET or POST method depending on the arguments passed.
419420
420421
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
421422
:param kwargs:
422423
:return:
423424
"""
424-
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_get(**kwargs)
425+
if 'body' in kwargs:
426+
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_post(**kwargs)
427+
if 'by_selector' in kwargs:
428+
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_get(**kwargs)
429+
body = culebratester_client.Selector(**kwargs)
430+
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_post(body=body)
425431

426432
def press_back(self):
427433
"""
@@ -475,18 +481,30 @@ def swipe(self, **kwargs):
475481
body = culebratester_client.SwipeBody(**kwargs)
476482
return self.uiAutomatorHelper.api_instance.ui_device_swipe_post(body=body)
477483

478-
def take_screenshot(self, scale=1.0, quality=90, **kwargs):
484+
def take_screenshot(self, scale=1.0, quality=90, filename=None, **kwargs):
479485
"""
480486
Takes screenshot.
487+
Eventually save it in a file specified by filename.
481488
482489
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
483-
:param scale:
484-
:param quality:
485-
:param kwargs:
486-
:return:
487-
"""
488-
return self.uiAutomatorHelper.api_instance.ui_device_screenshot_get(scale=scale, quality=quality,
489-
_preload_content=False, **kwargs)
490+
:param scale: the scale
491+
:param quality: the quality
492+
:param filename: if specified the image will be saved in filename
493+
:param kwargs: optional arguments
494+
:return: the response containing the image binary if the filename was not specified
495+
"""
496+
if filename:
497+
img = self.uiAutomatorHelper.api_instance.ui_device_screenshot_get(scale=scale,
498+
quality=quality,
499+
_preload_content=False,
500+
**kwargs).read()
501+
with open(filename, 'wb') as file:
502+
file.write(img)
503+
return
504+
return self.uiAutomatorHelper.api_instance.ui_device_screenshot_get(scale=scale,
505+
quality=quality,
506+
_preload_content=False,
507+
**kwargs)
490508

491509
def wait(self, search_condition_ref: int, timeout=10000):
492510
"""

0 commit comments

Comments
 (0)