How to use parseOutputDate method of com.qaprosoft.carina.core.foundation.utils.android.AndroidService class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.android.AndroidService.parseOutputDate

Source:AndroidService.java Github

copy

Full Screen

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

Full Screen

Full Screen

parseOutputDate

Using AI Code Generation

copy

Full Screen

1DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");2LocalDateTime dateTime = LocalDateTime.parse("2021-04-15T05:30:00.000Z", formatter);3String formattedString = AndroidService.parseOutputDate(dateTime);4System.out.println(formattedString);5DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");6LocalDateTime dateTime = LocalDateTime.parse("2021-04-15T05:30:00.000Z", formatter);7String formattedString = AndroidService.parseOutputDate(dateTime, "dd/MM/yyyy");8System.out.println(formattedString);9DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");10LocalDateTime dateTime = LocalDateTime.parse("2021-04-15T05:30:00.000Z", formatter);11String formattedString = AndroidService.parseOutputDate(dateTime, "dd/MM/yyyy", "America/Los_Angeles");12System.out.println(formattedString);13DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");14LocalDateTime dateTime = LocalDateTime.parse("2021-04-15T05:30:00.000Z", formatter);15String formattedString = AndroidService.parseOutputDate(dateTime, "dd/MM/yyyy", "America/Los_Angeles", "en");16System.out.println(formattedString);17DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");18LocalDateTime dateTime = LocalDateTime.parse("2021-04-15T05:30:00.000Z", formatter);19String formattedString = AndroidService.parseOutputDate(dateTime, "dd/MM/yyyy", "America/Los_Angeles

Full Screen

Full Screen

parseOutputDate

Using AI Code Generation

copy

Full Screen

1String date = AndroidService.parseOutputDate("2017-03-20 14:03:00", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss");2String date = AndroidService.parseOutputDate("2017-03-20 14:03:00", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss");3String date = AndroidService.parseOutputDate("2017-03-20 14:03:00", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss");4String date = AndroidService.parseOutputDate("2017-03-20 14:03:00", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss");5String date = AndroidService.parseOutputDate("2017-03-20 14:03:00", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss");6String date = AndroidService.parseOutputDate("2017-03-20 14:03:00", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss");7String date = AndroidService.parseOutputDate("2017-03-20 14:

Full Screen

Full Screen

parseOutputDate

Using AI Code Generation

copy

Full Screen

1String date = "2019-01-21T12:00:00+08:00";2String outputDate = AndroidService.parseOutputDate(date);3System.out.println(outputDate);4String date = "2019-01-21 12:00:00";5String inputDate = AndroidService.parseInputDate(date);6System.out.println(inputDate);7String date = "2019-01-21T12:00:00+08:00";8String outputDate = AndroidService.parseOutputDate(date);9System.out.println(outputDate);10String date = "2019-01-21 12:00:00";11String inputDate = AndroidService.parseInputDate(date);12System.out.println(inputDate);

Full Screen

Full Screen

parseOutputDate

Using AI Code Generation

copy

Full Screen

1String date = "Wed Jul 1 23:32:15 GMT+03:00 2020";2String parsedDate = AndroidService.parseOutputDate(date);3Assert.assertEquals(parsedDate, "2020-07-01 23:32:15");4String date = "Wed Jul 1 23:32:15 GMT+03:00 2020";5String parsedDate = AndroidService.parseOutputDate(date, "dd.MM.yyyy");6Assert.assertEquals(parsedDate, "01.07.2020");7String date = "Wed Jul 1 23:32:15 GMT+03:00 2020";8String parsedDate = AndroidService.parseOutputDate(date, "dd.MM.yyyy", "GMT+03:00");9Assert.assertEquals(parsedDate, "01.07.2020");10String date = "Wed Jul 1 23:32:15 GMT+03:00 2020";11String parsedDate = AndroidService.parseOutputDate(date, "dd.MM.yyyy", "GMT+03:00", "GMT+00:00");12Assert.assertEquals(parsedDate, "01.07.2020");

Full Screen

Full Screen

parseOutputDate

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.utils.android;2import java.util.Date;3import org.testng.Assert;4import org.testng.annotations.Test;5public class AndroidServiceTest {6 public void testParseOutputDate() {7 String date = "2018-06-07 17:16:34";8 Date parsedDate = AndroidService.parseOutputDate(date);9 Assert.assertEquals(parsedDate.toString(), "Thu Jun 07 17:16:34 EEST 2018");10 }11}

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