Skip to content

Commit 5a366df

Browse files
committed
fix: Adb.get_screen()
1 parent 14c597c commit 5a366df

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

core/utils/device/adb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ def is_text_visible(id, text, case_sensitive=False):
145145
@staticmethod
146146
def get_screen(id, file_path):
147147
File.clean(path=file_path)
148-
Adb.__run_adb_command(command='exec-out screencap -p > ' + file_path, id=id, log_level=logging.INFO)
148+
if Settings.OSType == OSType.WINDOWS:
149+
Adb.__run_adb_command(command='exec-out screencap -p > ' + file_path, id=id, log_level=logging.INFO)
150+
else:
151+
Adb.__run_adb_command(command='shell rm /sdcard/screen.png', id=id)
152+
Adb.__run_adb_command(command='shell screencap -p /sdcard/screen.png', id=id)
153+
Adb.pull(id=id, source='/sdcard/screen.png', target=file_path)
149154
if File.exists(file_path):
150155
return
151156
else:

core/utils/device/device_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def stop():
5050
Process.kill('qemu-system-i38')
5151

5252
@staticmethod
53-
def start(emulator, use_snapshot=False):
53+
def start(emulator, wipe_data=True):
5454
emulator_path = os.path.join(ANDROID_HOME, 'emulator', 'emulator')
5555
base_options = '-no-snapshot-save -no-boot-anim -no-audio'
56-
options = '-port {0} -wipe-data -no-snapshot-load {1}'.format(emulator.port, base_options)
57-
if use_snapshot:
58-
options = '-port {0} {1}'.format(emulator.port, base_options)
56+
options = '-port {0} {1}'.format(emulator.port, base_options)
57+
if wipe_data:
58+
options = '-port {0} -wipe-data {1}'.format(emulator.port, base_options)
5959
command = '{0} @{1} {2}'.format(emulator_path, emulator.avd, options)
6060
Log.info('Booting {0} with cmd:'.format(emulator.avd))
6161
Log.info(command)

core_tests/core/adb_tests.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
3+
from core.base_test.tns_test import TnsTest
4+
from core.log.log import Log
5+
from core.settings import Settings
6+
from core.utils.device.adb import Adb
7+
from core.utils.device.device_manager import DeviceManager
8+
# noinspection PyMethodMayBeStatic
9+
from core.utils.file_utils import File
10+
11+
12+
class AdbTests(TnsTest):
13+
emu = None
14+
15+
@classmethod
16+
def setUpClass(cls):
17+
TnsTest.setUpClass()
18+
DeviceManager.Emulator.stop()
19+
cls.emu = DeviceManager.Emulator.start(Settings.Emulators.DEFAULT, wipe_data=False)
20+
21+
def setUp(self):
22+
TnsTest.setUp(self)
23+
24+
def tearDown(self):
25+
TnsTest.tearDown(self)
26+
27+
@classmethod
28+
def tearDownClass(cls):
29+
TnsTest.tearDownClass()
30+
31+
def test_01_adb_get_source(self):
32+
page_source = Adb.get_page_source(id=self.emu.id)
33+
assert '</hierarchy>' in page_source
34+
35+
def test_02_adb_get_screen(self):
36+
path = os.path.join(Settings.TEST_OUT_HOME, 'temp.png')
37+
File.clean(path)
38+
Adb.get_screen(id=self.emu.id, file_path=path)

0 commit comments

Comments
 (0)