How to use format method of com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone.format

Source:AndroidService.java Github

copy

Full Screen

...445 expandStatusBar();446 // wait until status bar will be opened447 isStatusBarOpened = notificationPage.isOpened(INIT_TIMEOUT);448 if (!isStatusBarOpened) {449 LOGGER.info(String.format("Status bar isn't opened after %d seconds. One more attempt.",450 (int) INIT_TIMEOUT));451 expandStatusBar();452 }453 LOGGER.debug("Page source [expand status bar]: ".concat(454 getDriver().getPageSource()));455 Screenshot.capture(getDriver(),456 "Clear notification - screenshot. Status bar should be opened. Attempt: " + i);457 try {458 notificationPage.clearNotifications();459 } catch (Exception e) {460 LOGGER.info("Exception during notification extraction.");461 }462 }463 collapseStatusBar();464 }465 /**466 * isStatusBarExpanded467 *468 * @return boolean469 */470 public boolean isStatusBarExpanded() {471 NotificationPage notificationPage = new NotificationPage(getDriver());472 return notificationPage.isStatusBarExpanded();473 }474 // End of Notification section475 // Change Device Language section476 /**477 * change Android Device Language with default parameters478 *479 * @param language String480 * @return boolean481 */482 public boolean setDeviceLanguage(String language) {483 return setDeviceLanguage(language, true, 20);484 }485 /**486 * change Android Device Language487 * <p>488 * Url: <a href="http://play.google.com/store/apps/details?id=net.sanapeli.adbchangelanguage&hl=ru&rdid=net.sanapeli.adbchangelanguage">489 * ADBChangeLanguage apk490 * </a>491 * Change locale (language) of your device via ADB (on Android OS version 6.0, 5.0, 4.4, 4.3, 4.2 and older).492 * No need to root your device! With ADB (Android Debug Bridge) on your computer,493 * you can fast switch the device locale to see how your application UI looks on different languages.494 * Usage:495 * - install this app496 * - setup adb connection to your device (http://developer.android.com/tools/help/adb.html)497 * - Android OS 4.2 onwards (tip: you can copy the command here and paste it to your command console):498 * adb shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE_CONFIGURATION499 * <p>500 * English: adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language en501 * Russian: adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language ru502 * Spanish: adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language es503 *504 * @param language to set. Can be es, en, etc.505 * @param changeConfig boolean if true - update config locale and language params506 * @param waitTime int wait in seconds before device refresh.507 * @return boolean508 */509 public boolean setDeviceLanguage(String language, boolean changeConfig, int waitTime) {510 boolean status = false;511 language = language.toLowerCase();512 if (getDeviceLanguage().toLowerCase().contains(language)) {513 LOGGER.info("Device already have expected language.");514 return true;515 }516 String setLocalizationChangePermissionCmd = "shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE_CONFIGURATION";517 String setLocalizationCmd = "shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language " + language;518 LOGGER.info("Try set localization change permission with following cmd:"519 + setLocalizationChangePermissionCmd);520 String expandOutput = executeAbdCommand(setLocalizationChangePermissionCmd);521 if (expandOutput.contains("Unknown package: net.sanapeli.adbchangelanguage")) {522 LOGGER.info("Looks like 'ADB Change Language apk' is not installed. Install it and try again.");523 installApk(LANGUAGE_CHANGE_APP_PATH, true);524 expandOutput = executeAbdCommand(setLocalizationChangePermissionCmd);525 }526 LOGGER.info("Output after set localization change permission using 'ADB Change Language apk': "527 + expandOutput);528 LOGGER.info("Try set localization to '" + language529 + "' with following cmd: "530 + setLocalizationCmd);531 String changeLocaleOutput = executeAbdCommand(setLocalizationCmd);532 LOGGER.info("Output after set localization to '" + language533 + "' using 'ADB Change Language apk' : " + changeLocaleOutput);534 if (waitTime > 0) {535 LOGGER.info("Wait for at least '" + waitTime536 + "' seconds before device refresh.");537 pause(waitTime);538 }539 if (changeConfig) {540 String loc;541 String lang;542 if (language.contains("_")) {543 lang = language.split("_")[0];544 loc = language.split("_")[1];545 } else {546 lang = language;547 loc = language;548 }549 LOGGER.info("Update config.properties locale to '" + loc + "' and language to '" + lang + "'.");550 R.CONFIG.put("locale", loc);551 R.CONFIG.put("language", lang);552 }553 if (getDeviceLanguage().toLowerCase().contains(language)) {554 status = true;555 } else {556 if (getDeviceLanguage().isEmpty()) {557 LOGGER.info("Adb return empty response without errors.");558 status = true;559 } else {560 String currentAndroidVersion = DevicePool.getDevice().getOsVersion();561 LOGGER.info("currentAndroidVersion=" + currentAndroidVersion);562 if (currentAndroidVersion.contains("7.")) {563 LOGGER.info("Adb return language command do not work on some Android 7+ devices." +564 " Check that there are no error.");565 status = !getDeviceLanguage().toLowerCase().contains("error");566 }567 }568 }569 return status;570 }571 /**572 * getDeviceLanguage573 *574 * @return String575 */576 public String getDeviceLanguage() {577 return executeAbdCommand("shell getprop persist.sys.language");578 }579 // End Language Change section580 // Fake GPS section581 /**582 * startFakeGPS to emulate GPS location583 *584 * @param location String - existing city (for ex. New York)585 * @return boolean return true if everything is ok.586 */587 public boolean setFakeGPSLocation(String location) {588 return setFakeGPSLocation(location, false);589 }590 /**591 * startFakeGPS to emulate GPS location592 *593 * @param location String - existing city (for ex. New York)594 * @param restartApk - if true DriverPool.restartDriver(true);595 * @return boolean return true if everything is ok.596 */597 public boolean setFakeGPSLocation(String location, boolean restartApk) {598 getDriver();599 boolean res = false;600 installApk(FAKE_GPS_APP_PATH, true);601 String activity = FAKE_GPS_APP_ACTIVITY;602 try {603 forceFakeGPSApkOpen();604 FakeGpsPage fakeGpsPage = new FakeGpsPage(getDriver());605 if (!fakeGpsPage.isOpened(1)) {606 LOGGER.error("Fake GPS application should be open but wasn't. Force opening.");607 openApp(activity);608 pause(2);609 }610 res = fakeGpsPage.locationSearch(location);611 if (res) {612 LOGGER.info("Set Fake GPS locale: " + location);613 AndroidUtils.hideKeyboard();614 fakeGpsPage.clickSetLocation();615 }616 res = true;617 if (restartApk) DriverPool.restartDriver(true);618 } catch (Exception e) {619 LOGGER.error("Exception: ", e);620 }621 return res;622 }623 /**624 * stopFakeGPS stop using Fake GPS625 *626 * @return boolean627 */628 public boolean stopFakeGPS() {629 return stopFakeGPS(false);630 }631 /**632 * stopFakeGPS stop using Fake GPS633 *634 * @param restartApk - if true DriverPool.restartDriver(true);635 * @return boolean636 */637 public boolean stopFakeGPS(boolean restartApk) {638 getDriver();639 boolean res = false;640 String activity = FAKE_GPS_APP_ACTIVITY;641 try {642 forceFakeGPSApkOpen();643 FakeGpsPage fakeGpsPage = new FakeGpsPage(getDriver());644 if (!fakeGpsPage.isOpened(1)) {645 LOGGER.error("Fake GPS application should be open but wasn't. Force opening.");646 openApp(activity);647 pause(2);648 }649 LOGGER.info("STOP Fake GPS locale");650 res = fakeGpsPage.clickStopFakeGps();651 if (restartApk) DriverPool.restartDriver(true);652 } catch (Exception e) {653 LOGGER.error("Exception: ", e);654 }655 LOGGER.info("Stop Fake GPS button was clicked: " + res);656 return res;657 }658 /**659 * forceFakeGPSApkOpen660 *661 * @return boolean662 */663 private boolean forceFakeGPSApkOpen() {664 return forceApkOpen(FAKE_GPS_APP_ACTIVITY, FAKE_GPS_APP_PACKAGE, FAKE_GPS_APP_PATH);665 }666 /**667 * forceApkOpen668 *669 * @param activity String670 * @param packageName String671 * @param apkPath String672 * @return boolean673 */674 private boolean forceApkOpen(String activity, String packageName, String apkPath) {675 boolean res;676 int attemps = 3;677 boolean isApkOpened = checkCurrentDeviceFocus(packageName);678 while (!isApkOpened && attemps > 0) {679 LOGGER.info("Apk was not open. Attempt to open...");680 openApp(activity);681 pause(2);682 isApkOpened = checkCurrentDeviceFocus(packageName);683 attemps--;684 }685 if (!isApkOpened) {686 LOGGER.info("Probably APK was not installed correctly. Try to reinstall.");687 installApk(apkPath, true);688 openApp(activity);689 pause(2);690 }691 if (checkCurrentDeviceFocus(packageName)) {692 LOGGER.info("On '" + packageName + "' apk page");693 res = true;694 } else {695 LOGGER.error("Not on '" + packageName + "' page after all tries. Please check logs.");696 res = false;697 }698 return res;699 }700 // End of Fake GPS section701 // TimeZone change section702 /**703 * switchDeviceAutoTimeAndTimeZone704 *705 * @param autoSwitch boolean. If true - auto Time and TimeZone will be set as On.706 */707 public void switchDeviceAutoTimeAndTimeZone(boolean autoSwitch) {708 String value = "0";709 if (autoSwitch) {710 value = "1";711 }712 executeAbdCommand("shell settings put global auto_time " + value);713 executeAbdCommand("shell settings put global auto_time_zone " + value);714 }715 /**716 * get Device Time Zone717 *718 * @return DeviceTimeZone719 */720 public DeviceTimeZone getDeviceTimeZone() {721 return getDeviceTimeZone("");722 }723 /**724 * get Device Time Zone. Set default TimeZone725 *726 * @param defaultTZ - default string.727 * @return DeviceTimeZone728 */729 public DeviceTimeZone getDeviceTimeZone(String defaultTZ) {730 getDriver(); //start driver in before class to assign it for particular thread731 DeviceTimeZone dt = new DeviceTimeZone();732 String value = executeAbdCommand("shell settings get global auto_time");733 if (value.contains("0")) {734 dt.setAutoTime(false);735 } else {736 dt.setAutoTime(true);737 }738 value = executeAbdCommand("shell settings get global auto_time_zone");739 if (value.contains("0")) {740 dt.setAutoTimezone(false);741 } else {742 dt.setAutoTimezone(true);743 }744 value = executeAbdCommand("shell settings get system time_12_24");745 if (value.contains("12")) {746 dt.setTimeFormat(TimeFormat.FORMAT_12);747 } else {748 dt.setTimeFormat(TimeFormat.FORMAT_24);749 }750 if (defaultTZ.isEmpty()) {751 value = executeAbdCommand("shell getprop persist.sys.timezone");752 if (!value.isEmpty()) {753 dt.setTimezone(value);754 }755 } else {756 dt.setTimezone(defaultTZ);757 }758 value = executeAbdCommand("shell date -s %mynow%");759 LOGGER.info(value);760 if (!value.isEmpty()) {761 value = convertDateInCorrectString(parseOutputDate(value));762 dt.setSetDeviceDateTime(value);763 LOGGER.info(value);764 }765 dt.setChangeDateTime(false);766 dt.setRefreshDeviceTime(true);767 LOGGER.info(dt.toString());768 return dt;769 }770 /**771 * get Device Actual TimeZone772 *773 * @return String774 */775 public String getDeviceActualTimeZone() {776 String value = executeAbdCommand("shell getprop persist.sys.timezone");777 if (!value.isEmpty()) {778 LOGGER.info(value);779 }780 return value;781 }782 //Start of TimeZone Setting section783 /**784 * set Device TimeZone by using Apk785 *786 * @param timeZone String required timeZone in Android standard format (Europe/London)787 * @param timeFormat String 12 or 24788 * @return boolean789 */790 public boolean setDeviceTimeZone(String timeZone, TimeFormat timeFormat) {791 return setDeviceTimeZone(timeZone, "", timeFormat, ChangeTimeZoneWorkflow.APK);792 }793 /**794 * set Device TimeZone using all supported workflows. By ADB, Settings and Apk795 *796 * @param timeZone String required timeZone797 * @param timeFormat String 12 or 24798 * @param settingsTZ TimeFormat799 * @return boolean800 */801 public boolean setDeviceTimeZone(String timeZone, String settingsTZ, TimeFormat timeFormat) {802 return setDeviceTimeZone(timeZone, settingsTZ, timeFormat, ChangeTimeZoneWorkflow.ALL);803 }804 /**805 * set Device TimeZone. By required workflow: ADB, Settings or APK806 *807 * @param timeZone String required timeZone808 * @param timeFormat String 12 or 24809 * @param settingsTZ TimeFormat810 * @param workflow ChangeTimeZoneWorkflow811 * @return boolean812 */813 public boolean setDeviceTimeZone(String timeZone, String settingsTZ, TimeFormat timeFormat, ChangeTimeZoneWorkflow workflow) {814 boolean changed = false;815 getDriver(); //start driver in before class to assign it for particular thread816 String actualTZ = getDeviceActualTimeZone();817 if (isRequiredTimeZone(actualTZ, timeZone)) {818 LOGGER.info("Required TimeZone is already set.");819 return true;820 }821 String currentAndroidVersion = DevicePool.getDevice().getOsVersion();822 LOGGER.info("currentAndroidVersion=" + currentAndroidVersion);823 if (currentAndroidVersion.contains("7.") || (DevicePool.getDeviceType() == DeviceType.Type.ANDROID_TABLET)) {824 LOGGER.info("TimeZone changing for Android 7+ and tablets works only by TimeZone changer apk.");825 workflow = ChangeTimeZoneWorkflow.APK;826 }827 //Solution for ADB timezone changing.828 if (ChangeTimeZoneWorkflow.ADB.isSupported(workflow)) {829 LOGGER.info("Try to change TimeZone by ADB");830 LOGGER.info(setDeviceTimeZoneByADB(timeZone, timeFormat, ""));831 changed = applyTZChanges(ChangeTimeZoneWorkflow.ADB, timeZone);832 }833 // Solution for timezone changing by device Settings. (Tested on S7, Note 3, S6, S5).834 if (!changed && ChangeTimeZoneWorkflow.SETTINGS.isSupported(workflow)) {835 LOGGER.info("Try to change TimeZone by Device Settings");836 setDeviceTimeZoneBySetting(timeZone, settingsTZ, timeFormat);837 changed = applyTZChanges(ChangeTimeZoneWorkflow.SETTINGS, timeZone);838 }839 // Solution for using TimeZone Changer apk.840 if (!changed && ChangeTimeZoneWorkflow.APK.isSupported(workflow)) {841 LOGGER.info("Try to change TimeZone by TimeZone Changer apk.");842 setDeviceTimeZoneByChangerApk(timeZone, timeFormat);843 changed = applyTZChanges(ChangeTimeZoneWorkflow.APK, timeZone);844 }845 return changed;846 }847 //End of TimeZone change sections848 //Private section849 //TimeZone Private methods850 /**851 * setDeviceTimeZoneByADB852 *853 * @param timeZone String854 * @param timeFormat TimeFormat855 * @param deviceSetDate String in format yyyyMMdd.HHmmss. Can be empty.856 * @return String857 */858 private String setDeviceTimeZoneByADB(String timeZone, TimeFormat timeFormat, String deviceSetDate) {859 boolean changeDateTime = true;860 String tzGMT = "";861 if (deviceSetDate.isEmpty()) {862 changeDateTime = false;863 }864 DeviceTimeZone dt = new DeviceTimeZone(false, false, timeFormat, timeZone, tzGMT, deviceSetDate, changeDateTime, true);865 return setDeviceTimeZoneByADB(dt);866 }867 /**868 * setDeviceTimeZoneByADB869 * Automatic date and time = OFF (settings - date and time)870 * adb shell settings put global auto_time 0871 * Automatic time zone = OFF (settings - date and time)872 * adb shell settings put global auto_time_zone 0873 * <p>874 * Set Time Zone on device875 * adb shell setprop persist.sys.timezone "America/Chicago"876 * <p>877 * Check timezones:878 * <a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones">List_of_tz_database_time_zones</a>879 * <p>880 * Check time on device881 * adb shell date -s %mynow%882 * <p>883 * Restart application884 *885 * @param dt DeviceTimeZone886 * @return String actual Device Date and Time887 */888 private String setDeviceTimeZoneByADB(DeviceTimeZone dt) {889 if (dt == null) {890 LOGGER.error("DeviceTimeZone is not initialised.");891 dt = new DeviceTimeZone();892 }893 LOGGER.info(dt.toString());894 String autoTime = "0";895 String autoTimeZone = "0";896 if (dt.isAutoTime()) {897 autoTime = "1";898 }899 executeAbdCommand("shell settings put global auto_time " + autoTime);900 if (dt.isAutoTimezone()) {901 autoTimeZone = "1";902 }903 executeAbdCommand("shell settings put global auto_time_zone " + autoTimeZone);904 setSystemTime(dt.getTimeFormat());905 if (!dt.getTimezone().isEmpty()) {906 executeAbdCommand("shell setprop persist.sys.timezone \"" + dt.getTimezone() + "\"");907 }908 if (dt.isRefreshDeviceTime()) {909 executeAbdCommand("shell am broadcast -a android.intent.action.TIME_SET");910 }911 if (dt.isChangeDateTime() && !dt.getSetDeviceDateTime().isEmpty()) {912 // Try to set date for device but it will not work on not rooted913 // devices914 executeAbdCommand("shell date " + dt.getSetDeviceDateTime());915 }916 String actualDT = executeAbdCommand("shell date -s %mynow%");917 LOGGER.info(actualDT);918 return actualDT;919 }920 /**921 * setDeviceTimeZoneBySetting922 *923 * @param timeZone String924 * @param settingsTZ String925 * @param timeFormat TimeFormat926 */927 private void setDeviceTimeZoneBySetting(String timeZone, String settingsTZ, TimeFormat timeFormat) {928 String actualTZ = getDeviceActualTimeZone();929 String tz = DeviceTimeZone.getTimezoneOffset(timeZone);930 if (isRequiredTimeZone(actualTZ, timeZone)) {931 LOGGER.info("Required timeZone is already set.");932 return;933 }934 try {935 openDateTimeSettingsSetupWizard(true, timeFormat);936 String res = getCurrentDeviceFocus();937 if (res.contains("settings.DateTimeSettingsSetupWizard")) {938 LOGGER.info("On settings.DateTimeSettingsSetupWizard page");939 } else {940 LOGGER.error("Not on settings.DateTimeSettingsSetupWizard page");941 }942 DateTimeSettingsPage dtSettingsPage = new DateTimeSettingsPage(getDriver());943 if (!dtSettingsPage.isOpened(3)) {944 openDateTimeSettingsSetupWizard(true, timeFormat);945 }946 if (dtSettingsPage.isOpened(3)) {947 LOGGER.info("Date Time Settings page was open.");948 } else {949 LOGGER.error("Date Time Settings page should be open.");950 }951 dtSettingsPage.openTimeZoneSetting();952 dtSettingsPage.selectTimeZone(tz, settingsTZ);953 dtSettingsPage.clickNextButton();954 } catch (Exception e) {955 LOGGER.error("Exception: ", e);956 }957 }958 /**959 * setDeviceTimeZoneByChangerApk960 *961 * @param timeZone String962 * @param timeFormat TimeFormat963 */964 private void setDeviceTimeZoneByChangerApk(String timeZone, TimeFormat timeFormat) {965 String actualTZ = getDeviceActualTimeZone();966 String tz = DeviceTimeZone.getTimezoneOffset(timeZone);967 LOGGER.info("Required TimeZone offset: " + tz);968 if (isRequiredTimeZone(actualTZ, timeZone)) {969 LOGGER.info("Required timeZone is already set.");970 return;971 }972 installApk(TZ_CHANGE_APP_PATH, true);973 try {974 forceTZChangingApkOpen(true, timeFormat);975 TZChangerPage tzChangerPage = new TZChangerPage(getDriver());976 if (tzChangerPage.isOpened(3)) {977 LOGGER.info("TimeZone changer main page was open.");978 } else {979 LOGGER.error("TimeZone changer main page should be open. Retry to open.");980 openTZChangingApk(true, timeFormat);981 }982 tzChangerPage.selectTimeZone(timeZone);983 } catch (Exception e) {984 LOGGER.error("Exception: ", e);985 }986 }987 private boolean applyTZChanges(ChangeTimeZoneWorkflow workflow, String expectedZone) {988 boolean res = false;989 String actualTZ = getDeviceActualTimeZone();990 if (isRequiredTimeZone(actualTZ, expectedZone)) {991 LOGGER.info("Required timeZone '" + expectedZone + "' was set by " + workflow.toString() + ". Restarting driver to apply changes.");992 DriverPool.restartDriver(true);993 res = true;994 } else {995 LOGGER.error("TimeZone was not changed by " + workflow.toString() + ". Actual TZ is: " + actualTZ);996 }997 return res;998 }999 /**1000 * comparingExpectedAndActualTZ1001 *1002 * @param actualTZ String1003 * @param expextedTZ String1004 * @return boolean1005 */1006 private boolean isRequiredTimeZone(String actualTZ, String expextedTZ) {1007 boolean res = actualTZ.equals(expextedTZ);1008 if (!res) {1009 String[] actTZ = actualTZ.split("/");1010 String lastActTZ = actTZ[actTZ.length - 1];1011 String[] timeZoneTZ = expextedTZ.split("/");1012 String lastTimeZoneTZ = timeZoneTZ[timeZoneTZ.length - 1];1013 LOGGER.debug("Comparing '" + lastActTZ + "' with '" + lastTimeZoneTZ + "'.");1014 res = lastActTZ.equals(lastTimeZoneTZ);1015 }1016 return res;1017 }1018 /**1019 * @param turnOffAuto boolean1020 * @param timeFormat TimeFormat1021 * @return boolean1022 */1023 private boolean forceTZChangingApkOpen(boolean turnOffAuto, TimeFormat timeFormat) {1024 boolean res = false;1025 String tzPackageName = TZ_CHANGE_APP_PACKAGE;1026 int attemps = 3;1027 boolean isTzOpened = checkCurrentDeviceFocus(tzPackageName);1028 while (!isTzOpened && attemps > 0) {1029 LOGGER.info("TimeZoneChanger apk was not open. Attempt to open...");1030 openTZChangingApk(turnOffAuto, timeFormat);1031 isTzOpened = checkCurrentDeviceFocus(tzPackageName);1032 attemps--;1033 }1034 if (!isTzOpened) {1035 LOGGER.info("Probably TimeZone Changer APK was not installed correctly. Try to reinstall.");1036 installApk(TZ_CHANGE_APP_PATH, true);1037 openTZChangingApk(turnOffAuto, timeFormat);1038 }1039 TZChangerPage tzChangerPage = new TZChangerPage(getDriver());1040 if (!tzChangerPage.isOpened(10)) {1041 openTZChangingApk(turnOffAuto, timeFormat);1042 }1043 if (tzChangerPage.isOpened(3)) {1044 LOGGER.info("TimeZone changer main page was open.");1045 res = true;1046 } else {1047 LOGGER.error("TimeZone changer main page should be open.");1048 openTZChangingApk(turnOffAuto, timeFormat);1049 res = false;1050 }1051 if (checkCurrentDeviceFocus(tzPackageName)) {1052 LOGGER.info("On TZ changer apk page");1053 res = true;1054 } else {1055 LOGGER.error("Not on com.futurek.android.tzc page after all tries. Please check logs.");1056 res = false;1057 }1058 return res;1059 }1060 /**1061 * openDateTimeSettingsSetupWizard in settings1062 *1063 * @param turnOffAuto - turn off AutoTimeZone and AutoTime1064 * @param timeFormat - can be 12 or 24. Or empty.1065 */1066 private void openDateTimeSettingsSetupWizard(boolean turnOffAuto, TimeFormat timeFormat) {1067 if (turnOffAuto) {1068 switchDeviceAutoTimeAndTimeZone(false);1069 }1070 setSystemTime(timeFormat);1071 openApp("com.android.settings/.DateTimeSettingsSetupWizard");1072 }1073 /**1074 * openDateTimeSettingsSetupWizard in settings1075 *1076 * @param turnOffAuto - turn off AutoTimeZone and AutoTime1077 * @param timeFormat - can be 12 or 24. Or empty.1078 */1079 private void openTZChangingApk(boolean turnOffAuto, TimeFormat timeFormat) {1080 if (turnOffAuto) {1081 switchDeviceAutoTimeAndTimeZone(false);1082 }1083 setSystemTime(timeFormat);1084 openApp(TZ_CHANGE_APP_ACTIVITY);1085 pause(2);1086 }1087 private void setSystemTime(TimeFormat timeFormat) {1088 switch (timeFormat) {1089 case FORMAT_12:1090 LOGGER.info("Set 12 hours format");1091 executeAbdCommand("shell settings put system time_12_24 12");1092 break;1093 case FORMAT_24:1094 LOGGER.info("Set 24 hours format");1095 executeAbdCommand("shell settings put system time_12_24 24");1096 break;1097 }1098 }1099 /**1100 * Parse DateTime which came in format 'EE MMM dd hh:mm:ss zz yyyy'1101 *1102 * @param inputDate String1103 * @return Date1104 */1105 private Date parseOutputDate(String inputDate) {1106 Date result = new Date();1107 try {1108 LOGGER.info("Input date: " + inputDate);1109 SimpleDateFormat inDateFormat = new SimpleDateFormat("EE MMM dd hh:mm:ss zz yyyy");1110 result = inDateFormat.parse(inputDate);1111 LOGGER.info("Output date: " + result);1112 } catch (Exception e) {1113 LOGGER.error(e);1114 }1115 return result;1116 }1117 /**1118 * convertDateInCorrectString1119 *1120 * @param inputDate String1121 * @return String1122 */1123 private String convertDateInCorrectString(Date inputDate) {1124 String res = "";1125 try {1126 SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyyMMdd.HHmmss");1127 res = outputDateFormat.format(inputDate);1128 } catch (Exception e) {1129 LOGGER.error(e);1130 }1131 LOGGER.info("Output date in expected format: " + res);1132 return res;1133 }1134 //End of TimeZone private section1135 /**1136 * Pause1137 *1138 * @param timeout long1139 */1140 private void pause(long timeout) {1141 try {1142 Thread.sleep(timeout * 1000);1143 } catch (InterruptedException e) {1144 e.printStackTrace();1145 }...

Full Screen

Full Screen

Source:MobileUtils.java Github

copy

Full Screen

...455 break;456 default:457 throw new RuntimeException("Unsupported direction: " + direction);458 }459 LOGGER.debug(String.format("Swipe from (X = %d; Y = %d) to (X = %d; Y = %d)", startx, starty, endx, endy));460 try {461 for (int i = 0; i < count; ++i) {462 swipe(startx, starty, endx, endy, duration);463 }464 return true;465 } catch (Exception e) {466 LOGGER.error(String.format("Error during Swipe from (X = %d; Y = %d) to (X = %d; Y = %d): %s", startx, starty, endx, endy, e));467 }468 return false;469 }470 /**471 * Swipe up several times472 * 473 * @param times int474 * @param duration int475 */476 public static void swipeUp(final int times, final int duration) {477 for (int i = 0; i < times; i++) {478 swipeUp(duration);479 }480 }481 /**482 * Swipe up483 * 484 * @param duration int485 */486 public static void swipeUp(final int duration) {487 LOGGER.info("Swipe up will be executed.");488 swipeInContainer(null, Direction.UP, duration);489 }490 /**491 * Swipe down several times492 * 493 * @param times int494 * @param duration int495 */496 public static void swipeDown(final int times, final int duration) {497 for (int i = 0; i < times; i++) {498 swipeDown(duration);499 }500 }501 /**502 * Swipe down503 * 504 * @param duration int505 */506 public static void swipeDown(final int duration) {507 LOGGER.info("Swipe down will be executed.");508 swipeInContainer(null, Direction.DOWN, duration);509 }510 /**511 * Swipe left several times512 * 513 * @param times int514 * @param duration int515 */516 public static void swipeLeft(final int times, final int duration) {517 for (int i = 0; i < times; i++) {518 swipeLeft(duration);519 }520 }521 /**522 * Swipe left523 * 524 * @param duration int525 */526 public static void swipeLeft(final int duration) {527 LOGGER.info("Swipe left will be executed.");528 swipeLeft(null, duration);529 }530 /**531 * Swipe left in container532 * 533 * @param container534 * ExtendedWebElement535 * @param duration536 * int537 */538 public static void swipeLeft(ExtendedWebElement container, final int duration) {539 LOGGER.info("Swipe left will be executed.");540 swipeInContainer(container, Direction.LEFT, duration);541 }542 /**543 * Swipe right several times544 * 545 * @param times int546 * @param duration int547 */548 public static void swipeRight(final int times, final int duration) {549 for (int i = 0; i < times; i++) {550 swipeRight(duration);551 }552 }553 /**554 * Swipe right555 * 556 * @param duration int557 */558 public static void swipeRight(final int duration) {559 LOGGER.info("Swipe right will be executed.");560 swipeRight(null, duration);561 }562 /**563 * Swipe right in container564 * 565 * @param container566 * ExtendedWebElement567 * @param duration568 * int569 */570 public static void swipeRight(ExtendedWebElement container, final int duration) {571 LOGGER.info("Swipe right will be executed.");572 swipeInContainer(container, Direction.RIGHT, duration);573 }574 /**575 * Set Android Device Default TimeZone And Language based on config or to GMT and En576 * Without restoring actual focused apk.577 */578 public static void setDeviceDefaultTimeZoneAndLanguage() {579 setDeviceDefaultTimeZoneAndLanguage(false);580 }581 /**582 * set Android Device Default TimeZone And Language based on config or to GMT and En583 * 584 * @param returnAppFocus - if true store actual Focused apk and activity, than restore after setting Timezone and Language.585 */586 public static void setDeviceDefaultTimeZoneAndLanguage(boolean returnAppFocus) {587 try {588 String baseApp = "";589 String os = DevicePool.getDevice().getOs();590 if (os.equalsIgnoreCase(SpecialKeywords.ANDROID)) {591 AndroidService androidService = AndroidService.getInstance();592 if (returnAppFocus) {593 baseApp = androidService.getCurrentFocusedApkDetails();594 }595 String deviceTimezone = Configuration.get(Parameter.DEFAULT_DEVICE_TIMEZONE);596 String deviceTimeFormat = Configuration.get(Parameter.DEFAULT_DEVICE_TIME_FORMAT);597 String deviceLanguage = Configuration.get(Parameter.DEFAULT_DEVICE_LANGUAGE);598 DeviceTimeZone.TimeFormat timeFormat = DeviceTimeZone.TimeFormat.parse(deviceTimeFormat);599 DeviceTimeZone.TimeZoneFormat timeZone = DeviceTimeZone.TimeZoneFormat.parse(deviceTimezone);600 LOGGER.info("Set device timezone to " + timeZone.toString());601 LOGGER.info("Set device time format to " + timeFormat.toString());602 LOGGER.info("Set device language to " + deviceLanguage);603 boolean timeZoneChanged = androidService.setDeviceTimeZone(timeZone.getTimeZone(), timeZone.getSettingsTZ(), timeFormat);604 boolean languageChanged = androidService.setDeviceLanguage(deviceLanguage);605 LOGGER.info(String.format("Device TimeZone was changed to timeZone '%s' : %s. Device Language was changed to language '%s': %s",606 deviceTimezone,607 timeZoneChanged, deviceLanguage, languageChanged));608 if (returnAppFocus) {609 androidService.openApp(baseApp);610 }611 } else {612 LOGGER.info(String.format("Current OS is %s. But we can set default TimeZone and Language only for Android.", os));613 }614 } catch (Exception e) {615 LOGGER.error(e);616 }617 }618 /**619 * Hide keyboard if needed620 */621 public static void hideKeyboard() {622 try {623 ((MobileDriver<?>) getDriver()).hideKeyboard();624 } catch (Exception e) {625 if (!e.getMessage().contains("Soft keyboard not present, cannot hide keyboard")) {626 LOGGER.error("Exception appears during hideKeyboard: " + e);...

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1DeviceTimeZone.getTimeZone();2DeviceTimeZone.getTimeZone();3DeviceTimeZone.getTimeZone();4DeviceTimeZone.getTimeZone();5DeviceTimeZone.getTimeZone();6DeviceTimeZone.getTimeZone();7DeviceTimeZone.getTimeZone();8DeviceTimeZone.getTimeZone();9DeviceTimeZone.getTimeZone();10DeviceTimeZone.getTimeZone();11DeviceTimeZone.getTimeZone();12DeviceTimeZone.getTimeZone();13DeviceTimeZone.getTimeZone();14DeviceTimeZone.getTimeZone();15DeviceTimeZone.getTimeZone();

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;2import java.text.SimpleDateFormat;3import java.util.Date;4import java.util.TimeZone;5import java.util.Calendar;6import java.util.GregorianCalendar;7import java.util.Locale;8public class 1 {9 public static void main(String[] args) {10 String timeZone = DeviceTimeZone.getDeviceTimeZone();11 System.out.println("Device TimeZone: " + timeZone);12 System.out.println("Device TimeZone: " + timeZone);13 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");14 sdf.setTimeZone(TimeZone.getTimeZone(timeZone));15 Calendar calendar = new GregorianCalendar();16 calendar.setTimeZone(TimeZone.getTimeZone(timeZone));17 System.out.println("Current Date Time: " + sdf.format(calendar.getTime()));18 String format = "yyyy/MM/dd HH:mm:ss";19 String date = sdf.format(calendar.getTime());20 System.out.println("format: " + format);21 System.out.println("date: " + date);22 System.out.println("date: " + date);23 System.out.println("date: " + date);24 SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ENGLISH);25 formatter.setTimeZone(TimeZone.getTimeZone(timeZone));26 Date dateObj = formatter.parse(date);27 System.out.println("dateObj: " + dateObj);28 }29}30import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;31import java.text.SimpleDateFormat;32import java.util.Date;33import java.util.TimeZone;34import java.util.Calendar;35import java.util.GregorianCalendar;36import java.util.Locale;37public class 2 {38 public static void main(String[] args) {39 String timeZone = DeviceTimeZone.getDeviceTimeZone();40 System.out.println("Device TimeZone: " + timeZone);41 System.out.println("Device TimeZone: " + timeZone);42 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");43 sdf.setTimeZone(TimeZone.getTimeZone(timeZone));44 Calendar calendar = new GregorianCalendar();45 calendar.setTimeZone(TimeZone.getTimeZone(timeZone));46 System.out.println("Current Date Time: " + sdf.format(calendar.getTime()));47 String format = "yyyy/MM/dd HH:mm:ss";48 String date = sdf.format(calendar.getTime());49 System.out.println("format: " + format);50 System.out.println("date: " + date);

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");2DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");3DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");4DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");5DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");6DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");7DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");8DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");9DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");10DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");11DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");12DeviceTimeZone.getTimeZone().format("MM/dd/yyyy HH:mm:ss");

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;2String timeZone = DeviceTimeZone.format("America/New_York");3System.out.println(timeZone);4import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;5String timeZone = DeviceTimeZone.get();6System.out.println(timeZone);7import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;8String timeZone = DeviceTimeZone.get();9System.out.println(timeZone);10import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;11String timeZone = DeviceTimeZone.get();12System.out.println(timeZone);13import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;14String timeZone = DeviceTimeZone.get();15System.out.println(timeZone);16import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;17String timeZone = DeviceTimeZone.get();18System.out.println(timeZone);19import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;20String timeZone = DeviceTimeZone.get();21System.out.println(timeZone);22import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;23String timeZone = DeviceTimeZone.get();24System.out.println(timeZone);25import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;26String timeZone = DeviceTimeZone.get();27System.out.println(timeZone);28import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;29String timeZone = DeviceTimeZone.get();30System.out.println(timeZone);31import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;2public class 1 {3public static void main(String[] args) {4DeviceTimeZone deviceTimeZone = new DeviceTimeZone();5System.out.println(deviceTimeZone.getTimeZone());6}7}8import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;9public class 2 {10public static void main(String[] args) {11DeviceTimeZone deviceTimeZone = new DeviceTimeZone();12System.out.println(deviceTimeZone.getTimeZone());13}14}15import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;16public class 3 {17public static void main(String[] args) {18DeviceTimeZone deviceTimeZone = new DeviceTimeZone();19System.out.println(deviceTimeZone.getTimeZone());20}21}22import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;23public class 4 {24public static void main(String[] args) {25DeviceTimeZone deviceTimeZone = new DeviceTimeZone();26System.out.println(deviceTimeZone.getTimeZone());27}28}29import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;30public class 5 {31public static void main(String[] args) {32DeviceTimeZone deviceTimeZone = new DeviceTimeZone();33System.out.println(deviceTimeZone.getTimeZone());34}35}36import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;37public class 6 {38public static void main(String[] args) {39DeviceTimeZone deviceTimeZone = new DeviceTimeZone();40System.out.println(deviceTimeZone.getTimeZone());41}42}

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");2String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");3String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");4String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");5String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");6String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");7String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");8String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");9String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");10String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT-05:00");11String time = DeviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1DeviceTimeZone deviceTimeZone = new DeviceTimeZone();2String result = deviceTimeZone.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "America/New_York", "Europe/Paris", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "Europe/Paris");3System.out.println(result);4DeviceTimeZone deviceTimeZone = new DeviceTimeZone();5String result = deviceTimeZone.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "America/New_York", "Europe/Paris", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "Europe/Paris");6System.out.println(result);7DeviceTimeZone deviceTimeZone = new DeviceTimeZone();8long result = deviceTimeZone.getOffset("Europe/Paris", "America/New_York");9System.out.println(result);10DeviceTimeZone deviceTimeZone = new DeviceTimeZone();11long result = deviceTimeZone.getOffset("Europe/Paris", "America/New_York");12System.out.println(result);13DeviceTimeZone deviceTimeZone = new DeviceTimeZone();14long result = deviceTimeZone.getOffset("Europe/Paris", "America/New_York", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");15System.out.println(result);16DeviceTimeZone deviceTimeZone = new DeviceTimeZone();17long result = deviceTimeZone.getOffset("Europe/Paris", "America/New_York", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");18System.out.println(result);19DeviceTimeZone deviceTimeZone = new DeviceTimeZone();20long result = deviceTimeZone.getOffset("Europe/Paris", "America/New_York", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;2import java.text.ParseException;3import java.text.SimpleDateFormat;4import java.util.Date;5import java.util.TimeZone;6public class 1 {7public static void main(String[] args) throws ParseException {8String timeZone = DeviceTimeZone.format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");9System.out.println(timeZone);10String format = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";11SimpleDateFormat sdf = new SimpleDateFormat(format);12sdf.setTimeZone(TimeZone.getTimeZone(timeZone));13String date = sdf.format(new Date());14System.out.println(date);15}16}

Full Screen

Full Screen

format

Using AI Code Generation

copy

Full Screen

1DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);2String deviceTimeZone1 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");3System.out.println("deviceTimeZone1: "+deviceTimeZone1);4DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);5String deviceTimeZone2 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");6System.out.println("deviceTimeZone2: "+deviceTimeZone2);7DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);8String deviceTimeZone3 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");9System.out.println("deviceTimeZone3: "+deviceTimeZone3);10DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);11String deviceTimeZone4 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");12System.out.println("deviceTimeZone4: "+deviceTimeZone4);13DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);14String deviceTimeZone5 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");15System.out.println("deviceTimeZone5: "+deviceTimeZone5);16DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);17String deviceTimeZone6 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");18System.out.println("deviceTimeZone6: "+deviceTimeZone6);19DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);20String deviceTimeZone7 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+05:30");21System.out.println("deviceTimeZone7: "+deviceTimeZone7);22DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);23String deviceTimeZone8 = deviceTimeZone.format("yyyy-MM-dd HH:mm:ss", "GMT+

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