Skip to content

Commit ddb1c98

Browse files
authored
Merge pull request #109 from mhkarsten/update_androidrunner
Update android-runner & fix some bugs
2 parents ed51e39 + 15f8358 commit ddb1c98

File tree

72 files changed

+146
-2704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+146
-2704
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ omit = */old tests*
66
*/tests/*
77
*BatterystatsParser*
88
*/python3.6/*
9+
*/python3.13/*
910
*/pytest-*
1011
*/.venv/*
1112

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- "3.6"
3+
- "3.13"
44
before_script:
55
install:
66
- pip install pytest

AndroidRunner/Browsers/Browser.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ def __init__(self, package_name, main_activity):
1111

1212
def start(self, device):
1313
self.logger.info('%s: Start' % device.id)
14-
device.launch_activity(self.package_name, self.main_activity, from_scratch=True, force_stop=True,
15-
action='android.intent.action.VIEW')
14+
15+
kwargs = {
16+
'from_scratch': True,
17+
'force_stop': True,
18+
'action': 'android.intent.action.VIEW',
19+
}
20+
21+
if device != None and int(device.get_version()) > 12:
22+
kwargs['data_uri'] = "about:blank"
23+
24+
device.launch_activity(self.package_name, self.main_activity, **kwargs)
1625

1726
def load_url(self, device, url):
1827
self.logger.info('%s: Load URL: %s' % (device.id, url))

AndroidRunner/Browsers/Chrome.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33

44
class Chrome(Browser):
5-
def __init__(self):
5+
def __init__(self, device=None):
66
# https://stackoverflow.com/a/28151563
7-
super(Chrome, self).__init__('com.android.chrome', 'com.google.android.apps.chrome.Main')
7+
if device != None and int(device.get_version()) > 12:
8+
super(Chrome, self).__init__('com.android.chrome', 'com.google.android.apps.chrome.IntentDispatcher')
9+
else:
10+
super(Chrome, self).__init__('com.android.chrome', 'com.google.android.apps.chrome.Main')
811

AndroidRunner/Browsers/Firefox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33

44
class Firefox(Browser):
5-
def __init__(self):
5+
def __init__(self, device=None):
66
super(Firefox, self).__init__('org.mozilla.firefox', 'org.mozilla.gecko.BrowserApp')
77

AndroidRunner/Browsers/Opera.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class Opera(Browser):
5-
def __init__(self):
5+
def __init__(self, device=None):
66
super(Opera, self).__init__('com.opera.browser', 'com.opera.Opera')

AndroidRunner/Device.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ def plug(self):
164164

165165
def current_activity(self):
166166
"""Newer Android 10 does not have mCurrentFocus and mFocusedApp. Different approach to get the current activity"""
167-
recent_activity = Adb.shell(self.id,'dumpsys activity recents | grep "Recent #0" | cut -d "=" -f2 | grep -o -p "[a-z|.]*"')
168-
167+
recent_activity = Adb.shell(self.id,'dumpsys activity recents | grep "Recent #0" | tr " }" "\n" | grep "=" | cut -d "=" -f 2 | sed -E "s/[^a-zA-Z.]+//g"')
168+
169+
"""Recent activities have both a type (home/standard/ect.) as well as a name e.g. com.android.chrome"""
169170
if recent_activity:
170-
result = recent_activity
171+
result = {"type": recent_activity.split("\n")[0], "name": recent_activity.split("\n")[1]}
171172
self.logger.debug('Current activity: %s' % result)
172173
return result
173174
else:
@@ -197,6 +198,7 @@ def launch_activity(self, package, activity, action='', data_uri='', from_scratc
197198
# https://android.stackexchange.com/a/113919
198199
if from_scratch:
199200
cmd += ' --activity-clear-task'
201+
200202
return Adb.shell(self.id, cmd)
201203

202204
def force_stop(self, name):

AndroidRunner/Devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Devices:
1212
def __init__(self, devices, adb_path='adb', devices_spec=None):
1313
if devices_spec is None:
1414
devices_spec = op.join(ROOT_DIR, 'devices.json')
15-
15+
1616
Adb.setup(adb_path)
1717
mapping_file = load_json(devices_spec)
1818
self._device_map = {n: mapping_file.get(n, None) for n in devices}

AndroidRunner/Experiment.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,33 @@ def __init__(self, config, progress, restart):
2222
self.progress = progress
2323
self.basedir = None
2424
self.random = config.get('randomization', False)
25+
2526
Tests.is_valid_option(self.random, valid_options=[True, False])
2627
self.clear_cache = config.get('clear_cache', False)
2728
Tests.is_valid_option(self.clear_cache, valid_options=[True, False])
29+
2830
if 'devices' not in config:
2931
raise ConfigError('"device" is required in the configuration')
3032
adb_path = config.get('adb_path', 'adb')
33+
3134
self.devices = Devices(config['devices'], adb_path=adb_path, devices_spec=config.get('devices_spec'))
3235
self.repetitions = Tests.is_integer(config.get('repetitions', 1))
3336
self.paths = config.get('paths', [])
3437
self.profilers = Profilers(config.get('profilers', {}))
35-
monkeyrunner_path = config.get('monkeyrunner_path', 'monkeyrunner')
36-
monkey_playback_path = config.get('monkey_playback_path', 'monkey_playback.py')
37-
self.scripts = Scripts(config.get('scripts', {}), monkeyrunner_path=monkeyrunner_path, monkey_playback_path=monkey_playback_path)
38+
self.scripts = Scripts(config.get('scripts', {}))
3839
self.reset_adb_among_runs = config.get('reset_adb_among_runs', False)
3940
Tests.is_valid_option(self.reset_adb_among_runs, valid_options=[True, False])
4041
self.time_between_run = Tests.is_integer(config.get('time_between_run', 0))
4142
Tests.check_dependencies(self.devices, self.profilers.dependencies())
4243
self.output_root = paths.OUTPUT_DIR
4344
self.result_file_structure = None
44-
45+
4546
self.usb_handler_config = config.get("usb_handler", None)
4647
self.usb_handler = USBHandler(self.usb_handler_config)
4748

4849
self.run_stopping_condition_config = config.get("run_stopping_condition", None)
4950
self.queue = mp.Queue()
50-
51+
5152
if restart:
5253
for device in self.devices:
5354
self.prepare_device(device, restart=True)

AndroidRunner/MonkeyReplay.py

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

0 commit comments

Comments
 (0)