Skip to content

Commit

Permalink
Add filename to take_screenshot
Browse files Browse the repository at this point in the history
- Add find_objects POST
  • Loading branch information
dtmilano committed Jun 24, 2022
1 parent a5fa4bd commit 0cc4a9c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
6 changes: 4 additions & 2 deletions .idea/runConfigurations/culebra__GUh.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions .idea/runConfigurations/culebra__Guhc.xml

This file was deleted.

18 changes: 18 additions & 0 deletions examples/helper/screenshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env python3
"""
Copyright (C) 2022 Diego Torres Milano
Created on Jun 24, 2022
@author: diego
"""

import sys

from com.dtmilano.android.viewclient import ViewClient

if len(sys.argv) != 2:
sys.exit("usage: %s filename.png" % sys.argv[0])

filename = sys.argv.pop(1)
helper = ViewClient(*ViewClient.connectToDeviceOrExit(), useuiautomatorhelper=True).uiAutomatorHelper
helper.ui_device.take_screenshot(filename=filename)
38 changes: 28 additions & 10 deletions src/com/dtmilano/android/uiautomator/uiautomatorhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from __future__ import print_function

__version__ = '21.10.2'
__version__ = '21.11.0'

import json
import os
Expand Down Expand Up @@ -416,12 +416,18 @@ def find_object(self, **kwargs):
def find_objects(self, **kwargs):
"""
Finds objects.
Invokes GET or POST method depending on the arguments passed.
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
:param kwargs:
:return:
"""
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_get(**kwargs)
if 'body' in kwargs:
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_post(**kwargs)
if 'by_selector' in kwargs:
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_get(**kwargs)
body = culebratester_client.Selector(**kwargs)
return self.uiAutomatorHelper.api_instance.ui_device_find_objects_post(body=body)

def press_back(self):
"""
Expand Down Expand Up @@ -475,18 +481,30 @@ def swipe(self, **kwargs):
body = culebratester_client.SwipeBody(**kwargs)
return self.uiAutomatorHelper.api_instance.ui_device_swipe_post(body=body)

def take_screenshot(self, scale=1.0, quality=90, **kwargs):
def take_screenshot(self, scale=1.0, quality=90, filename=None, **kwargs):
"""
Takes screenshot.
Eventually save it in a file specified by filename.
:see https://github.com/dtmilano/CulebraTester2-public/blob/master/openapi.yaml
:param scale:
:param quality:
:param kwargs:
:return:
"""
return self.uiAutomatorHelper.api_instance.ui_device_screenshot_get(scale=scale, quality=quality,
_preload_content=False, **kwargs)
:param scale: the scale
:param quality: the quality
:param filename: if specified the image will be saved in filename
:param kwargs: optional arguments
:return: the response containing the image binary if the filename was not specified
"""
if filename:
img = self.uiAutomatorHelper.api_instance.ui_device_screenshot_get(scale=scale,
quality=quality,
_preload_content=False,
**kwargs).read()
with open(filename, 'wb') as file:
file.write(img)
return
return self.uiAutomatorHelper.api_instance.ui_device_screenshot_get(scale=scale,
quality=quality,
_preload_content=False,
**kwargs)

def wait(self, search_condition_ref: int, timeout=10000):
"""
Expand Down

0 comments on commit 0cc4a9c

Please sign in to comment.