How to use isIOS method of com.qaprosoft.carina.core.foundation.webdriver.device.Device class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIOS

Source:Device.java Github

copy

Full Screen

...250 }251 public void connectRemote() {252 if (isNull())253 return;254 if (isIOS())255 return;256 257 String connectUrl = getAdbName();258 if (StringUtils.isEmpty(connectUrl)) {259 LOGGER.error("Unable to use adb as ADB remote url is not available!");260 return;261 }262 263 LOGGER.debug("adb connect " + connectUrl);264 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "connect", connectUrl);265 executor.execute(cmd);266 CommonUtils.pause(1);267 // TODO: verify that device connected and raise an error if not and disabled adb integration268 String[] cmd2 = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "devices");269 executor.execute(cmd2);270 isAdbEnabled = true;271 }272 public void disconnectRemote() {273 if (!isAdbEnabled)274 return;275 276 if (isNull())277 return;278 // [VD] No need to do adb command as stopping STF session do it correctly279 // in new STF we have huge problems with sessions disconnect280 LOGGER.debug("adb disconnect " + getRemoteURL());281 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "disconnect", getRemoteURL());282 executor.execute(cmd);283 isAdbEnabled = false;284 }285 public String getFullPackageByName(final String name) {286 List<String> packagesList = getInstalledPackages();287 LOGGER.debug("Found packages: ".concat(packagesList.toString()));288 String resultPackage = null;289 for (String packageStr : packagesList) {290 if (packageStr.matches(String.format(".*%s.*", name))) {291 LOGGER.info("Package was found: ".concat(packageStr));292 resultPackage = packageStr;293 break;294 }295 }296 if (null == resultPackage) {297 LOGGER.info("Package wasn't found using following name: ".concat(name));298 resultPackage = "not found";299 }300 return resultPackage;301 }302 public List<String> getInstalledPackages() {303 String deviceUdid = getAdbName();304 LOGGER.debug("Device udid: ".concat(deviceUdid));305 String[] cmd = CmdLine.createPlatformDependentCommandLine("adb", "-s", deviceUdid, "shell", "pm", "list", "packages");306 LOGGER.debug("Following cmd will be executed: " + Arrays.toString(cmd));307 List<String> packagesList = executor.execute(cmd);308 return packagesList;309 }310 public boolean isAppInstall(final String packageName) {311 return !getFullPackageByName(packageName).contains("not found");312 }313 public void pressKey(int key) {314 if (isNull())315 return;316 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "-s", getAdbName(), "shell", "input",317 "keyevent", String.valueOf(key));318 executor.execute(cmd);319 }320 public void pause(long timeout) {321 CommonUtils.pause(timeout);322 }323 public void clearAppData() {324 clearAppData(Configuration.getMobileApp());325 }326 public void clearAppData(String app) {327 if (!Configuration.getPlatform().equalsIgnoreCase(SpecialKeywords.ANDROID)) {328 return;329 }330 if (isNull())331 return;332 // adb -s UDID shell pm clear com.myfitnesspal.android333 String packageName = getApkPackageName(app);334 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "-s", getAdbName(), "shell", "pm", "clear", packageName);335 executor.execute(cmd);336 }337 public String getApkPackageName(String apkFile) {338 // aapt dump badging <apk_file> | grep versionCode339 // aapt dump badging <apk_file> | grep versionName340 // output:341 // package: name='com.myfitnesspal.android' versionCode='9025' versionName='develop-QA' platformBuildVersionName='6.0-2704002'342 String packageName = "";343 String[] cmd = CmdLine.insertCommandsAfter("aapt dump badging".split(" "), apkFile);344 List<String> output = executor.execute(cmd);345 // parse output command and get appropriate data346 for (String line : output) {347 if (line.contains("versionCode") && line.contains("versionName")) {348 LOGGER.debug(line);349 String[] outputs = line.split("'");350 packageName = outputs[1]; // package351 }352 }353 return packageName;354 }355 public void uninstallApp(String packageName) {356 if (isNull())357 return;358 // adb -s UDID uninstall com.myfitnesspal.android359 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "-s", getAdbName(), "uninstall", packageName);360 executor.execute(cmd);361 }362 public void installApp(String apkPath) {363 if (isNull())364 return;365 // adb -s UDID install com.myfitnesspal.android366 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "-s", getAdbName(), "install", "-r", apkPath);367 executor.execute(cmd);368 }369 public synchronized void installAppSync(String apkPath) {370 if (isNull())371 return;372 // adb -s UDID install com.myfitnesspal.android373 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "-s", getAdbName(), "install", "-r", apkPath);374 executor.execute(cmd);375 }376 /*377 * public void reinstallApp() {378 * if (!Configuration.getPlatform().equalsIgnoreCase(SpecialKeywords.ANDROID)) {379 * return;380 * }381 * 382 * if (isNull())383 * return;384 * 385 * String mobileApp = Configuration.getMobileApp();386 * String oldMobileApp = Configuration.get(Parameter.MOBILE_APP_PREUPGRADE);387 * 388 * if (!oldMobileApp.isEmpty()) {389 * //redefine strategy to do upgrade scenario390 * R.CONFIG.put(Parameter.MOBILE_APP_UNINSTALL.getKey(), "true");391 * R.CONFIG.put(Parameter.MOBILE_APP_INSTALL.getKey(), "true");392 * }393 * 394 * if (Configuration.getBoolean(Parameter.MOBILE_APP_UNINSTALL)) {395 * // explicit reinstall the apk396 * String[] apkVersions = getApkVersion(mobileApp);397 * if (apkVersions != null) {398 * String appPackage = apkVersions[0];399 * 400 * String[] apkInstalledVersions = getInstalledApkVersion(appPackage);401 * 402 * LOGGER.info("installed app: " + apkInstalledVersions[2] + "-" + apkInstalledVersions[1]);403 * LOGGER.info("new app: " + apkVersions[2] + "-" + apkVersions[1]);404 * 405 * if (apkVersions[1].equals(apkInstalledVersions[1]) && apkVersions[2].equals(apkInstalledVersions[2]) && oldMobileApp.isEmpty()) {406 * LOGGER.info(407 * "Skip application uninstall and cache cleanup as exactly the same version is already installed.");408 * } else {409 * uninstallApp(appPackage);410 * clearAppData(appPackage);411 * isAppInstalled = false;412 * if (!oldMobileApp.isEmpty()) {413 * LOGGER.info("Starting sync install operation for preupgrade app: " + oldMobileApp);414 * installAppSync(oldMobileApp);415 * }416 * 417 * if (Configuration.getBoolean(Parameter.MOBILE_APP_INSTALL)) {418 * // install application in single thread to fix issue with gray Google maps419 * LOGGER.info("Starting sync install operation for app: " + mobileApp);420 * installAppSync(mobileApp);421 * }422 * }423 * }424 * } else if (Configuration.getBoolean(Parameter.MOBILE_APP_INSTALL) && !isAppInstalled) {425 * LOGGER.info("Starting install operation for app: " + mobileApp);426 * installApp(mobileApp);427 * isAppInstalled = true;428 * }429 * }430 */431 public String[] getInstalledApkVersion(String packageName) {432 // adb -s UDID shell dumpsys package PACKAGE | grep versionCode433 if (isNull())434 return null;435 String[] res = new String[3];436 res[0] = packageName;437 String[] cmd = CmdLine.insertCommandsAfter(executor.getDefaultCmd(), "-s", getAdbName(), "shell", "dumpsys", "package", packageName);438 List<String> output = executor.execute(cmd);439 for (String line : output) {440 LOGGER.debug(line);441 if (line.contains("versionCode")) {442 // versionCode=17040000 targetSdk=25443 LOGGER.info("Line for parsing installed app: " + line);444 String[] outputs = line.split("=");445 String tmp = outputs[1]; // everything after '=' sign446 res[1] = tmp.split(" ")[0];447 }448 if (line.contains("versionName")) {449 // versionName=8.5.0450 LOGGER.info("Line for parsing installed app: " + line);451 String[] outputs = line.split("=");452 res[2] = outputs[1];453 }454 }455 if (res[0] == null && res[1] == null && res[2] == null) {456 return null;457 }458 return res;459 }460 public String[] getApkVersion(String apkFile) {461 // aapt dump badging <apk_file> | grep versionCode462 // aapt dump badging <apk_file> | grep versionName463 // output:464 // package: name='com.myfitnesspal.android' versionCode='9025' versionName='develop-QA' platformBuildVersionName='6.0-2704002'465 String[] res = new String[3];466 res[0] = "";467 res[1] = "";468 res[2] = "";469 String[] cmd = CmdLine.insertCommandsAfter("aapt dump badging".split(" "), apkFile);470 List<String> output = executor.execute(cmd);471 // parse output command and get appropriate data472 for (String line : output) {473 if (line.contains("versionCode") && line.contains("versionName")) {474 LOGGER.debug(line);475 String[] outputs = line.split("'");476 res[0] = outputs[1]; // package477 res[1] = outputs[3]; // versionCode478 res[2] = outputs[5]; // versionName479 }480 }481 return res;482 }483 public List<String> execute(String[] cmd) {484 return executor.execute(cmd);485 }486 public void setProxy(final String host, final String port, final String ssid, final String password) {487 if (!getOs().equalsIgnoreCase(DeviceType.Type.ANDROID_PHONE.getFamily())) {488 LOGGER.error("Proxy configuration is available for Android ONLY");489 throw new RuntimeException("Proxy configuration is available for Android ONLY");490 }491 if (!isAppInstall(SpecialKeywords.PROXY_SETTER_PACKAGE)) {492 final String proxySetterFileName = "./proxy-setter-temp.apk";493 File targetFile = new File(proxySetterFileName);494 downloadFileFromJar(SpecialKeywords.PROXY_SETTER_RES_PATH, targetFile);495 installApp(proxySetterFileName);496 }497 String deviceUdid = getAdbName();498 LOGGER.debug("Device udid: ".concat(deviceUdid));499 String[] cmd = CmdLine.createPlatformDependentCommandLine("adb", "-s", deviceUdid, "shell", "am", "start", "-n",500 "tk.elevenk.proxysetter/.MainActivity", "-e", "host", host, "-e", "port", port, "-e", "ssid", ssid, "-e", "key", password);501 LOGGER.debug("Following cmd will be executed: " + Arrays.toString(cmd));502 executor.execute(cmd);503 }504 private void downloadFileFromJar(final String path, final File targetFile) {505 InputStream initialStream = Device.class.getClassLoader().getResourceAsStream(path);506 try {507 FileUtils.copyInputStreamToFile(initialStream, targetFile);508 } catch (IOException e) {509 LOGGER.error("Error during copying of file from the resources. ".concat(e.getMessage()));510 }511 }512 public String getAdbName() {513 if (!StringUtils.isEmpty(getRemoteURL())) {514 return getRemoteURL();515 } else if (!StringUtils.isEmpty(getUdid())) {516 return getUdid();517 } else {518 return "";519 }520 }521 /**522 * Related apps will be uninstall just once for a test launch.523 */524 public void uninstallRelatedApps() {525 if (getOs().equalsIgnoreCase(Type.ANDROID_PHONE.getFamily()) && Configuration.getBoolean(Parameter.UNINSTALL_RELATED_APPS)526 && !clearedDeviceUdids.contains(getUdid())) {527 String mobileApp = Configuration.getMobileApp();528 LOGGER.debug("Current mobile app: ".concat(mobileApp));529 String tempPackage;530 try {531 tempPackage = getApkPackageName(mobileApp);532 } catch (Exception e) {533 LOGGER.info("Error during extraction of package using aapt. It will be extracted from config");534 tempPackage = R.CONFIG.get(SpecialKeywords.MOBILE_APP_PACKAGE);535 }536 final String mobilePackage = tempPackage;537 LOGGER.debug("Current mobile package: ".concat(mobilePackage));538 // in general it has following naming convention:539 // com.projectname.app540 // so we need to remove all apps realted to 1 project541 String projectName = mobilePackage.split("\\.")[1];542 LOGGER.debug("Apps related to current project will be uninstalled. Extracted project: ".concat(projectName));543 List<String> installedPackages = getInstalledPackages();544 // extracted package syntax: package:com.project.app545 installedPackages.parallelStream()546 .filter(packageName -> (packageName.matches(String.format(".*\\.%s\\..*", projectName))547 && !packageName.equalsIgnoreCase(String.format("package:%s", mobilePackage))))548 .collect(Collectors.toList()).forEach((k) -> uninstallApp(k.split(":")[1]));549 clearedDeviceUdids.add(getUdid());550 LOGGER.debug("Udids of devices where applciation was already reinstalled: ".concat(clearedDeviceUdids.toString()));551 } else {552 LOGGER.debug("Related apps had been already uninstalled or flag uninstall_related_apps is disabled.");553 }554 }555 556 /**557 * Save xml layout of the application 558 * @param screenshotName - png file name to generate appropriate uix 559 * @return saved file560 */561 public File generateUiDump(String screenshotName) {562 if (isNull()) {563 return null;564 }565 566// TODO: investigate with iOS: how does it work with iOS567 if (!isConnected()) {568 LOGGER.debug("Device isConnected() returned false. Dump file won't be generated.");569 //do not use new features if execution is not inside approved cloud570 return null;571 }572 573 if (getDrivers().size() == 0) {574 LOGGER.debug("There is no active drivers in the pool.");575 return null;576 }577 // TODO: investigate how to connect screenshot with xml dump: screenshot578 // return File -> Zip png and uix or move this logic to zafira579 580 try {581 WebDriver driver = getDriver(this);582 if (driver == null) {583 LOGGER.debug(String.format("There is no active driver for device: %s", getName()));584 return null;585 }586 587 LOGGER.debug("UI dump generation...");588 String fileName = ReportContext.getTestDir() + String.format("/%s.uix", screenshotName.replace(".png", ""));589 String pageSource = driver.getPageSource();590 pageSource = pageSource.replaceAll(SpecialKeywords.ANDROID_START_NODE, SpecialKeywords.ANDROID_START_UIX_NODE).591 replaceAll(SpecialKeywords.ANDROID_END_NODE, SpecialKeywords.ANDROID_END_UIX_NODE);592 593 File file = null;594 try {595 file = new File(fileName);596 FileUtils.writeStringToFile(file, pageSource, Charset.forName("ASCII"));597 } catch (IOException e) {598 LOGGER.warn("Error has been met during attempt to extract xml tree.", e);599 }600 LOGGER.debug("XML file path: ".concat(fileName));601 return file;602 } catch (Exception e) {603 LOGGER.error("Undefined failure during UiDump generation for Android device!", e);604 }605 606 return null;607 }608 609 private boolean isIOS() {610 return SpecialKeywords.IOS.equalsIgnoreCase(getOs()) || SpecialKeywords.TVOS.equalsIgnoreCase(getOs());611 }612 private boolean isConnected() {613 try {614 if (getOs().equalsIgnoreCase(DeviceType.Type.ANDROID_PHONE.getFamily())) {615 return getConnectedDevices().stream().parallel().anyMatch((m) -> m.contains(getAdbName()));616 } else {617 return false;618 }619 } catch (Throwable thr) {620 //do nothing for now621 return false;622 }623 }...

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIOS()2com.qaprosoft.carina.core.foundation.webdriver.device.Device.isAndroid()3com.qaprosoft.carina.core.foundation.webdriver.device.Device.isMobile()4com.qaprosoft.carina.core.foundation.webdriver.device.Device.isDesktop()5com.qaprosoft.carina.core.foundation.webdriver.device.Device.isTablet()6com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIpad()7com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphone()8com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphoneX()9com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphoneXR()10com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphoneXS()11com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphoneXSMax()12com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphone8()13com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIphone8Plus()

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1if (Device.isIOS()) {2}3if (Device.isAndroid()) {4}5if (Device.isMobile()) {6}7if (Device.isDesktop()) {8}9if (Device.isTablet()) {10}11if (Device.isIPhone()) {12}13if (Device.isIPad()) {14}15if (Device.isAndroidPhone()) {16}17if (Device.isAndroidTablet()) {18}19if (Device.isDesktopChrome()) {20}21if (Device.isDesktopFirefox()) {22}23if (Device.isDesktopIE()) {24}25if (Device.isDesktopSafari()) {26}27if (Device.isDesktopOpera()) {28}

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2if (Device.isIOS()) {3 System.out.println("iOS device");4} else {5 System.out.println("Android device");6}7import com.qaprosoft.carina.core.foundation.webdriver.device.Device;8public class DeviceSample {9 public static void main(String[] args) {10 if (Device.isIOS()) {11 System.out.println("iOS device");12 } else {13 System.out.println("Android device");14 }15 }16}17import com.qaprosoft.carina.core.foundation.webdriver.device.Device;18if (Device.isAndroid()) {19 System.out.println("Android device");20} else {21 System.out.println("iOS device");22}23import com.qaprosoft.carina.core.foundation.webdriver.device.Device;24public class DeviceSample {25 public static void main(String[] args) {26 if (Device.isAndroid()) {27 System.out.println("Android device");28 } else {29 System.out.println("iOS device");30 }31 }32}33import com.qaprosoft.carina.core.foundation.webdriver.device.Device;34if (Device.isAndroid()) {35 System.out.println("Android device");36} else {37 System.out.println("iOS device");38}39import com.qaprosoft.carina.core.foundation.webdriver.device.Device;40public class DeviceSample {41 public static void main(String[] args) {42 if (Device.isAndroid()) {43 System.out.println("Android device");44 } else {45 System.out.println("iOS device");46 }47 }48}49import com.qaprosoft.carina.core.foundation.webdriver.device.Device;50if (Device.isIOS()) {51 System.out.println("iOS device");52} else {53 System.out.println("Android device");54}55import com.qaprosoft.carina.core.foundation.webdriver.device.Device;56public class DeviceSample {57 public static void main(String[] args) {58 if (Device.isIOS()) {59 System.out.println("iOS device");60 } else {61 System.out.println("Android device");62 }63 }64}65import com.qaprosoft.carina.core.foundation.webdriver

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;3import org.testng.Assert;4import org.testng.annotations.Test;5public class DeviceTest {6 public void testIsIOS() {7 Device device = DevicePool.getDevice();8 Assert.assertTrue(device.isIOS(), "Device is not iOS!");9 }10}

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1if (DevicePool.getDevice().isIOS()) {2} else {3}4String deviceName = DevicePool.getDevice().getDeviceName();5String deviceVersion = DevicePool.getDevice().getDeviceVersion();6String devicePlatform = DevicePool.getDevice().getPlatform();7String devicePlatformVersion = DevicePool.getDevice().getPlatformVersion();8String deviceType = DevicePool.getDevice().getDeviceType();9String deviceManufacturer = DevicePool.getDevice().getDeviceManufacturer();10String deviceModel = DevicePool.getDevice().getDeviceModel();11String deviceOrientation = DevicePool.getDevice().getOrientation();12String deviceLanguage = DevicePool.getDevice().getLanguage();13String deviceLocale = DevicePool.getDevice().getLocale();

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIOS()){2}3if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isAndroid()){4}5if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isMobile()){6}7if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isWeb()){8}9if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isDesktop()){10}11if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isAndroidNative()){12}13if(com.qaprosoft.carina.core.foundation.webdriver.device.Device.isIOSNative()){14}

Full Screen

Full Screen

isIOS

Using AI Code Generation

copy

Full Screen

1if(Device.isIOS()) {2} else {3}4if(Device.isAndroid()) {5} else {6}7if(Device.isMobile()) {8} else {9}10if(Device.isDesktop()) {11} else {12}13if(Device.isTablet()) {14} else {15}16if(Device.isPhone()) {17} else {18}19if(Device.isPortrait()) {20} else {21}22if(Device.isLandscape()) {23} else {24}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful