How to use getCurrentDeviceFocus method of com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils.getCurrentDeviceFocus

Source:IAndroidUtils.java Github

copy

Full Screen

...581 throw new NoSuchElementException("Scroll timeout has been reached..");582 }583 }584 /**585 * getCurrentDeviceFocus - get actual device apk in focus.586 *587 * @return String588 */589 default public String getCurrentDeviceFocus() {590 String result = executeAdbCommand("shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'");591 return result;592 }593 /**594 * executeAbdCommand595 *596 * @param command597 * String598 * @return String command output in one line599 */600 default public String executeAdbCommand(String command) {601 String deviceName = getDevice().getAdbName();602 if (!deviceName.isEmpty()) {603 // add remoteURL/udid reference...

Full Screen

Full Screen

Source:AndroidService.java Github

copy

Full Screen

...132 * @return String133 */134 public String getCurrentFocusedApkPackageName() {135 String res = "";136 String txt = getCurrentDeviceFocus();137 String regEx1 = ".*?";138// String regEx2 = "((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])";139 Pattern pattern1 = Pattern.compile(regEx1 + regEx1, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);140 Matcher matcher1 = pattern1.matcher(txt);141 if (matcher1.find()) {142 res = matcher1.group(1);143 }144 LOGGER.info("Found package name for application in focus : " + res);145 return res;146 }147 /**148 * get Current Focused Apk Details (apkPackage/apkActivity)149 * 150 * @return apkPackage/apkActivity to use it in openApp method.151 */152 public String getCurrentFocusedApkDetails() {153 try {154 String packageName = "";155 String activityName = "";156 String txt = getCurrentDeviceFocus();157 String regEx1 = ".*?";158 String regEx2 = "((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])";159 Pattern pattern1 = Pattern.compile(regEx1 + regEx2, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);160 Matcher matcher1 = pattern1.matcher(txt);161 if (matcher1.find()) {162 packageName = matcher1.group(1);163 }164 LOGGER.info("Found package name for application in focus : " + packageName);165 String regEx3 = "\\/((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-\\_]+))(?![\\w\\.])";166 Pattern pattern2 = Pattern.compile(regEx1 + regEx3, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);167 Matcher matcher2 = pattern2.matcher(txt);168 if (matcher2.find()) {169 activityName = matcher2.group(1);170 }171 LOGGER.info("Found activity name for application in focus : " + activityName);172 return packageName + "/" + activityName;173 } catch (Exception e) {174 LOGGER.error("Error during getting apk details", e);175 return "";176 }177 }178 179 /**180 * Open Development Settings on device181 */182 public void openDeveloperOptions() {183 executeAdbCommand("shell am start -n com.android.settings/.DevelopmentSettings");184 }185 // End of Common Methods186 // Notification section187 /**188 * expandStatusBar189 */190 public void expandStatusBar() {191 executeAdbCommand("shell service call statusbar 1");192 }193 /**194 * collapseStatusBar195 */196 public void collapseStatusBar() {197 executeAdbCommand("shell service call statusbar 2");198 }199 // TODO: move notifications methods into separate class if possible. Maybe200 // declare notification service instance inside AndroidService201 /**202 * getNotifications203 *204 * @return List of Notification205 */206 public List<Notification> getNotifications() {207 return getNotifications(true);208 }209 /**210 * getNotifications211 *212 * @param withLogger boolean213 * @return List of Notification214 */215 public List<Notification> getNotifications(boolean withLogger) {216 String[] getNotificationsCmd = null;217 String deviceName = IDriverPool.getDefaultDevice().getAdbName();218 if (!deviceName.isEmpty()) {219 getNotificationsCmd = CmdLine.insertCommandsAfter(baseInitCmd, "-s", deviceName, "shell", "dumpsys", "notification");220 } else {221 getNotificationsCmd = CmdLine.insertCommandsAfter(baseInitCmd, "shell", "dumpsys", "notification");222 }223 LOGGER.info("getNotifications cmd was built: " + CmdLine.arrayToString(getNotificationsCmd));224 // TODO: migrate to executeAbdCommand later225 List<Notification> resultList = new ArrayList<Notification>();226 List<String> notificationsOutput = executor.execute(getNotificationsCmd);227 Notification notification = new Notification();228 for (String output : notificationsOutput) {229 boolean found = false;230 Matcher matcher = NOTIFICATION_PATTERN.matcher(output);231 while (matcher.find()) {232 notification.setNotificationPkg(matcher.group(1));233 if (withLogger)234 LOGGER.info(matcher.group(1));235 }236 Matcher matcher2 = NOTIFICATION_TEXT_PATTERN.matcher(output);237 while (matcher2.find()) {238 notification.setNotificationText(matcher2.group(1));239 if (withLogger)240 LOGGER.info(matcher2.group(1));241 found = true;242 }243 if (found) {244 resultList.add(notification);245 if (withLogger)246 LOGGER.info(notification.getNotificationText());247 notification = new Notification();248 found = false;249 }250 }251 if (withLogger)252 LOGGER.info("Found: " + resultList.size() + " notifications.");253 return resultList;254 }255 /**256 * notificationsCount257 *258 * @return notificationsCount259 */260 public int notificationsCount() {261 List<Notification> resultList = getNotifications(false);262 LOGGER.info("Found: " + resultList.size() + " notifications.");263 return resultList.size();264 }265 /**266 * isNotificationWithTextExist267 *268 * @param text String269 * @return boolean270 */271 public boolean isNotificationWithTextExist(String text) {272 List<Notification> resultList = getNotifications(false);273 for (Notification notify : resultList) {274 if (notify.getNotificationText().contains(text)) {275 LOGGER.info("Found '" + text + "' in notification '" + notify.getNotificationText() + "'.");276 return true;277 }278 }279 return false;280 }281 /**282 * waitUntilNewNotificationAppear283 *284 * @param text String285 * @param timeout long286 * @return boolean287 */288 public boolean waitUntilNewNotificationAppear(String text, long timeout) {289 // boolean found = false;290 int base = notificationsCount();291 int time = 0;292 boolean foundText = isNotificationWithTextExist(text);293 int actual = notificationsCount();294 while (actual <= base && ++time < timeout && !foundText) {295 LOGGER.info("Wait for notification. Second: " + time + ". Actual number:" + actual);296 CommonUtils.pause(1);297 actual = notificationsCount();298 foundText = isNotificationWithTextExist(text);299 }300 return (foundText);301 }302 /**303 * isNotificationPkgExist304 *305 * @param text package text306 * @return boolean307 */308 public boolean isNotificationPkgExist(String text) {309 List<Notification> resultList = getNotifications(false);310 for (Notification notify : resultList) {311 if (notify.getNotificationPkg().contains(text)) {312 LOGGER.info("Found '" + text + "' in notification packages '" + notify.getNotificationPkg() + "' with text '"313 + notify.getNotificationText() + "'.");314 return true;315 }316 }317 return false;318 }319 /**320 * waitUntilNewNotificationPackageAppear321 *322 * @param pkg String323 * @param timeout long324 * @return boolean325 */326 public boolean waitUntilNewNotificationPackageAppear(String pkg, long timeout) {327 // boolean found = false;328 int base = notificationsCount();329 int time = 0;330 boolean foundText = isNotificationPkgExist(pkg);331 int actual = notificationsCount();332 while (actual <= base && ++time < timeout && !foundText) {333 LOGGER.info("Wait for notification. Second: " + time + ". Actual number:" + actual);334 CommonUtils.pause(1);335 actual = notificationsCount();336 foundText = isNotificationPkgExist(pkg);337 }338 return (foundText);339 }340 /**341 * find Expected Notification with partial text342 *343 * @param expectedTitle String344 * @param expectedText String345 * @return boolean346 */347 public boolean findExpectedNotification(String expectedTitle, String expectedText) {348 return findExpectedNotification(expectedTitle, expectedText, true);349 }350 /**351 * find Expected Notification352 *353 * @param expectedTitle String354 * @param expectedText String355 * @param partially boolean356 * @return boolean357 */358 @SuppressWarnings("rawtypes")359 public boolean findExpectedNotification(String expectedTitle, String expectedText, boolean partially) {360 // open notification361 try {362 ((AndroidDriver) castDriver()).openNotifications();363 CommonUtils.pause(2); // wait while notifications are playing animation to364 // appear to avoid missed taps365 } catch (Exception e) {366 LOGGER.error("Error during searching notification: " + expectedTitle, e);367 LOGGER.info("Using adb to expand Status bar. ");368 expandStatusBar();369 }370 NotificationPage nativeNotificationPage = new NotificationPage(getDriver());371 LOGGER.info("Native notification page is loaded: " + nativeNotificationPage.isNativeNotificationPage());372 int itemsListSize = nativeNotificationPage.getLastItemsContentSize();373 String title, text;374 int notificationItemNum = 0;375 for (int i = 0; i <= itemsListSize; i++) {376 title = nativeNotificationPage.getItemTitle(i);377 text = nativeNotificationPage.getItemText(i);378 LOGGER.info("Notification title is: " + title);379 LOGGER.info("Notification text is: " + text);380 if (!expectedTitle.isEmpty()) {381 if (title.equals(expectedTitle)) {382 notificationItemNum = i;383 LOGGER.info("Found expected title '" + expectedTitle + "' in notification #" + notificationItemNum);384 return true;385 } else if (partially) {386 if (expectedTitle.contains(title)) {387 notificationItemNum = i;388 LOGGER.info(389 "Found that expected title '" + expectedTitle + "' contains '" + title + "' in notification #" + notificationItemNum);390 return true;391 }392 }393 }394 if (!expectedText.isEmpty()) {395 if (text.equals(expectedText)) {396 notificationItemNum = i;397 LOGGER.info("Found expected text '" + expectedText + "' in notification #" + notificationItemNum);398 return true;399 } else if (partially) {400 if (expectedText.contains(text)) {401 notificationItemNum = i;402 LOGGER.info(403 "Found that expected text '" + expectedText + "' contains '" + text + "' in notification #" + notificationItemNum);404 return true;405 }406 }407 }408 }409 return false;410 }411 /**412 * clearNotifications413 */414 public void clearNotifications() {415 LOGGER.info("Clear notifications");416 NotificationPage notificationPage = new NotificationPage(getDriver());417 int attempts = 3;418 boolean isStatusBarOpened;419 // three attempts will be executed to clear notifications420 for (int i = 0; i < attempts; i++) {421 collapseStatusBar();422 expandStatusBar();423 // wait until status bar will be opened424 isStatusBarOpened = notificationPage.isOpened(INIT_TIMEOUT);425 if (!isStatusBarOpened) {426 LOGGER.info(String.format("Status bar isn't opened after %d seconds. One more attempt.", (int) INIT_TIMEOUT));427 expandStatusBar();428 }429 LOGGER.debug("Page source [expand status bar]: ".concat(getDriver().getPageSource()));430 Screenshot.captureByRule(getDriver(), "Clear notification - screenshot. Status bar should be opened. Attempt: " + i);431 try {432 notificationPage.clearNotifications();433 } catch (Exception e) {434 LOGGER.info("Exception during notification extraction.");435 }436 }437 collapseStatusBar();438 }439 /**440 * isStatusBarExpanded441 *442 * @return boolean443 */444 public boolean isStatusBarExpanded() {445 NotificationPage notificationPage = new NotificationPage(getDriver());446 return notificationPage.isStatusBarExpanded();447 }448 // End of Notification section449 // Fake GPS section450 /**451 * startFakeGPS to emulate GPS location452 *453 * @param location String - existing city (for ex. New York)454 * @return boolean return true if everything is ok.455 */456 public boolean setFakeGPSLocation(String location) {457 return setFakeGPSLocation(location, false);458 }459 /**460 * startFakeGPS to emulate GPS location461 *462 * @param location String - existing city (for ex. New York)463 * @param restartApk - if true restartDriver(true);464 * @return boolean return true if everything is ok.465 */466 public boolean setFakeGPSLocation(String location, boolean restartApk) {467 getDriver();468 boolean res = false;469 installApk(FAKE_GPS_APP_PATH, true);470 String activity = FAKE_GPS_APP_ACTIVITY;471 try {472 forceFakeGPSApkOpen();473 FakeGpsPage fakeGpsPage = new FakeGpsPage(getDriver());474 if (!fakeGpsPage.isOpened(1)) {475 LOGGER.error("Fake GPS application should be open but wasn't. Force opening.");476 openApp(activity);477 CommonUtils.pause(2);478 }479 res = fakeGpsPage.locationSearch(location);480 if (res) {481 LOGGER.info("Set Fake GPS locale: " + location);482 hideKeyboard();483 fakeGpsPage.clickSetLocation();484 }485 res = true;486 if (restartApk)487 restartDriver(true);488 } catch (Exception e) {489 LOGGER.error("Exception: ", e);490 }491 return res;492 }493 /**494 * stopFakeGPS stop using Fake GPS495 *496 * @return boolean497 */498 public boolean stopFakeGPS() {499 return stopFakeGPS(false);500 }501 /**502 * stopFakeGPS stop using Fake GPS503 *504 * @param restartApk - if true restartDriver(true);505 * @return boolean506 */507 public boolean stopFakeGPS(boolean restartApk) {508 getDriver();509 boolean res = false;510 String activity = FAKE_GPS_APP_ACTIVITY;511 try {512 forceFakeGPSApkOpen();513 FakeGpsPage fakeGpsPage = new FakeGpsPage(getDriver());514 if (!fakeGpsPage.isOpened(1)) {515 LOGGER.error("Fake GPS application should be open but wasn't. Force opening.");516 openApp(activity);517 CommonUtils.pause(2);518 }519 LOGGER.info("STOP Fake GPS locale");520 res = fakeGpsPage.clickStopFakeGps();521 if (restartApk)522 restartDriver(true);523 } catch (Exception e) {524 LOGGER.error("Exception: ", e);525 }526 LOGGER.info("Stop Fake GPS button was clicked: " + res);527 return res;528 }529 /**530 * forceFakeGPSApkOpen531 *532 * @return boolean533 */534 private boolean forceFakeGPSApkOpen() {535 return forceApkOpen(FAKE_GPS_APP_ACTIVITY, FAKE_GPS_APP_PACKAGE, FAKE_GPS_APP_PATH);536 }537 /**538 * forceApkOpen539 *540 * @param activity String541 * @param packageName String542 * @param apkPath String543 * @return boolean544 */545 private boolean forceApkOpen(String activity, String packageName, String apkPath) {546 boolean res;547 int attemps = 3;548 boolean isApkOpened = isAppRunning(packageName);549 while (!isApkOpened && attemps > 0) {550 LOGGER.info("Apk was not open. Attempt to open...");551 openApp(activity);552 CommonUtils.pause(2);553 isApkOpened = isAppRunning(packageName);554 attemps--;555 }556 if (!isApkOpened) {557 LOGGER.info("Probably APK was not installed correctly. Try to reinstall.");558 installApk(apkPath, true);559 openApp(activity);560 CommonUtils.pause(2);561 }562 if (isAppRunning(packageName)) {563 LOGGER.info("On '" + packageName + "' apk page");564 res = true;565 } else {566 LOGGER.error("Not on '" + packageName + "' page after all tries. Please check logs.");567 res = false;568 }569 return res;570 }571 // End of Fake GPS section572 // TimeZone change section573 /**574 * switchDeviceAutoTimeAndTimeZone575 *576 * @param autoSwitch boolean. If true - auto Time and TimeZone will be set577 * as On.578 */579 public void switchDeviceAutoTimeAndTimeZone(boolean autoSwitch) {580 String value = "0";581 if (autoSwitch) {582 value = "1";583 }584 executeAdbCommand("shell settings put global auto_time " + value);585 executeAdbCommand("shell settings put global auto_time_zone " + value);586 }587 /**588 * get Device Time Zone589 *590 * @return DeviceTimeZone591 */592 public DeviceTimeZone getDeviceTimeZone() {593 return getDeviceTimeZone("");594 }595 /**596 * get Device Time Zone. Set default TimeZone597 *598 * @param defaultTZ - default string.599 * @return DeviceTimeZone600 */601 public DeviceTimeZone getDeviceTimeZone(String defaultTZ) {602 getDriver(); // start driver in before class to assign it for particular603 // thread604 DeviceTimeZone dt = new DeviceTimeZone();605 String value = executeAdbCommand("shell settings get global auto_time");606 if (value.contains("0")) {607 dt.setAutoTime(false);608 } else {609 dt.setAutoTime(true);610 }611 value = executeAdbCommand("shell settings get global auto_time_zone");612 if (value.contains("0")) {613 dt.setAutoTimezone(false);614 } else {615 dt.setAutoTimezone(true);616 }617 value = executeAdbCommand("shell settings get system time_12_24");618 if (value.contains("12")) {619 dt.setTimeFormat(TimeFormat.FORMAT_12);620 } else {621 dt.setTimeFormat(TimeFormat.FORMAT_24);622 }623 if (defaultTZ.isEmpty()) {624 value = executeAdbCommand("shell getprop persist.sys.timezone");625 if (!value.isEmpty()) {626 dt.setTimezone(value);627 }628 } else {629 dt.setTimezone(defaultTZ);630 }631 value = executeAdbCommand("shell date -s %mynow%");632 LOGGER.info(value);633 if (!value.isEmpty()) {634 value = convertDateInCorrectString(parseOutputDate(value));635 dt.setSetDeviceDateTime(value);636 LOGGER.info(value);637 }638 dt.setChangeDateTime(false);639 dt.setRefreshDeviceTime(true);640 LOGGER.info(dt.toString());641 return dt;642 }643 /**644 * get Device Actual TimeZone645 *646 * @return String647 */648 public String getDeviceActualTimeZone() {649 String value = executeAdbCommand("shell getprop persist.sys.timezone");650 if (!value.isEmpty()) {651 LOGGER.info(value);652 }653 return value;654 }655 // Start of TimeZone Setting section656 /**657 * set Device TimeZone by using Apk658 *659 * @param timeZone String required timeZone in Android standard format660 * (Europe/London)661 * @param timeFormat String 12 or 24662 * @return boolean663 */664 public boolean setDeviceTimeZone(String timeZone, TimeFormat timeFormat) {665 return setDeviceTimeZone(timeZone, "", timeFormat, "", ChangeTimeZoneWorkflow.APK);666 }667 /**668 * set Device TimeZone using all supported workflows. By ADB, Settings and669 * Apk670 *671 * @param timeZone String required timeZone672 * @param timeFormat String 12 or 24673 * @param settingsTZ TimeFormat674 * @return boolean675 */676 public boolean setDeviceTimeZone(String timeZone, String settingsTZ, TimeFormat timeFormat) {677 return setDeviceTimeZone(timeZone, settingsTZ, timeFormat, "", ChangeTimeZoneWorkflow.ALL);678 }679 /**680 * set Device TimeZone. By required workflow: ADB, Settings or APK681 *682 * @param timeZone String required timeZone683 * @param timeFormat String 12 or 24684 * @param gmtStamp String685 * @param settingsTZ TimeFormat686 * @param workflow ChangeTimeZoneWorkflow687 * @return boolean688 */689 public boolean setDeviceTimeZone(String timeZone, String settingsTZ, TimeFormat timeFormat, String gmtStamp, ChangeTimeZoneWorkflow workflow) {690 boolean changed = false;691 getDriver(); // start driver in before class to assign it for particular692 // thread693 String actualTZ = getDeviceActualTimeZone();694 if (isRequiredTimeZone(actualTZ, timeZone)) {695 LOGGER.info("Required TimeZone is already set.");696 return true;697 }698 String currentAndroidVersion = IDriverPool.getDefaultDevice().getOsVersion();699 LOGGER.info("currentAndroidVersion=" + currentAndroidVersion);700 if (currentAndroidVersion.contains("7.") ||701 (IDriverPool.getDefaultDevice().getDeviceType() == DeviceType.Type.ANDROID_TABLET && !currentAndroidVersion.contains("8."))) {702 LOGGER.info("TimeZone changing for Android 7+ and tablets works only by TimeZone changer apk.");703 workflow = ChangeTimeZoneWorkflow.APK;704 }705 // Solution for ADB timezone changing.706 if (ChangeTimeZoneWorkflow.ADB.isSupported(workflow)) {707 LOGGER.info("Try to change TimeZone by ADB");708 LOGGER.info(setDeviceTimeZoneByADB(timeZone, timeFormat, ""));709 changed = applyTZChanges(ChangeTimeZoneWorkflow.ADB, timeZone);710 }711 // Solution for timezone changing by device Settings. (Tested on S7,712 // Note 3, S6, S5).713 if (!changed && ChangeTimeZoneWorkflow.SETTINGS.isSupported(workflow)) {714 LOGGER.info("Try to change TimeZone by Device Settings");715 setDeviceTimeZoneBySetting(timeZone, settingsTZ, timeFormat, gmtStamp);716 changed = applyTZChanges(ChangeTimeZoneWorkflow.SETTINGS, timeZone);717 }718 // Solution for using TimeZone Changer apk.719 if (!changed && ChangeTimeZoneWorkflow.APK.isSupported(workflow)) {720 LOGGER.info("Try to change TimeZone by TimeZone Changer apk.");721 setDeviceTimeZoneByChangerApk(timeZone, timeFormat);722 changed = applyTZChanges(ChangeTimeZoneWorkflow.APK, timeZone);723 }724 return changed;725 }726 // End of TimeZone change sections727 /**728 * Open camera on device729 */730 public void openCamera() {731 LOGGER.info("Camera will be opened");732 executeAdbCommand("shell am start -a android.media.action.IMAGE_CAPTURE");733 }734 /**735 * Android camera should be already opened736 */737 public void takePhoto() {738 LOGGER.info("Will take photo");739 executeAdbCommand("shell input keyevent KEYCODE_CAMERA");740 }741 // Private section742 // TimeZone Private methods743 /**744 * setDeviceTimeZoneByADB745 *746 * @param timeZone String747 * @param timeFormat TimeFormat748 * @param deviceSetDate String in format yyyyMMdd.HHmmss. Can be empty.749 * @return String750 */751 private String setDeviceTimeZoneByADB(String timeZone, TimeFormat timeFormat, String deviceSetDate) {752 boolean changeDateTime = true;753 String tzGMT = "";754 if (deviceSetDate.isEmpty()) {755 changeDateTime = false;756 }757 DeviceTimeZone dt = new DeviceTimeZone(false, false, timeFormat, timeZone, tzGMT, deviceSetDate, changeDateTime, true);758 return setDeviceTimeZoneByADB(dt);759 }760 /**761 * setDeviceTimeZoneByADB Automatic date and time = OFF (settings - date and762 * time) adb shell settings put global auto_time 0 Automatic time zone = OFF763 * (settings - date and time) adb shell settings put global auto_time_zone 0764 * <p>765 * Set Time Zone on device adb shell setprop persist.sys.timezone766 * "America/Chicago"767 * <p>768 * Check timezones: <a href=769 * "https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">List_of_tz_database_time_zones</a>770 * <p>771 * Check time on device adb shell date -s %mynow%772 * <p>773 * Restart application774 *775 * @param dt DeviceTimeZone776 * @return String actual Device Date and Time777 */778 private String setDeviceTimeZoneByADB(DeviceTimeZone dt) {779 if (dt == null) {780 LOGGER.error("DeviceTimeZone is not initialised.");781 dt = new DeviceTimeZone();782 }783 LOGGER.info(dt.toString());784 String autoTime = "0";785 String autoTimeZone = "0";786 if (dt.isAutoTime()) {787 autoTime = "1";788 }789 executeAdbCommand("shell settings put global auto_time " + autoTime);790 if (dt.isAutoTimezone()) {791 autoTimeZone = "1";792 }793 executeAdbCommand("shell settings put global auto_time_zone " + autoTimeZone);794 setSystemTime(dt.getTimeFormat());795 if (!dt.getTimezone().isEmpty()) {796 executeAdbCommand("shell setprop persist.sys.timezone \"" + dt.getTimezone() + "\"");797 }798 if (dt.isRefreshDeviceTime()) {799 executeAdbCommand("shell am broadcast -a android.intent.action.TIME_SET");800 }801 if (dt.isChangeDateTime() && !dt.getSetDeviceDateTime().isEmpty()) {802 // Try to set date for device but it will not work on not rooted803 // devices804 executeAdbCommand("shell date " + dt.getSetDeviceDateTime());805 }806 String actualDT = executeAdbCommand("shell date -s %mynow%");807 LOGGER.info(actualDT);808 return actualDT;809 }810 /**811 * setDeviceTimeZoneBySetting812 *813 * @param timeZone String814 * @param settingsTZ String815 * @param timeFormat TimeFormat816 * @param gmtStamp String817 */818 private void setDeviceTimeZoneBySetting(String timeZone, String settingsTZ, TimeFormat timeFormat, String gmtStamp) {819 String actualTZ = getDeviceActualTimeZone();820 // String tz = DeviceTimeZone.getTimezoneOffset(timeZone);821 if (isRequiredTimeZone(actualTZ, timeZone)) {822 LOGGER.info("Required timeZone is already set.");823 return;824 }825 try {826 openDateTimeSettingsSetupWizard(true, timeFormat);827 String res = getCurrentDeviceFocus();828 if (res.contains(".Settings$DateTimeSettingsActivity")) {829 LOGGER.info("On '.Settings$DateTimeSettingsActivity' page");830 } else {831 LOGGER.error("Not on '.Settings$DateTimeSettingsActivity' page");832 }833 DateTimeSettingsPage dtSettingsPage = new DateTimeSettingsPage(getDriver());834 if (!dtSettingsPage.isOpened()) {835 openDateTimeSettingsSetupWizard(true, timeFormat);836 }837 if (dtSettingsPage.isOpened()) {838 LOGGER.info("Date Time Settings page was open.");839 } else {840 LOGGER.error("Date Time Settings page should be open.");841 }...

Full Screen

Full Screen

getCurrentDeviceFocus

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;5import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils.DeviceFocus;6import com.qaprosoft.carina.core.foundation.utils.android.impl.AndroidUtils;7import com.qaprosoft.carina.core.foundation.utils.mobile.MobileUtils;8import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;9import com.qaprosoft.carina.demo.gui.pages.android.LoginPage;10import com.qaprosoft.carina.demo.gui.pages.common.HomeBasePage;11import com.qaprosoft.carina.demo.gui.pages.common.LoginBasePage;12public class AndroidSampleTest extends AndroidSampleTestBase {13 public void testLogin() {14 LoginBasePage loginPage = initPage(getDriver(), LoginPage.class);15 Assert.assertTrue(loginPage.isPageOpened(), "Login page is not opened!");16 HomeBasePage homePage = loginPage.login(getUser());17 Assert.assertTrue(homePage.isPageOpened(), "Home page is not opened!");18 homePage.getHeader().logout();19 Assert.assertTrue(loginPage.isPageOpened(), "Login page is not opened!");20 }21 public void testLogin2() {22 LoginBasePage loginPage = initPage(getDriver(), LoginPage.class);23 Assert.assertTrue(loginPage.isPageOpened(), "Login page is not opened!");24 HomeBasePage homePage = loginPage.login(getUser());25 Assert.assertTrue(homePage.isPageOpened(), "Home page is not opened!");26 homePage.getHeader().logout();27 Assert.assertTrue(loginPage.isPageOpened(), "Login page is not opened!");28 }29 public void testLogin3() {30 LoginBasePage loginPage = initPage(getDriver(), LoginPage.class);31 Assert.assertTrue(loginPage.isPageOpened(), "Login page is not opened!");32 HomeBasePage homePage = loginPage.login(getUser());

Full Screen

Full Screen

getCurrentDeviceFocus

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) throws Exception {3 IAndroidUtils androidUtils = new AndroidUtils();4 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();5 System.out.println(currentDeviceFocus);6 }7}8public class 2 {9 public static void main(String[] args) throws Exception {10 IAndroidUtils androidUtils = new AndroidUtils();11 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();12 System.out.println(currentDeviceFocus);13 }14}15public class 3 {16 public static void main(String[] args) throws Exception {17 IAndroidUtils androidUtils = new AndroidUtils();18 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();19 System.out.println(currentDeviceFocus);20 }21}22public class 4 {23 public static void main(String[] args) throws Exception {24 IAndroidUtils androidUtils = new AndroidUtils();25 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();26 System.out.println(currentDeviceFocus);27 }28}29public class 5 {30 public static void main(String[] args) throws Exception {31 IAndroidUtils androidUtils = new AndroidUtils();32 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();33 System.out.println(currentDeviceFocus);34 }35}36public class 6 {37 public static void main(String[] args) throws Exception {38 IAndroidUtils androidUtils = new AndroidUtils();39 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();40 System.out.println(currentDeviceFocus);41 }42}43public class 7 {

Full Screen

Full Screen

getCurrentDeviceFocus

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;2import com.qaprosoft.carina.core.foundation.utils.android.impl.AndroidUtils;3public class 1 {4public static void main(String[] args) throws Exception {5IAndroidUtils androidUtils = new AndroidUtils();6System.out.println(androidUtils.getCurrentDeviceFocus());7}8}9import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;10import com.qaprosoft.carina.core.foundation.utils.android.impl.AndroidUtils;11public class 2 {12public static void main(String[] args) throws Exception {13IAndroidUtils androidUtils = new AndroidUtils();14System.out.println(androidUtils.getDeviceFocus("appium"));15}16}17import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;18import com.qaprosoft.carina.core.foundation.utils.android.impl.AndroidUtils;19public class 3 {20public static void main(String[] args) throws Exception {21IAndroidUtils androidUtils = new AndroidUtils();22System.out.println(androidUtils.getDeviceFocus("appium", "com.android.calculator2", "com.android.calculator2.Calculator"));23}24}25import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;26import com.qaprosoft.carina.core.foundation.utils.android.impl.AndroidUtils;27public class 4 {28public static void main(String[] args) throws Exception {29IAndroidUtils androidUtils = new AndroidUtils();30System.out.println(androidUtils.getDeviceFocus("appium", "com.android.calculator2", "com.android.calculator2.Calculator", "com.android.calculator2.Calculator"));31}32}33import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;34import com

Full Screen

Full Screen

getCurrentDeviceFocus

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.annotations.Test;3import org.testng.Assert;4import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;5public class AndroidUtilsGetCurrentDeviceFocusTest {6public void testGetCurrentDeviceFocus() {7IAndroidUtils androidUtils = (IAndroidUtils) IAndroidUtils.getInstance();8String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();9Assert.assertNotNull(currentDeviceFocus, "Current device focus is null");10}11}12package com.qaprosoft.carina.demo;13import org.testng.annotations.Test;14import org.testng.Assert;15import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;16public class AndroidUtilsGetDeviceFocusTest {17public void testGetDeviceFocus() {18IAndroidUtils androidUtils = (IAndroidUtils) IAndroidUtils.getInstance();19String deviceFocus = androidUtils.getDeviceFocus();20Assert.assertNotNull(deviceFocus, "Device focus is null");21}22}23package com.qaprosoft.carina.demo;24import org.testng.annotations.Test;25import org.testng.Assert;26import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;27public class AndroidUtilsGetDeviceFocusTest {28public void testGetDeviceFocus() {29IAndroidUtils androidUtils = (IAndroidUtils) IAndroidUtils.getInstance();30String deviceFocus = androidUtils.getDeviceFocus();31Assert.assertNotNull(deviceFocus, "Device focus is null");32}33}34package com.qaprosoft.carina.demo;35import org.testng.annotations.Test;36import org.testng.Assert;37import com.qaprosoft.carina.core.foundation.utils.android.IAndroidUtils;38public class AndroidUtilsGetDeviceFocusTest {39public void testGetDeviceFocus() {40IAndroidUtils androidUtils = (IAndroidUtils) IAndroidUtils.getInstance();41String deviceFocus = androidUtils.getDeviceFocus();42Assert.assertNotNull(deviceFocus, "Device focus is null");43}44}

Full Screen

Full Screen

getCurrentDeviceFocus

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.utils.android;2import org.openqa.selenium.WebDriver;3public class GetCurrentDeviceFocus {4 public static void main(String[] args) {5 WebDriver driver = null;6 IAndroidUtils androidUtils = new IAndroidUtils(driver);

Full Screen

Full Screen

getCurrentDeviceFocus

Using AI Code Generation

copy

Full Screen

1 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();2 String currentDeviceFocus = androidUtils.getCurrentDeviceFocus();3 System.out.println("Current Device Focus: " + currentDeviceFocus);4 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();5 String androidVersion = androidUtils.getAndroidVersion();6 System.out.println("Android Version: " + androidVersion);7 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();8 String androidVersion = androidUtils.getAndroidVersion();9 System.out.println("Android Version: " + androidVersion);10 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();11 String androidVersion = androidUtils.getAndroidVersion();12 System.out.println("Android Version: " + androidVersion);13 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();14 String androidVersion = androidUtils.getAndroidVersion();15 System.out.println("Android Version: " + androidVersion);16 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();17 boolean appInstalled = androidUtils.isAppInstalled("com.android.chrome");18 System.out.println("App Installed: " + appInstalled);19 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();20 boolean appInstalled = androidUtils.isAppInstalled("com.android.chrome");21 System.out.println("App Installed: " + appInstalled);22 IAndroidUtils androidUtils = (IAndroidUtils) getDriver().getUtils();

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