Skip to content

Commit a0246cc

Browse files
added the adb shell commands
1 parent 1a506cc commit a0246cc

File tree

1 file changed

+84
-46
lines changed

1 file changed

+84
-46
lines changed

docs/adb-commands-support.md

Lines changed: 84 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Android Debug Bridge (adb) is a versatile command-line tool that lets users comm
5050

5151
LambdaTest provides support for limited commands which can be executed in your app automation test scripts via javascript executors. The following command with the below mentioned parameters need to be used to execute adb command with LambdaTest real device cloud.
5252

53-
```bash
53+
```python
5454
driver.execute_script("lambda-adb", params)
5555
```
5656

@@ -61,31 +61,31 @@ driver.execute_script("lambda-adb", params)
6161
### Swipe
6262
**adb shell input swipe** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
6363

64-
The command is used to generate a swipe gesture by defining the coordinates of starting and ending point of the swipe. The following is a Python sample of using the adb swipe command with LambdaTest executor.
64+
The command is used to generate a swipe gesture by defining the coordinates of starting and ending point of the swipe. The following is a Python sample of using the adb swipe command with LambdaTest executor.
6565

66-
```bash
67-
params = {"command":"input-swipe", "startX":200,"startY":900,"endX": 200,"endY":300}
68-
result = driver.execute_script("lambda-adb",params)
69-
```
66+
```python
67+
params = {"command":"input-swipe", "startX":200,"startY":900,"endX": 200,"endY":300}
68+
result = driver.execute_script("lambda-adb",params)
69+
```
7070

7171
### Clipboard
7272

7373
**adb shell input sendKeys** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
7474

75-
The command is used to sends text as if typed at the keyboard in the real devices. The following is a Python sample of using the adb sendKeys command with LambdaTest executor.
75+
The command is used to sends text as if typed at the keyboard in the real devices. The following is a Python sample of using the adb sendKeys command with LambdaTest executor.
7676

77-
```bash
78-
params = {"command":"input-text", "text":"this is my text"}
79-
result = driver.execute_script("lambda-adb",params)
80-
```
77+
```python
78+
params = {"command":"input-text", "text":"this is my text"}
79+
result = driver.execute_script("lambda-adb",params)
80+
```
8181

8282
### Home Button
8383

8484
- **Navigate to the home screen** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
8585

8686
The command is used to navigate to the home screen of the device while running an app automation test script. The following is a Python sample of using the adb command to navigate to the home screen with LambdaTest executor.
8787

88-
```bash
88+
```python
8989
params = {"command":"keyevent", "keycode":3}
9090
result = driver.execute_script("lambda-adb",params)
9191
```
@@ -94,60 +94,80 @@ result = driver.execute_script("lambda-adb",params)
9494

9595
- **enableAutoRotate** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
9696

97-
The command is used to auto rotate the screen of the device while running an app automation test script. The following is a Python sample using the adb command to allow auto rotation with LambdaTest executor.
97+
The command is used to auto rotate the screen of the device while running an app automation test script. The following is a Python sample using the adb command to allow auto rotation with LambdaTest executor.
98+
99+
```python
100+
params = {"command":"autorotate", "enableAutoRotate": True}
101+
result = driver.execute_script("lambda-adb",params)
102+
```
98103

99-
```bash
100-
params = {"command":"autorotate", "enableAutoRotate": True}
101-
result = driver.execute_script("lambda-adb",params)
102-
```
103104
### ADB Shell Command
104105

105106
- **adb shell dumpsys** <RealDeviceTag value="Real Device" />
106107

107-
This command is used to obtain detailed information about installed packages on device. When you run this command, it provides a list of information for each package installed on the device. The output includes various details about each package.The following is a Python sample using the adb command:
108+
This command is used to obtain detailed information about installed packages on device. When you run this command, it provides a list of information for each package installed on the device. The output includes various details about each package.The following is a Python sample using the adb command:
108109

109-
```bash
110-
params = {"command": "shell", "text": "dumpsys package <package_info>"}
111-
result = driver.execute_script("lambda-adb",params)
112-
```
110+
```python
111+
params = {"command": "shell", "text": "dumpsys package <package_info>"}
112+
result = driver.execute_script("lambda-adb",params)
113+
```
114+
115+
- **adb shell getprop** <VirtualDeviceTag value="Virtual Device" />
116+
117+
This command is used to retrieve system properties from an Android device. When executed, it provides a list of key-value pairs representing various system settings and configurations. These properties include information about the device's build, hardware, and other system-related details. The output can be useful for debugging, development or understanding the device's current state. The following is a Python sample using the adb command:
118+
119+
```python
120+
params = {"command": "shell", "text": "getprop"}
121+
result = driver.execute_script("lambda-adb",params)
122+
```
123+
124+
- **adb shell ping -c 4 YOUR_URL** <VirtualDeviceTag value="Virtual Device" />
125+
126+
This command is used to test the network connectivity between the Android device and a specified host, such as `google.com`. When executed it sends four ICMP request packets to the host and wait for responses. The output includes details such as packet transmission time, success rate and round-trip time, which helps diagnose network connectivity and latency issues. The following is a Python sample using the adb command:
127+
128+
> **Note :** The **-c** is required in this command
129+
```python
130+
params = {"command": "shell", "text": "ping -c 4 google.com"}
131+
result = driver.execute_script("lambda-adb",params)
132+
```
113133

114134
### Enable/Disable Notification
115135

116136
- **enableNotification** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
117137

118-
These commands enable or disable your app notifications on the device based on the value provided for `enableNotification`. **True** is used to enable notifications, while **False** is used to disable them.The following is a Python sample using the adb command with LambdaTest executor:
138+
These commands enable or disable your app notifications on the device based on the value provided for `enableNotification`. **True** is used to enable notifications, while **False** is used to disable them. The following is a Python sample using the adb command with LambdaTest executor:
119139

120-
```bash
121-
params = {"command": "enable-notification", "enableNotification":True/False}
122-
result = driver.execute_script("lambda-adb",params)
123-
```
140+
```python
141+
params = {"command": "enable-notification", "enableNotification":True/False}
142+
result = driver.execute_script("lambda-adb",params)
143+
```
124144

125-
:::note
126-
- These commands are compatible with Android versions 13 and above.
127-
- When you disable app notification permissions using the command, the app go into the background. This behavior occurs due to limitations with ADB, and you need to reactivate the app through test script.
128-
:::
145+
:::note
146+
- These commands are compatible with Android versions 13 and above.
147+
- When you disable app notification permissions using the command, the app go into the background. This behavior occurs due to limitations with ADB, and you need to reactivate the app through test script.
148+
:::
129149

130150
### Enable/Disable Battery Optimization
131151

132152
- **disableBatteryOptimization** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
133153

134-
This command is used to enable or disable battery optimization for your app on the device. The following is a Python sample using the adb command to disable battery optimization with LambdaTest executor:
154+
This command is used to enable or disable battery optimization for your app on the device. The following is a Python sample using the adb command to disable battery optimization with LambdaTest executor:
135155

136-
```bash
137-
params = {"command":"disable-battery-optimization", "disableBatteryOptimization":True/False}
138-
result = driver.execute_script("lambda-adb",params)
139-
```
156+
```python
157+
params = {"command":"disable-battery-optimization", "disableBatteryOptimization":True/False}
158+
result = driver.execute_script("lambda-adb",params)
159+
```
140160

141161
### Fixed-to-User Rotation
142162

143163
- **fixedToUserRotation** <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
144164

145-
This command serves to lock the screen rotation in alignment with the app's default behavior and user-defined settings. Below is a Python example utilizing the adb command to enforce fixed screen rotation with the LambdaTest executor:
165+
This command serves to lock the screen rotation in alignment with the app's default behavior and user-defined settings. Below is a Python example utilizing the adb command to enforce fixed screen rotation with the LambdaTest executor:
146166

147-
```bash
148-
params = {"command":"fixed-to-user-rotation", "fixedToUserRotation":True}
149-
result = driver.execute_script("lambda-adb",params)
150-
```
167+
```python
168+
params = {"command":"fixed-to-user-rotation", "fixedToUserRotation":True}
169+
result = driver.execute_script("lambda-adb",params)
170+
```
151171

152172
### Disabling Animations on Android Devices <RealDeviceTag value="Real Device" /> <VirtualDeviceTag value="Virtual Device" />
153173
Disabling animations can enhance test execution speed by preventing unnecessary visual effects. The following commands are used to disable different types of animations:
@@ -156,13 +176,31 @@ Disabling animations can enhance test execution speed by preventing unnecessary
156176
- `adb shell settings put global transition_animation_scale 0`: Disables window transition animations, making UI transitions instant.
157177
- `adb shell settings put global window_animation_scale 0`: Disables activity window animations, eliminating fade-in or zoom-in effects.
158178

159-
These commands set the respective global animation scales to 0, effectively disabling animations.
179+
These commands set the respective global animation scales to 0, effectively disabling animations.
160180

161-
```java
162-
Map<String, String> params = Map.of("command", "shell", "text", "settings get global animator_duration_scale");
163-
androidDriver.executeScript("lambda-adb", params);
164-
```
181+
```java
182+
Map<String, String> params = Map.of("command", "shell", "text", "settings get global animator_duration_scale");
183+
androidDriver.executeScript("lambda-adb", params);
184+
```
185+
186+
### Enabling Automatic Timezone and Automatic Time Using ADB <VirtualDeviceTag value="Virtual Device App" />
187+
By default, Automatic Timezone and Automatic Time settings are enabled on the device. These settings ensure that the device updates its time and timezone automatically based on network-provided information. If needed, you can manually enable these settings using ADB shell commands. To enable these settings via ADB, run the following commands:
188+
189+
- `settings put global auto_time_zone 1`: Enables Automatic Timezone, allowing the device to adjust its timezone based on network data.
190+
- `settings put global auto_time 1`: Enables Automatic Time, ensuring that the device syncs time automatically from the network.
165191

192+
These commands help maintain accurate time and timezone settings without requiring manual intervention. If you're using Python with LambdaTest’s App Automation, you can execute these commands using the `execute_script` function:
193+
194+
```python
195+
# Define ADB commands for enabling automatic time and timezone
196+
params_timezone = {"command": "shell", "text": "settings put global auto_time_zone 1"}
197+
params_time = {"command": "shell", "text": "settings put global auto_time 1"}
198+
199+
# Execute commands using LambdaTest's ADB execution method
200+
result_timezone = driver.execute_script("lambda-adb", params_timezone)
201+
result_time = driver.execute_script("lambda-adb", params_time)
202+
```
203+
This approach is particularly useful when testing applications that rely on correct time settings, ensuring they function properly across different time zones.
166204

167205
<nav aria-label="breadcrumbs">
168206
<ul className="breadcrumbs">

0 commit comments

Comments
 (0)