Skip to content

Commit

Permalink
added launch emulator and appium server
Browse files Browse the repository at this point in the history
  • Loading branch information
dipjyotimetia committed May 11, 2019
1 parent 4061d76 commit 78ca4c8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/core/ADB.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,48 @@
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

public class ADB {
private Logger logger = LogManager.getLogger(ADB.class);

private static String sdkPath = System.getenv("ANDROID_HOME");
private static String adbPath = sdkPath + "platform-tools" + File.separator + "adb";
private static String emulatorPath = sdkPath +File.separator + "emulator";

private String ID;

public ADB(String deviceID) {
ID = deviceID;
}

public static void launchEmulator(String nameOfAVD) {
System.out.println("Starting emulator for '" + nameOfAVD + "' ...");
String[] aCommand = new String[] { emulatorPath, "-avd", nameOfAVD };
try {
Process process = new ProcessBuilder(aCommand).start();
process.waitFor(180, TimeUnit.SECONDS);
System.out.println("Emulator launched successfully!");
} catch (Exception e) {
e.printStackTrace();
}
}

public static void closeEmulator() {
System.out.println("Killing emulator...");
String[] aCommand = new String[] { adbPath, "emu", "kill" };
try {
Process process = new ProcessBuilder(aCommand).start();
process.waitFor(1, TimeUnit.SECONDS);
System.out.println("Emulator closed successfully!");
} catch (Exception e) {
e.printStackTrace();
}
}

public String command(String command) {
logger.debug("Formatting ADB Command: " + command);
if (command.startsWith("adb"))
Expand Down

0 comments on commit 78ca4c8

Please sign in to comment.