xref: /aosp_15_r20/external/mobly-bundled-snippets/README.md (revision f8709298c7f2c449bb8c80b03fabe16c67b8969c)
1*f8709298SAndroid Build Coastguard WorkerMobly Bundled Snippets is a set of Snippets to allow Mobly tests to control
2*f8709298SAndroid Build Coastguard WorkerAndroid devices by exposing a simplified version of the public Android API
3*f8709298SAndroid Build Coastguard Workersuitable for testing.
4*f8709298SAndroid Build Coastguard Worker
5*f8709298SAndroid Build Coastguard WorkerWe are adding more APIs as we go. If you have specific needs for certain groups
6*f8709298SAndroid Build Coastguard Workerof APIs, feel free to file a request in [Issues](https://github.com/google/mobly-bundled-snippets/issues).
7*f8709298SAndroid Build Coastguard Worker
8*f8709298SAndroid Build Coastguard WorkerNote: this is not an official Google product.
9*f8709298SAndroid Build Coastguard Worker
10*f8709298SAndroid Build Coastguard Worker
11*f8709298SAndroid Build Coastguard Worker## Usage
12*f8709298SAndroid Build Coastguard Worker
13*f8709298SAndroid Build Coastguard Worker1.  Compile and install the bundled snippets
14*f8709298SAndroid Build Coastguard Worker
15*f8709298SAndroid Build Coastguard Worker        ./gradlew assembleDebug
16*f8709298SAndroid Build Coastguard Worker        adb install -d -r -g ./build/outputs/apk/debug/mobly-bundled-snippets-debug.apk
17*f8709298SAndroid Build Coastguard Worker
18*f8709298SAndroid Build Coastguard Worker1.  Use the Mobly snippet shell to interact with the bundled snippets
19*f8709298SAndroid Build Coastguard Worker
20*f8709298SAndroid Build Coastguard Worker        snippet_shell.py com.google.android.mobly.snippet.bundled
21*f8709298SAndroid Build Coastguard Worker        >>> print(s.help())
22*f8709298SAndroid Build Coastguard Worker        Known methods:
23*f8709298SAndroid Build Coastguard Worker          bluetoothDisable() returns void  // Disable bluetooth with a 30s timeout.
24*f8709298SAndroid Build Coastguard Worker        ...
25*f8709298SAndroid Build Coastguard Worker          wifiDisable() returns void  // Turns off Wi-Fi with a 30s timeout.
26*f8709298SAndroid Build Coastguard Worker          wifiEnable() returns void  // Turns on Wi-Fi with a 30s timeout.
27*f8709298SAndroid Build Coastguard Worker        ...
28*f8709298SAndroid Build Coastguard Worker
29*f8709298SAndroid Build Coastguard Worker1.  To use these snippets within Mobly tests, load it on your AndroidDevice objects
30*f8709298SAndroid Build Coastguard Worker    after registering android_device module:
31*f8709298SAndroid Build Coastguard Worker
32*f8709298SAndroid Build Coastguard Worker    ```python
33*f8709298SAndroid Build Coastguard Worker    def setup_class(self):
34*f8709298SAndroid Build Coastguard Worker      self.ad = self.register_controllers(android_device, min_number=1)[0]
35*f8709298SAndroid Build Coastguard Worker      self.ad.load_snippet('api', 'com.google.android.mobly.snippet.bundled')
36*f8709298SAndroid Build Coastguard Worker
37*f8709298SAndroid Build Coastguard Worker    def test_enable_wifi(self):
38*f8709298SAndroid Build Coastguard Worker      self.ad.api.wifiEnable()
39*f8709298SAndroid Build Coastguard Worker    ```
40*f8709298SAndroid Build Coastguard Worker
41*f8709298SAndroid Build Coastguard Worker## Develop
42*f8709298SAndroid Build Coastguard Worker
43*f8709298SAndroid Build Coastguard WorkerIf you want to contribute, use the usual github method of forking and sending
44*f8709298SAndroid Build Coastguard Workera pull request.
45*f8709298SAndroid Build Coastguard Worker
46*f8709298SAndroid Build Coastguard WorkerBefore sending a pull request, run the `presubmit` target to format and run
47*f8709298SAndroid Build Coastguard Workerlint over the code. Fix any issues it indicates. When complete, send the pull
48*f8709298SAndroid Build Coastguard Workerrequest.
49*f8709298SAndroid Build Coastguard Worker
50*f8709298SAndroid Build Coastguard Worker```shell
51*f8709298SAndroid Build Coastguard Worker./gradlew presubmit
52*f8709298SAndroid Build Coastguard Worker```
53*f8709298SAndroid Build Coastguard Worker
54*f8709298SAndroid Build Coastguard WorkerThis target will reformat the code with
55*f8709298SAndroid Build Coastguard Worker[googleJavaFormat](https://github.com/sherter/google-java-format-gradle-plugin)
56*f8709298SAndroid Build Coastguard Workerand run lint. The lint report should open in your default browser.
57*f8709298SAndroid Build Coastguard Worker
58*f8709298SAndroid Build Coastguard WorkerBe sure to address *all* off the errors reported by lint. When finished and you
59*f8709298SAndroid Build Coastguard Workerrun `presubmit` one last time you should see:
60*f8709298SAndroid Build Coastguard Worker
61*f8709298SAndroid Build Coastguard Worker> No Issues Found
62*f8709298SAndroid Build Coastguard Worker>   Congratulations!
63*f8709298SAndroid Build Coastguard Worker
64*f8709298SAndroid Build Coastguard Workerin your browser.
65*f8709298SAndroid Build Coastguard Worker
66*f8709298SAndroid Build Coastguard Worker## Other resources
67*f8709298SAndroid Build Coastguard Worker
68*f8709298SAndroid Build Coastguard Worker  * [Mobly multi-device test framework](http://github.com/google/mobly)
69*f8709298SAndroid Build Coastguard Worker  * [Mobly Snippet Lib](http://github.com/google/mobly-snippet-lib)
70