use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.
the class MobileDriver method killAdbServer.
/**
* Kill misbehaving ADB server in order to bring it back later to normal state. The server is automatically started on next ADB command.
* Then failed ADB operation (start/stop/clear cache, etc. should be retried.)
*/
private void killAdbServer() {
log.info("Trying to restart ADB server on device: " + getDeviceDescription());
String[] commandArguments = new String[] { "kill-server" };
IProcessExecutor pe = null;
try {
pe = this.mobileDeviceUtils.executeAdbCommand(commandArguments, false);
} catch (Exception e) {
throw new MobileOperationException("Unable to stop ADB server. 'adb kill-server' failed", e);
}
if (pe.getExitCode() != 0) {
log.warn("Unable to stop gracefully the ADB server. Command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
log.info("Trying to forcefully terminate ADB process");
// fallback to taskkill
try {
if (OperatingSystemType.getCurrentOsType().isWindows()) {
pe = new LocalProcessExecutor(HostUtils.LOCAL_HOST_NAME, "taskkill.exe", new String[] { "/IM", "adb.exe", "/F", "/T" });
} else {
pe = new LocalProcessExecutor(HostUtils.LOCAL_HOST_NAME, "killall", new String[] { "adb" });
}
pe.execute();
} catch (Exception e) {
log.info("Unable to kill ADB server. Command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
throw new MobileOperationException("Unable to stop ADB server with taskkill/killall", e);
}
if (pe.getExitCode() != 0) {
// TODO - research possible error codes for non-existing process to kill
log.error("Unable to kill ADB server. Command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
}
}
}
use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.
the class MobileDriver method clearAppCache.
/**
* Clear application cache
*
* @param applicationPackage application package name
*/
@PublicAtsApi
public void clearAppCache(String applicationPackage) {
if (isAndroidAgent) {
if (this.adbLocation == null) {
throw new MobileOperationException("You must specify a valid Android home location or define " + ANDROID_HOME_ENV_VAR + " environment variable. The ADB executable must be located in a 'platform-tools/' subfolder");
}
String[] commandArguments = new String[] { "shell", "pm", "clear", applicationPackage };
IProcessExecutor pe = null;
int numRetries = 0;
while (numRetries <= MAX_ADB_RELATED_RETRIES) {
if (numRetries > 0) {
log.warn("Retrying to start application action as previous try failed");
}
try {
pe = this.mobileDeviceUtils.executeAdbCommand(commandArguments, false);
} catch (Exception e) {
throw new MobileOperationException("Unable to clear application cache of '" + applicationPackage + "'", e);
}
numRetries++;
if (pe.getExitCode() == 0) {
break;
} else {
if (numRetries <= MAX_ADB_RELATED_RETRIES) {
log.error("Unable to clear application cache of '" + applicationPackage + "'. Start command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
//try to kill ADB and issue start again
killAdbServer();
} else {
throw new MobileOperationException("Unable to clear application cache of '" + applicationPackage + "'. Clear cache command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
}
}
}
} else {
//TODO: Find solution. Note that "this.driver.resetApp();" doesn't reset app cache.
throw new NotSupportedOperationException("Currently clear application cache operation for iOS is not implemented");
}
}
use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.
the class MobileDriver method stopIOSSimulator.
/**
* Stopping iOS Simulator
*/
@PublicAtsApi
public void stopIOSSimulator() {
log.info("Stopping simulator on: " + getDeviceDescription());
IProcessExecutor pe = null;
try {
// the simulator window was named "iPhone Simulator" till Xcode 6, now it is "iOS Simulator"
pe = getProcessExecutorImpl("killall", new String[] { "iPhone Simulator", "iOS Simulator" });
pe.execute();
} catch (Exception e) {
throw new MobileOperationException("Unable to stop iOS Simulator", e);
}
if (pe.getExitCode() != 0) {
throw new MobileOperationException("Unable to stop iOS Simulator. Stop command failed (STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
}
}
use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.
the class MobileDriver method stopAndroidApplication.
/**
* Stop application using ADB command: ./adb shell am force-stop <PACKAGE><br/>
* for example: ./adb shell am force-stop com.axway.st.mobile
*
* @param applicationPackage application package
*/
private void stopAndroidApplication(String applicationPackage) {
log.info("Stopping application '" + applicationPackage + "' on device: " + getDeviceDescription());
String[] commandArguments = new String[] { "shell", "am", "force-stop", applicationPackage };
IProcessExecutor pe = null;
int numRetries = 0;
while (numRetries <= MAX_ADB_RELATED_RETRIES) {
if (numRetries > 0) {
log.warn("Retrying to start application action as previous try failed");
}
try {
pe = this.mobileDeviceUtils.executeAdbCommand(commandArguments, false);
} catch (Exception e) {
throw new MobileOperationException("Unable to stop Android application with package '" + applicationPackage + "'", e);
}
numRetries++;
if (pe.getExitCode() == 0) {
break;
} else {
if (numRetries <= MAX_ADB_RELATED_RETRIES) {
log.error("Unable to stop Android application with package '" + applicationPackage + "'. Stop command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
// try to kill ADB and issue stop again
killAdbServer();
} else {
throw new MobileOperationException("Unable to stop Android application with package '" + applicationPackage + "'. Stop command failed (Exit code: " + pe.getExitCode() + ", STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
}
}
}
// while
}
use of com.axway.ats.core.process.model.IProcessExecutor in project ats-framework by Axway.
the class MobileDeviceUtils method executeAdbCommand.
public IProcessExecutor executeAdbCommand(String[] commandArguments, boolean verifyExitCode) {
IProcessExecutor pe = null;
try {
if (getSystemOperationsImpl().getOperatingSystemType().isWindows()) {
pe = getProcessExecutorImpl(this.mobileDriver.getAdbLocation() + "adb.exe", commandArguments);
} else {
pe = getProcessExecutorImpl(this.mobileDriver.getAdbLocation() + "adb", commandArguments);
}
pe.setWorkDirectory(this.mobileDriver.getAdbLocation());
pe.execute();
if (verifyExitCode && pe.getExitCode() != 0) {
throw new MobileOperationException("Adb command failed (STDOUT: '" + pe.getStandardOutput() + "', STDERR: '" + pe.getErrorOutput() + "')");
}
} catch (Exception e) {
throw new MobileOperationException("Adb command failed", e);
}
return pe;
}
Aggregations