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

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

Source:Device.java Github

copy

Full Screen

...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 ...

Full Screen

Full Screen

getInstalledPackages

Using AI Code Generation

copy

Full Screen

1Device device = new Device();2List<PackageInfo> packages = device.getInstalledPackages();3Device device = new Device();4List<PackageInfo> packages = device.getInstalledPackages();5Device device = new Device();6List<PackageInfo> packages = device.getInstalledPackages();7Device device = new Device();8List<PackageInfo> packages = device.getInstalledPackages();9Device device = new Device();10List<PackageInfo> packages = device.getInstalledPackages();11Device device = new Device();12List<PackageInfo> packages = device.getInstalledPackages();13Device device = new Device();14List<PackageInfo> packages = device.getInstalledPackages();15Device device = new Device();16List<PackageInfo> packages = device.getInstalledPackages();17Device device = new Device();18List<PackageInfo> packages = device.getInstalledPackages();19Device device = new Device();20List<PackageInfo> packages = device.getInstalledPackages();21Device device = new Device();22List<PackageInfo> packages = device.getInstalledPackages();23Device device = new Device();24List<PackageInfo> packages = device.getInstalledPackages();25Device device = new Device();26List<PackageInfo> packages = device.getInstalledPackages();

Full Screen

Full Screen

getInstalledPackages

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2List<PackageInfo> apps = Device.getInstalledPackages();3for(PackageInfo app : apps){4 System.out.println(app.packageName);5}6import com.qaprosoft.carina.core.foundation.webdriver.device.Device;7List<PackageInfo> apps = Device.getInstalledPackages();8for(PackageInfo app : apps){9 System.out.println(app.packageName);10}11import com.qaprosoft.carina.core.foundation.webdriver.device.Device;12List<PackageInfo> apps = Device.getInstalledPackages();13for(PackageInfo app : apps){14 System.out.println(app.packageName);15}16import com.qaprosoft.carina.core.foundation.webdriver.device.Device;17List<PackageInfo> apps = Device.getInstalledPackages();18for(PackageInfo app : apps){19 System.out.println(app.packageName);20}21import com.qaprosoft.carina.core.foundation.webdriver.device.Device;22List<PackageInfo> apps = Device.getInstalledPackages();23for(PackageInfo app : apps){24 System.out.println(app.packageName);25}26import com.qaprosoft.carina.core.foundation.webdriver.device.Device;27List<PackageInfo> apps = Device.getInstalledPackages();28for(PackageInfo app : apps){29 System.out.println(app.packageName);30}31import com.qaprosoft.carina.core.foundation.webdriver.device.Device;32List<PackageInfo> apps = Device.getInstalledPackages();33for(PackageInfo app : apps){34 System.out.println(app.packageName);35}36import com.qaprosoft.carina.core.foundation.webdriver.device.Device;37List<PackageInfo> apps = Device.getInstalledPackages();38for(PackageInfo app : apps){39 System.out.println(app.packageName);40}

Full Screen

Full Screen

getInstalledPackages

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2List<String> installedPackages = Device.getInstalledPackages();3import com.qaprosoft.carina.core.foundation.webdriver.device.Device;4String packageName = "com.qaprosoft.carina.demo";5boolean isPackageInstalled = Device.isPackageInstalled(packageName);6import com.qaprosoft.carina.core.foundation.webdriver.device.Device;7String packageName = "com.qaprosoft.carina.demo";8boolean isPackageInstalled = Device.isPackageInstalled(packageName);9import com.qaprosoft.carina.core.foundation.webdriver.device.Device;10String packageName = "com.qaprosoft.carina.demo";11boolean isPackageInstalled = Device.isPackageInstalled(packageName);12import com.qaprosoft.carina.core.foundation.webdriver.device.Device;13String packageName = "com.qaprosoft.carina.demo";14boolean isPackageInstalled = Device.isPackageInstalled(packageName);15import com.qaprosoft.carina.core.foundation.webdriver.device.Device;16String packageName = "com.qaprosoft.carina.demo";17boolean isPackageInstalled = Device.isPackageInstalled(packageName);18import com.qaprosoft.carina.core.foundation.webdriver.device.Device;19String packageName = "com.qaprosoft.carina.demo";20boolean isPackageInstalled = Device.isPackageInstalled(packageName);21import com.qaprosoft.carina.core.foundation.webdriver.device.Device;22String packageName = "com.qaprosoft.carina.demo";

Full Screen

Full Screen

getInstalledPackages

Using AI Code Generation

copy

Full Screen

1Device device = new Device();2List<String> installedPackages = device.getInstalledPackages();3for (String installedPackage : installedPackages) {4 System.out.println(installedPackage);5}6Device device = new Device();7List<String> installedPackages = device.getInstalledPackages();8for (String installedPackage : installedPackages) {9 System.out.println(installedPackage);10}11Device device = new Device();12List<String> installedPackages = device.getInstalledPackages();13for (String installedPackage : installedPackages) {14 System.out.println(installedPackage);15}16Device device = new Device();17List<String> installedPackages = device.getInstalledPackages();18for (String installedPackage : installedPackages) {19 System.out.println(installedPackage);20}21Device device = new Device();22List<String> installedPackages = device.getInstalledPackages();23for (String installedPackage : installedPackages) {24 System.out.println(installedPackage);25}26Device device = new Device();27List<String> installedPackages = device.getInstalledPackages();28for (String installedPackage : installedPackages) {29 System.out.println(installedPackage);30}31Device device = new Device();32List<String> installedPackages = device.getInstalledPackages();33for (String installedPackage : installedPackages) {34 System.out.println(installedPackage);35}36Device device = new Device();

Full Screen

Full Screen

getInstalledPackages

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.webdriver.device.Device;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.webdriver.device.Device;5public class GetInstalledPackages {6 public void getInstalledPackages() {7 DesiredCapabilities capabilities = new DesiredCapabilities();8 capabilities.setCapability("deviceName", "Android");9 capabilities.setCapability("platformName", "Android");10 capabilities.setCapability("platformVersion", "7.1.1");11 capabilities.setCapability("deviceUDID", "emulator-5554");12 Device device = new Device(capabilities);13 List<String> installedPackages = device.getInstalledPackages();14 System.out.println(installedPackages);15 }16}

Full Screen

Full Screen

getInstalledPackages

Using AI Code Generation

copy

Full Screen

1Device device = DeviceManager.getDevice();2System.out.println(device.getInstalledPackages());3Device device = DeviceManager.getDevice();4System.out.println(device.getInstalledPackages());5Device device = DeviceManager.getDevice();6System.out.println(device.getInstalledPackages());7Device device = DeviceManager.getDevice();8System.out.println(device.getInstalledPackages());9Device device = DeviceManager.getDevice();10System.out.println(device.getInstalledPackages());11Device device = DeviceManager.getDevice();12System.out.println(device.getInstalledPackages());13Device device = DeviceManager.getDevice();14System.out.println(device.getInstalledPackages());

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