How to control ADB commands on Android using code JAVA + Appium
Hey Guys
After many searches, the best solution I found to work with ADB commands on real devices
(Those who use emulators for testing are less relevant because there you can use commands from the Appium library)
The first thing is to write a method that sends a command to the CommandLine
public static void runShellScript(String command) {
int iExitValue;
String sCommandString;
sCommandString = command;
CommandLine oCmdLine = CommandLine.parse(sCommandString);
DefaultExecutor oDefaultExecutor = new DefaultExecutor();
oDefaultExecutor.setExitValue(0);
try{
iExitValue = oDefaultExecutor.execute(oCmdLine);
} catch (ExecuteException e){
System.out.println("Fail");
e.printStackTrace();
} catch (IOException e){
System.out.println("Denied");
e.printStackTrace();
}
}
Then implement the method like this
runShellScript("adb shell svc data enable");
and use anywhere as needed in tests :)
Recommended by LinkedIn
For example:
If we want to test a certain application whose operating requirements require active Bluetooth + WIFI + Data + Location
So we will send the following commands:
runShellScript("adb shell svc data enable")
runShellScript("adb shell svc wifi enable");
runShellScript("adb shell am broadcast -a io.appium.settings.bluetooth --es setstatus enable");
runShellScript("adb shell settings put secure location_mode 3");;
It is important to note that the commands vary according to the type of version and device, so you must first check what the correct password is.
*You can find all other commands online*
Enjoy :)
תודה רבה לך על השיתוף🙂 אני מזמין אותך לקבוצה שלי: הקבוצה מחברת בין ישראלים במגוון תחומים, הקבוצה מייצרת לקוחות,שיתופי פעולה ואירועים. https://chat.whatsapp.com/IyTWnwphyc8AZAcawRTUhR
Wow
Amazing article!
Sergey Smirnov