Skip to content

Commit

Permalink
update atx-agent add api app_info, and app_icon
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Dec 10, 2018
1 parent a5c6594 commit 401ff55
Show file tree
Hide file tree
Showing 5 changed files with 789 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ d.app_stop_all()
d.app_stop_all(excludes=['com.examples.demo'])
```

### Get app info
```python
d.app_info("com.examples.demo")
# expect output
#{
# "mainActivity": "com.github.uiautomator.MainActivity",
# "label": "ATX",
# "versionName": "1.1.7",
# "versionCode": 1001007,
# "size":1760809
#}
# save app icon
img = d.app_icon("com.examples.demo")
img.save("icon.png")
```
### Push and pull files
* push a file to the device

Expand Down
41 changes: 41 additions & 0 deletions uiautomator2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,47 @@ def device_info(self):
self.__devinfo = self._reqsess.get(self.path2url('/info')).json()
return self.__devinfo

def app_info(self, pkg_name):
"""
Get app info
Args:
pkg_name (str): package name
Return example:
{
"mainActivity": "com.github.uiautomator.MainActivity",
"label": "ATX",
"versionName": "1.1.7",
"versionCode": 1001007,
"size":1760809
}
Raises:
UiaError
"""
url = self.path2url('/packages/{0}/info'.format(pkg_name))
resp = self._reqsess.get(url)
resp.raise_for_status()
resp = resp.json()
if not resp.get('success'):
raise UiaError(resp.get('description', 'unknown'))
return resp.get('data')

def app_icon(self, pkg_name):
"""
Returns:
PIL.Image
Raises:
UiaError
"""
from PIL import Image
url = self.path2url('/packages/{0}/icon'.format(pkg_name))
resp = self._reqsess.get(url)
resp.raise_for_status()
return Image.open(io.BytesIO(resp.content))

@property
def wlan_ip(self):
return self._reqsess.get(self.path2url("/wlan/ip")).text.strip()
Expand Down
15 changes: 13 additions & 2 deletions uiautomator2/ext/info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import datetime
import atexit

from uiautomator2 import UIAutomatorServer
from uiautomator2.ext.info import conf


class Info(object):
def __init__(self, driver, package_name=None):
Expand All @@ -21,8 +24,15 @@ def read_file(self, filename):

def get_basic_info(self):
device_info = self._driver.device_info
app = self.pkg_name
self.test_info['basic_info'] = {'device_info': device_info, 'app': app}
app_info = self._driver.app_info(self.pkg_name)
# query for exact model info
if device_info['model'] in conf.phones:
device_info['model'] = conf.phones[device_info['model']]
self.test_info['basic_info'] = {'device_info': device_info, 'app_info': app_info}

def get_app_icon(self):
icon = self._driver.app_icon(self.pkg_name)
icon.save(self.output_dir + 'icon.png')

def get_record_info(self):
record = json.loads(self.read_file('record.json'))
Expand Down Expand Up @@ -59,6 +69,7 @@ def get_result_info(self):

def start(self):
self.get_basic_info()
self.get_app_icon()

def write_info(self):
# self.get_basic_info()
Expand Down
Loading

0 comments on commit 401ff55

Please sign in to comment.