Appium_Tips/Tricks

Pratik Patel
2 min readJun 28, 2018
  1. How to check whether Android app already installed or not?
  • There are scenarios in which you want to check out whether your Android app is already installed on the device or not, but why do you need that? So let’s think of simple use case like most of the application needs to be logged-in in order to use further, the first step of automation would be login, which is a time-consuming (execution perspective). To skip the login part we can do 2 things.
  • 1) Set the desiredcapabilities for “noReset” true and “fullReset” false. So if your app has been installed, Appium neither uninstall it nor clear the cache, so your login would be retained and you do not need to login everytime while executing the test cases.
  • 2) Fire “adb shell pm list packages” to your terminal, it will lists all the packages of intalled apps.
  • Now the question is How would you fire this command with Java, so below code is an answer.
ProcessBuilder processBuilder = new ProcessBuilder("adb", "shell", "pm", "list", "packages");
Process process = null;
try {
process = processBuilder.start();
process.waitFor();
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Execution Ended");

For more details of this code go to my Github link: https://github.com/prat3ik/AppiumTricks

2. How to enable mouse pointer location on Android ?

Mouse pointer location helps so much in Debugging especially whenever you are dealing with a swipe, touch and scroll functions in Appium

  • If you want to enable mouse pointer location using the terminal then fire command: $ adb shell settings put system pointer_location 1 [Use 0 for disable]
  • In Java do use below code:
public static void main(String[] args) throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("adb", "shell", "settings", "put", "system", "pointer_location", "1");
Process pc = pb.start();
pc.waitFor();
System.out.println("Finish!");
}

--

--