Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1ae4754

Browse files
author
yennj12
committed
add
1 parent 5f43d41 commit 1ae4754

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed

‎mobly/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ sudo apt install adb
3434
# validate
3535

3636
adb
37+
38+
# get connected devices
39+
adb devices
3740
```
3841

3942
## Cmd
@@ -64,6 +67,16 @@ python3 hello_world_test_2.py -c sample_config.yml --test_case test_bye test_hel
6467

6568
python3 hello_world_test_2.py -c sample_config_2.yml --test_bed AbcTestBed
6669

70+
71+
#-----------------------
72+
# TEST 3
73+
#-----------------------
74+
75+
76+
python3 sample_test.py -c sample_config_3.yml
77+
78+
79+
6780
#-----------------------
6881
# TEST 2
6982
#-----------------------

‎mobly/sample_config_2.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TestBeds:
1414
- Name: AbcTestBed
1515
Controllers:
1616
AndroidDevice:
17-
- serial: abc
17+
- serial: xxx # replace with device serial number
1818
label: golden_device
1919
TestParams:
2020
<<: *DefaultParams

‎mobly/sample_config_3.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TestBeds:
2+
- Name: TwoDeviceTestBed
3+
Controllers:
4+
AndroidDevice:
5+
- serial: xyz
6+
label: target
7+
- serial: abc
8+
label: discoverer
9+
TestParams:
10+
bluetooth_name: MagicBluetooth
11+
bluetooth_timeout: 5

‎mobly/sample_test.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import logging
2+
import pprint
3+
4+
from mobly import asserts
5+
from mobly import base_test
6+
from mobly import test_runner
7+
from mobly.controllers import android_device
8+
9+
# Number of seconds for the target to stay discoverable on Bluetooth.
10+
DISCOVERABLE_TIME = 60
11+
12+
13+
class HelloWorldTest(base_test.BaseTestClass):
14+
def setup_class(self):
15+
# Registering android_device controller module, and declaring that the test
16+
# requires at least two Android devices.
17+
self.ads = self.register_controller(android_device, min_number=2)
18+
# The device used to discover Bluetooth devices.
19+
self.discoverer = android_device.get_device(
20+
self.ads, label='discoverer')
21+
# Sets the tag that represents this device in logs.
22+
self.discoverer.debug_tag = 'discoverer'
23+
# The device that is expected to be discovered
24+
self.target = android_device.get_device(self.ads, label='target')
25+
self.target.debug_tag = 'target'
26+
self.target.load_snippet('mbs', android_device.MBS_PACKAGE)
27+
self.discoverer.load_snippet('mbs', android_device.MBS_PACKAGE)
28+
29+
def setup_test(self):
30+
# Make sure bluetooth is on.
31+
self.target.mbs.btEnable()
32+
self.discoverer.mbs.btEnable()
33+
# Set Bluetooth name on target device.
34+
self.target.mbs.btSetName('LookForMe!')
35+
36+
def test_bluetooth_discovery(self):
37+
target_name = self.target.mbs.btGetName()
38+
self.target.log.info('Become discoverable with name "%s" for %ds.',
39+
target_name, DISCOVERABLE_TIME)
40+
self.target.mbs.btBecomeDiscoverable(DISCOVERABLE_TIME)
41+
self.discoverer.log.info('Looking for Bluetooth devices.')
42+
discovered_devices = self.discoverer.mbs.btDiscoverAndGetResults()
43+
self.discoverer.log.debug('Found Bluetooth devices: %s',
44+
pprint.pformat(discovered_devices, indent=2))
45+
discovered_names = [device['Name'] for device in discovered_devices]
46+
logging.info('Verifying the target is discovered by the discoverer.')
47+
asserts.assert_true(
48+
target_name in discovered_names,
49+
'Failed to discover the target device %s over Bluetooth.' %
50+
target_name)
51+
52+
def teardown_test(self):
53+
# Turn Bluetooth off on both devices after test finishes.
54+
self.target.mbs.btDisable()
55+
self.discoverer.mbs.btDisable()
56+
57+
58+
if __name__ == '__main__':
59+
test_runner.main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /