Skip to content

Commit f004e29

Browse files
committed
fix: Adb.get_screen()
1 parent 5ef3dfd commit f004e29

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

HINTS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ When stop emulator it will save its state and next boot with this command will b
2121
$ANDROID_HOME/emulator/emulator -avd Emulator-Api23-Default -no-snapshot-save -no-boot-anim
2222
```
2323

24-
### Faster screenshots
24+
### Faster Screenshots
2525

2626
See [this article](https://stackoverflow.com/questions/13984017/how-to-capture-the-screen-as-fast-as-possible-through-adb)
2727

28+
### Measure UI Performance
29+
30+
See [this article](https://developer.android.com/training/testing/performance)
31+
32+
See [this blog](https://hackernoon.com/gfxinfo-ui-automator-kotlin-automated-jank-tests-fc43995c7a06)
33+
34+
### Python wrappers around Android tools
35+
36+
- [uiautomator](https://github.com/xiaocong/uiautomator)
37+
2838
## Chrome
2939

3040
Chrome browser need to be in consistent state for debugger tests.

core/utils/device/adb.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ def is_running(id):
6868
return False
6969

7070
@staticmethod
71-
def wait_until_boot(id, timeout=180):
71+
def wait_until_boot(id, timeout=180, check_interval=3):
7272
"""
7373
Wait android device/emulator is up and running.
7474
:param id: Device identifier.
7575
:param timeout: Timeout until device is ready (in seconds).
76+
:param check_interval: Sleep specified time before check again.
7677
:return: True if device is ready before timeout, otherwise - False.
7778
"""
7879
booted = False
7980
start_time = time.time()
8081
end_time = start_time + timeout
8182
while not booted:
82-
time.sleep(2)
83+
time.sleep(check_interval)
8384
booted = Adb.is_running(id=id)
8485
if (booted is True) or (time.time() > end_time):
8586
break
@@ -144,14 +145,11 @@ def is_text_visible(id, text, case_sensitive=False):
144145
@staticmethod
145146
def get_screen(id, file_path):
146147
File.clean(path=file_path)
147-
Adb.__run_adb_command(command='shell rm /sdcard/screen.png', id=id)
148-
result = Adb.__run_adb_command(command='shell screencap -p /sdcard/screen.png', id=id)
149-
if result.exit_code == 0:
150-
time.sleep(1)
151-
Adb.pull(id=id, source='/sdcard/screen.png', target=file_path)
152-
if File.exists(file_path):
153-
return
154-
raise Exception('Failed to get screen of {0}.'.format(id))
148+
Adb.__run_adb_command(command='exec-out screencap -p > ' + file_path, id=id)
149+
if File.exists(file_path):
150+
return
151+
else:
152+
raise Exception('Failed to get screen of {0}.'.format(id))
155153

156154
@staticmethod
157155
def get_device_version(id):

0 commit comments

Comments
 (0)