use of com.axway.ats.uiengine.engine.MobileEngine in project ats-framework by Axway.
the class MobileDriver method start.
/**
* Start session to device and load the application <br>
* @param appPath filesystem path to the application - absolute or relative to the Appium server current dir
* <pre>
* <b>iOS</b>: absolute path to simulator-compiled .app file or the bundle_id of the desired target on device
* <b>Android</b>: absolute path to .apk file
* </pre>
*/
@PublicAtsApi
public void start(String appPath) {
log.info("Starting mobile testing session to device: " + getDeviceDescription());
URL url = null;
String platformName = null;
try {
url = new URL("http://" + this.host + ":" + this.port + "/wd/hub");
// http://appium.io/slate/en/master/?java#appium-server-capabilities
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
if (isAndroidAgent) {
if (this.adbLocation == null) {
// try to set Android home and adb location from the ANDROID_HOME environment variable
readAndroidHomeFromEnvironment();
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");
}
}
platformName = "Android";
} else {
desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
platformName = "iOS";
}
desiredCapabilities.setCapability("platformName", platformName);
desiredCapabilities.setCapability("deviceName", deviceName);
desiredCapabilities.setCapability("platformVersion", this.platformVersion);
if (!StringUtils.isNullOrEmpty(this.udid)) {
desiredCapabilities.setCapability("udid", this.udid);
}
desiredCapabilities.setCapability(MobileCapabilityType.APP, /*"app" */
appPath);
desiredCapabilities.setCapability("autoLaunch", true);
desiredCapabilities.setCapability("newCommandTimeout", 30 * 60);
desiredCapabilities.setCapability("noReset", // don’t reset settings and app state before this session
true);
// sometimes environment has performance problems
// in ms
desiredCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500_000);
if (isAndroidAgent) {
driver = new AndroidDriver<WebElement>(url, desiredCapabilities);
} else {
driver = new IOSDriver<WebElement>(url, desiredCapabilities);
}
driver.setLogLevel(Level.ALL);
// the following timeout only works for NATIVE context, but we will handle it in MobileElementState.
// Also there is a problem when != 0. In some reason, for iOS only(maybe), this timeout acts as session timeout ?!?
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
// driver.manage().timeouts().pageLoadTimeout( 30000, TimeUnit.MILLISECONDS ); // UnsupportedCommandException
// driver.manage().timeouts().setScriptTimeout( 10000, TimeUnit.MILLISECONDS ); // WebDriverException: Not yet implemented
driver.context(NATIVE_CONTEXT);
// must be called in NATIVE context
this.screenDimensions = driver.manage().window().getSize();
mobileEngine = new MobileEngine(this, this.mobileDeviceUtils);
// log.info("Application file at " + appPath + " is started and initialized");
} catch (Exception e) {
throw new MobileOperationException("Error starting connection to " + platformName + " device and application " + "under test. Check if there is connection to the device and the Appium " + "server at " + url + " is running.", e);
}
}
Aggregations