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

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

Source:AndroidService.java Github

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.utils.android;2import com.qaprosoft.carina.core.foundation.report.ReportContext;3import com.qaprosoft.carina.core.foundation.utils.R;4import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone.TimeFormat;5import com.qaprosoft.carina.core.foundation.utils.android.recorder.utils.AdbExecutor;6import com.qaprosoft.carina.core.foundation.utils.android.recorder.utils.CmdLine;7import com.qaprosoft.carina.core.foundation.utils.factory.DeviceType;8import com.qaprosoft.carina.core.foundation.utils.mobile.notifications.android.Notification;9import com.qaprosoft.carina.core.foundation.webdriver.DriverPool;10import com.qaprosoft.carina.core.foundation.webdriver.Screenshot;11import com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool;12import com.qaprosoft.carina.core.gui.mobile.devices.android.phone.pages.fakegps.FakeGpsPage;13import com.qaprosoft.carina.core.gui.mobile.devices.android.phone.pages.notifications.NotificationPage;14import com.qaprosoft.carina.core.gui.mobile.devices.android.phone.pages.settings.DateTimeSettingsPage;15import com.qaprosoft.carina.core.gui.mobile.devices.android.phone.pages.tzchanger.TZChangerPage;16import io.appium.java_client.android.AndroidDriver;17import org.apache.commons.io.FilenameUtils;18import org.apache.log4j.Logger;19import java.io.File;20import java.io.IOException;21import java.io.InputStream;22import java.net.URL;23import java.nio.file.Files;24import java.text.SimpleDateFormat;25import java.util.ArrayList;26import java.util.Date;27import java.util.List;28import java.util.regex.Matcher;29import java.util.regex.Pattern;30import static com.qaprosoft.carina.core.foundation.webdriver.DriverPool.getDriver;31public class AndroidService {32 private static final Logger LOGGER = Logger.getLogger(AndroidService.class);33 protected static final int INIT_TIMEOUT = 20;34 private final Pattern NOTIFICATION_PATTERN = Pattern.compile(".* NotificationRecord.*pkg=(.*) user");35 private final Pattern NOTIFICATION_TEXT_PATTERN = Pattern.compile(".*tickerText=(.*)");36 private final String TZ_CHANGE_APP_PATH = "app/TimeZone_Changer.apk";37 private final String TZ_CHANGE_APP_ACTIVITY = "com.futurek.android.tzc/com.futurek.android.tzc.MainActivity";38 private final String TZ_CHANGE_APP_PACKAGE = "com.futurek.android.tzc";39 private final String LANGUAGE_CHANGE_APP_PATH = "app/ADB_Change_Language.apk";40 private final String FAKE_GPS_APP_PATH = "app/FakeGPSLocation.apk";41 private final String FAKE_GPS_APP_ACTIVITY = "com.lexa.fakegps/com.lexa.fakegps.ui.Main";42 private final String FAKE_GPS_APP_PACKAGE = "com.lexa.fakegps";43 private String[] baseInitCmd;44 private AdbExecutor executor;45 public enum ChangeTimeZoneWorkflow {46 ADB(1), // 0b00147 SETTINGS(2), // 0b01048 APK(4), // 0b10049 ALL(7); // 0b11150 private int workflow;51 ChangeTimeZoneWorkflow(int workflow) {52 this.workflow = workflow;53 }54 public int getWorkflow() {55 return workflow;56 }57 public boolean isSupported(ChangeTimeZoneWorkflow workflow) {58 return (this.workflow & workflow.getWorkflow()) > 0;59 }60 }61 private static AndroidService instance;62 private AndroidService() {63 executor = new AdbExecutor();64 baseInitCmd = executor.getDefaultCmd();65 }66 static {67 try {68 instance = new AndroidService();69 } catch (Exception e) {70 throw new RuntimeException("Exception occurred in creating singleton AndroidService!");71 }72 }73 public static AndroidService getInstance() {74 return instance;75 }76 // Common methods77 /**78 * executeAbdCommand79 *80 * @param command String81 * @return String command output in one line82 */83 public String executeAbdCommand(String command) {84 String udid = DevicePool.getDeviceUdid();85 if (!udid.isEmpty()) {86 // add udid reference87 command = "-s " + udid + " " + command;88 }89 String result = "";90 LOGGER.info("Command: " + command);91 String[] listOfCommands = command.split(" ");92 String[] execCmd = CmdLine.insertCommandsAfter(baseInitCmd, listOfCommands);93 try {94 LOGGER.info("Try to execute following cmd: " + CmdLine.arrayToString(execCmd));95 List<String> execOutput = executor.execute(execCmd);96 LOGGER.info("Output after execution ADB command: " + execOutput);97 result = execOutput.toString().replaceAll("\\[|\\]", "").replaceAll(", ", " ").trim();98 LOGGER.info("Returning Output: " + result);99 } catch (Exception e) {100 LOGGER.error(e);101 }102 return result;103 }104 /**105 * openApp106 *107 * @param pkg String108 * @param activity String109 */110 public void openApp(String pkg, String activity) {111 openApp(pkg.trim() + "/" + activity.trim());112 }113 /**114 * openApp115 *116 * @param app String117 */118 public void openApp(String app) {119 executeAbdCommand("shell am start -n " + app);120 }121 /**122 * clear Apk Cache123 *124 * @param appPackageName for example: com.bamnetworks.mobile.android.gameday.atbat125 * @return boolean126 */127 public boolean clearApkCache(String appPackageName) {128 //Later can be used:129 /*130 String packageName = executor.getApkPackageName(String apkFile);131 executor.clearAppData(Device device, String appPackage);132 */133 String result = executeAbdCommand("shell pm clear " + appPackageName);134 if (result.contains("Success")) {135 LOGGER.info("Cache was cleared correctly");136 return true;137 } else {138 LOGGER.error("Cache was not cleared. May be application does not exist on this device.");139 return false;140 }141 }142 /**143 * checkCurrentDeviceFocus - return actual device focused apk and compare with expected.144 *145 * @param apk String146 * @return boolean147 */148 public boolean checkCurrentDeviceFocus(String apk) {149 String res = getCurrentDeviceFocus();150 if (res.contains(apk)) {151 LOGGER.info("Actual device focus is as expected and contains package or activity: '" + apk + "'.");152 return true;153 } else {154 LOGGER.error("Not expected apk '" + apk + "' is in focus. Actual result is: " + res);155 return false;156 }157 }158 /**159 * getCurrentDeviceFocus - get actual device apk in focus160 *161 * @return String162 */163 public String getCurrentDeviceFocus() {164 String result = executeAbdCommand("shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'");165 return result;166 }167 /**168 * install android Apk by path to apk file.169 *170 * @param apkPath String171 */172 public void installApk(final String apkPath) {173 installApk(apkPath, false);174 }175 /**176 * install android Apk by path to apk or by name in classpath.177 *178 * @param apkPath String179 * @param inClasspath boolean180 */181 public void installApk(final String apkPath, boolean inClasspath) {182 String filePath = apkPath;183 if (inClasspath) {184 URL baseResource = ClassLoader.getSystemResource(apkPath);185 if (baseResource == null) {186 throw new RuntimeException("Unable to get resource from classpath: " + apkPath);187 } else {188 LOGGER.debug("Resource was found: " + baseResource.getPath());189 }190 String fileName = FilenameUtils.getBaseName(baseResource.getPath()) + "."191 + FilenameUtils.getExtension(baseResource.getPath());192 // make temporary copy of resource in artifacts folder193 filePath = ReportContext.getArtifactsFolder().getAbsolutePath() + File.separator + fileName;194 File file = new File(filePath);195 if (!file.exists()) {196 InputStream link = (ClassLoader.getSystemResourceAsStream(apkPath));197 try {198 Files.copy(link, file.getAbsoluteFile().toPath());199 } catch (IOException e) {200 LOGGER.error("Unable to extract resource from ClassLoader!", e);201 }202 }203 }204 executeAbdCommand("install " + filePath);205 }206 /**207 * Open Development Settings on device208 */209 public void openDeveloperOptions() {210 executeAbdCommand("shell am start -n com.android.settings/.DevelopmentSettings");211 }212 // End of Common Methods213 //Notification section214 /**215 * expandStatusBar216 */217 public void expandStatusBar() {218 executeAbdCommand("shell service call statusbar 1");219 }220 /**221 * collapseStatusBar222 */223 public void collapseStatusBar() {224 executeAbdCommand("shell service call statusbar 2");225 }226 //TODO: move notifications methods into separate class if possible. Maybe declare notification service instance inside AndroidService 227 /**228 * getNotifications229 *230 * @return List of Notification231 */232 public List<Notification> getNotifications() {233 return getNotifications(true);234 }235 /**236 * getNotifications237 *238 * @param withLogger boolean239 * @return List of Notification240 */241 public List<Notification> getNotifications(boolean withLogger) {242 String[] getNotificationsCmd = null;243 String udid = DevicePool.getDeviceUdid();244 if (!udid.isEmpty()) {245 getNotificationsCmd = CmdLine.insertCommandsAfter(baseInitCmd, "-s", udid, "shell", "dumpsys",246 "notification");247 } else {248 getNotificationsCmd = CmdLine.insertCommandsAfter(baseInitCmd, "shell", "dumpsys", "notification");249 }250 LOGGER.info("getNotifications cmd was built: " + CmdLine.arrayToString(getNotificationsCmd));251 //TODO: migrate to executeAbdCommand later252 List<Notification> resultList = new ArrayList<Notification>();253 List<String> notificationsOutput = executor.execute(getNotificationsCmd);254 Notification notification = new Notification();255 for (String output : notificationsOutput) {256 boolean found = false;257 Matcher matcher = NOTIFICATION_PATTERN.matcher(output);258 while (matcher.find()) {259 notification.setNotificationPkg(matcher.group(1));260 if (withLogger)261 LOGGER.info(matcher.group(1));262 }263 Matcher matcher2 = NOTIFICATION_TEXT_PATTERN.matcher(output);264 while (matcher2.find()) {265 notification.setNotificationText(matcher2.group(1));266 if (withLogger)267 LOGGER.info(matcher2.group(1));268 found = true;269 }270 if (found) {271 resultList.add(notification);272 if (withLogger)273 LOGGER.info(notification);274 notification = new Notification();275 found = false;276 }277 }278 if (withLogger)279 LOGGER.info("Found: " + resultList.size() + " notifications.");280 return resultList;281 }282 /**283 * notificationsCount284 *285 * @return notificationsCount286 */287 public int notificationsCount() {288 List<Notification> resultList = getNotifications(false);289 LOGGER.info("Found: " + resultList.size() + " notifications.");290 return resultList.size();291 }292 /**293 * isNotificationWithTextExist294 *295 * @param text String296 * @return boolean297 */298 public boolean isNotificationWithTextExist(String text) {299 List<Notification> resultList = getNotifications(false);300 for (Notification notify : resultList) {301 if (notify.getNotificationText().contains(text)) {302 LOGGER.info("Found '" + text + "' in notification '" + notify.getNotificationText() + "'.");303 return true;304 }305 }306 return false;307 }308 /**309 * waitUntilNewNotificationAppear310 *311 * @param text String312 * @param timeout long313 * @return boolean314 */315 public boolean waitUntilNewNotificationAppear(String text, long timeout) {316 //boolean found = false;317 int base = notificationsCount();318 int time = 0;319 boolean foundText = isNotificationWithTextExist(text);320 int actual = notificationsCount();321 while (actual <= base && ++time < timeout && !foundText) {322 LOGGER.info("Wait for notification. Second: " + time + ". Actual number:" + actual);323 pause(1);324 actual = notificationsCount();325 foundText = isNotificationWithTextExist(text);326 }327 return (foundText);328 }329 /**330 * isNotificationPkgExist331 *332 * @param text package text333 * @return boolean334 */335 public boolean isNotificationPkgExist(String text) {336 List<Notification> resultList = getNotifications(false);337 for (Notification notify : resultList) {338 if (notify.getNotificationPkg().contains(text)) {339 LOGGER.info("Found '" + text + "' in notification packages '" + notify.getNotificationPkg() + "' with text '" + notify.getNotificationText() + "'.");340 return true;341 }342 }343 return false;344 }345 /**346 * waitUntilNewNotificationPackageAppear347 *348 * @param pkg String349 * @param timeout long350 * @return boolean351 */352 public boolean waitUntilNewNotificationPackageAppear(String pkg, long timeout) {353 //boolean found = false;354 int base = notificationsCount();355 int time = 0;356 boolean foundText = isNotificationPkgExist(pkg);357 int actual = notificationsCount();358 while (actual <= base && ++time < timeout && !foundText) {359 LOGGER.info("Wait for notification. Second: " + time + ". Actual number:" + actual);360 pause(1);361 actual = notificationsCount();362 foundText = isNotificationPkgExist(pkg);363 }364 return (foundText);365 }366 /**367 * find Expected Notification with partial text368 *369 * @param expectedTitle String370 * @param expectedText String371 * @return boolean372 */373 public boolean findExpectedNotification(String expectedTitle, String expectedText) {374 return findExpectedNotification(expectedTitle, expectedText, true);375 }376 /**377 * find Expected Notification378 *379 * @param expectedTitle String380 * @param expectedText String381 * @param partially boolean382 * @return boolean383 */384 @SuppressWarnings("rawtypes")385 public boolean findExpectedNotification(String expectedTitle, String expectedText, boolean partially) {386 //open notification387 try {388 ((AndroidDriver) getDriver()).openNotifications();389 pause(2); //wait while notifications are playing animation to appear to avoid missed taps390 } catch (Exception e) {391 LOGGER.error(e);392 LOGGER.info("Using adb to expand Status bar. ");393 expandStatusBar();394 }395 NotificationPage nativeNotificationPage = new NotificationPage(getDriver());396 LOGGER.info("Native notification page is loaded: " + nativeNotificationPage.isNativeNotificationPage());397 int itemsListSize = nativeNotificationPage.getLastItemsContentSize();398 String title, text;399 int notificationItemNum = 0;400 for (int i = 0; i <= itemsListSize; i++) {401 title = nativeNotificationPage.getItemTitle(i);402 text = nativeNotificationPage.getItemText(i);403 LOGGER.info("Notification title is: " + title);404 LOGGER.info("Notification text is: " + text);405 if (!expectedTitle.isEmpty()) {406 if (title.equals(expectedTitle)) {407 notificationItemNum = i;408 LOGGER.info("Found expected title '" + expectedTitle + "' in notification #" + notificationItemNum);409 return true;410 } else if (partially) {411 if (expectedTitle.contains(title)) {412 notificationItemNum = i;413 LOGGER.info("Found that expected title '" + expectedTitle + "' contains '" + title + "' in notification #" + notificationItemNum);414 return true;415 }416 }417 }418 if (!expectedText.isEmpty()) {419 if (text.equals(expectedText)) {420 notificationItemNum = i;421 LOGGER.info("Found expected text '" + expectedText + "' in notification #" + notificationItemNum);422 return true;423 } else if (partially) {424 if (expectedText.contains(text)) {425 notificationItemNum = i;426 LOGGER.info("Found that expected text '" + expectedText + "' contains '" + text + "' in notification #" + notificationItemNum);427 return true;428 }429 }430 }431 }432 return false;433 }434 /**435 * clearNotifications436 */437 public void clearNotifications() {438 LOGGER.info("Clear notifications");439 NotificationPage notificationPage = new NotificationPage(getDriver());440 int attempts = 3;441 boolean isStatusBarOpened;442 // three attempts will be executed to clear notifications443 for (int i = 0; i < attempts; i++) {444 collapseStatusBar();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);...

Full Screen

Full Screen

Source:IMobileUtils.java Github

copy

Full Screen

...27import com.qaprosoft.carina.core.foundation.utils.Configuration;28import com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter;29import com.qaprosoft.carina.core.foundation.utils.Messager;30import com.qaprosoft.carina.core.foundation.utils.android.AndroidService;31import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;32import com.qaprosoft.carina.core.foundation.webdriver.DriverHelper;33import com.qaprosoft.carina.core.foundation.webdriver.IDriverPool;34import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;35import io.appium.java_client.AppiumDriver;36import io.appium.java_client.MobileDriver;37import io.appium.java_client.MultiTouchAction;38import io.appium.java_client.TouchAction;39import io.appium.java_client.android.AndroidDriver;40import io.appium.java_client.appmanagement.ApplicationState;41import io.appium.java_client.ios.IOSDriver;42import io.appium.java_client.touch.LongPressOptions;43import io.appium.java_client.touch.WaitOptions;44import io.appium.java_client.touch.offset.ElementOption;45import io.appium.java_client.touch.offset.PointOption;46public interface IMobileUtils extends IDriverPool {47 static final Logger UTILS_LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());48 public enum Direction {49 LEFT,50 RIGHT,51 UP,52 DOWN,53 VERTICAL,54 HORIZONTAL,55 VERTICAL_DOWN_FIRST,56 HORIZONTAL_RIGHT_FIRST57 }58 public enum Zoom {59 IN,60 OUT61 }62 // TODO: [VD] make private after migration to java 9+63 static final long EXPLICIT_TIMEOUT = Configuration.getLong(Parameter.EXPLICIT_TIMEOUT);64 static final int MINIMUM_TIMEOUT = 2;65 static final int DEFAULT_TOUCH_ACTION_DURATION = 1000;66 static final int DEFAULT_MAX_SWIPE_COUNT = 50;67 static final int DEFAULT_MIN_SWIPE_COUNT = 1;68 static DriverHelper helper = new DriverHelper();69 /**70 * Tap with TouchAction by the center of element71 *72 * @param element ExtendedWebElement73 */74 default public void tap(ExtendedWebElement element) {75 UTILS_LOGGER.info("tap on " + element.getName());76 Point point = element.getLocation();77 Dimension size = element.getSize();78 tap(point.getX() + size.getWidth() / 2, point.getY() + size.getHeight() / 2);79 }80 /**81 * Tap with TouchAction by coordinates with default 1000ms duration82 *83 * @param startx int84 * @param starty int85 */86 default public void tap(int startx, int starty) {87 tap(startx, starty, DEFAULT_TOUCH_ACTION_DURATION);88 }89 /**90 * tap with TouchActions slowly to imitate log tap on element91 *92 * @param elem ExtendedWebElement93 * element94 */95 default public void longTap(ExtendedWebElement elem) {96 UTILS_LOGGER.info("longTap on" + elem.getName());97 Dimension size = elem.getSize();98 int width = size.getWidth();99 int height = size.getHeight();100 Point point = elem.getLocation();101 int x = point.getX() + width / 2;102 int y = point.getY() + height / 2;103 try {104 swipe(x, y, x, y, 2500);105 } catch (Exception e) {106 UTILS_LOGGER.error("Exception: " + e);107 }108 }109 /**110 * Tap and Hold (LongPress) on element111 *112 * @param element ExtendedWebElement113 * @return boolean114 */115 default public boolean longPress(ExtendedWebElement element) {116 UTILS_LOGGER.info("longPress on" + element.getName());117 // TODO: SZ migrate to FluentWaits118 try {119 WebDriver driver = castDriver();120 @SuppressWarnings("rawtypes")121 TouchAction<?> action = new TouchAction((MobileDriver<?>) driver);122 LongPressOptions options = LongPressOptions.longPressOptions().withElement(ElementOption.element(element.getElement()));123 action.longPress(options).release().perform();124 return true;125 } catch (Exception e) {126 UTILS_LOGGER.info("Error occurs during longPress: " + e, e);127 }128 return false;129 }130 /**131 * Tap with TouchAction by coordinates with custom duration132 *133 * @param startx int134 * @param starty int135 * @param duration int136 */137 default public void tap(int startx, int starty, int duration) {138 // TODO: add Screenshot.capture()139 try {140 @SuppressWarnings("rawtypes")141 TouchAction<?> touchAction = new TouchAction((MobileDriver<?>) castDriver());142 PointOption<?> startPoint = PointOption.point(startx, starty);143 WaitOptions waitOptions = WaitOptions.waitOptions(Duration.ofMillis(duration));144 if (duration == 0) {145 // do not perform waiter as using 6.0.0. appium java client we do longpress instead of simple tap even with 0 wait duration146 touchAction.press(startPoint).release().perform();147 } else {148 touchAction.press(startPoint).waitAction(waitOptions).release().perform();149 }150 Messager.TAP_EXECUTED.info(String.valueOf(startx), String.valueOf(starty));151 } catch (Exception e) {152 Messager.TAP_NOT_EXECUTED.error(String.valueOf(startx), String.valueOf(starty));153 throw e;154 }155 }156 /**157 * swipe till element using TouchActions158 *159 * @param element ExtendedWebElement160 * @return boolean161 */162 default public boolean swipe(final ExtendedWebElement element) {163 return swipe(element, null, Direction.UP, DEFAULT_MAX_SWIPE_COUNT, DEFAULT_TOUCH_ACTION_DURATION);164 }165 /**166 * swipe till element using TouchActions167 *168 * @param element ExtendedWebElement169 * @param count int170 * @return boolean171 */172 default public boolean swipe(final ExtendedWebElement element, int count) {173 return swipe(element, null, Direction.UP, count, DEFAULT_TOUCH_ACTION_DURATION);174 }175 /**176 * swipe till element using TouchActions177 *178 * @param element ExtendedWebElement179 * @param direction Direction180 * @return boolean181 */182 default public boolean swipe(final ExtendedWebElement element, Direction direction) {183 return swipe(element, null, direction, DEFAULT_MAX_SWIPE_COUNT, DEFAULT_TOUCH_ACTION_DURATION);184 }185 /**186 * swipe till element using TouchActions187 *188 * @param element ExtendedWebElement189 * @param count int190 * @param duration int191 * @return boolean192 */193 default public boolean swipe(final ExtendedWebElement element, int count, int duration) {194 return swipe(element, null, Direction.UP, count, duration);195 }196 /**197 * swipe till element using TouchActions198 *199 * @param element ExtendedWebElement200 * @param direction Direction201 * @param count int202 * @param duration int203 * @return boolean204 */205 default public boolean swipe(final ExtendedWebElement element, Direction direction, int count, int duration) {206 return swipe(element, null, direction, count, duration);207 }208 /**209 * Swipe inside container in default direction - Direction.UP210 * Number of attempts is limited by count argument211 * <p>212 *213 * @param element214 * ExtendedWebElement215 * @param container216 * ExtendedWebElement217 * @param count218 * int219 * @return boolean220 */221 default public boolean swipe(ExtendedWebElement element, ExtendedWebElement container, int count) {222 return swipe(element, container, Direction.UP, count, DEFAULT_TOUCH_ACTION_DURATION);223 }224 /**225 * Swipe inside container in default direction - Direction.UP226 * Number of attempts is limited by 5227 * <p>228 *229 * @param element230 * ExtendedWebElement231 * @param container232 * ExtendedWebElement233 * @return boolean234 */235 default public boolean swipe(ExtendedWebElement element, ExtendedWebElement container) {236 return swipe(element, container, Direction.UP, DEFAULT_MAX_SWIPE_COUNT, DEFAULT_TOUCH_ACTION_DURATION);237 }238 /**239 * Swipe inside container in specified direction240 * Number of attempts is limited by 5241 * <p>242 *243 * @param element244 * ExtendedWebElement245 * @param container246 * ExtendedWebElement247 * @param direction248 * Direction249 * @return boolean250 */251 default public boolean swipe(ExtendedWebElement element, ExtendedWebElement container, Direction direction) {252 return swipe(element, container, direction, DEFAULT_MAX_SWIPE_COUNT, DEFAULT_TOUCH_ACTION_DURATION);253 }254 /**255 * Swipe inside container in specified direction with default pulling timeout in 1000ms256 * Number of attempts is limited by count argument257 * <p>258 *259 * @param element260 * ExtendedWebElement261 * @param container262 * ExtendedWebElement263 * @param direction264 * Direction265 * @param count266 * int267 * @return boolean268 */269 default public boolean swipe(ExtendedWebElement element, ExtendedWebElement container, Direction direction,270 int count) {271 return swipe(element, container, direction, count, DEFAULT_TOUCH_ACTION_DURATION);272 }273 /**274 * Swipe to element inside container in specified direction while element275 * will not be present on the screen. If element is on the screen already,276 * scrolling will not be performed.277 * <p>278 *279 * @param element280 * element to which it will be scrolled281 * @param container282 * element, inside which scrolling is expected. null to scroll283 * @param direction284 * direction of scrolling. HORIZONTAL and VERTICAL support swiping in both directions automatically285 * @param count286 * for how long to scroll, ms287 * @param duration288 * pulling timeout, ms289 * @return boolean290 */291 default public boolean swipe(ExtendedWebElement element, ExtendedWebElement container, Direction direction,292 int count, int duration) {293 boolean isVisible = element.isVisible(1);294 if (isVisible) {295 // no sense to continue;296 UTILS_LOGGER.info("element already present before swipe: " + element.getNameWithLocator().toString());297 return true;298 } else {299 UTILS_LOGGER.info("swiping to element: " + element.getNameWithLocator().toString());300 }301 Direction oppositeDirection = Direction.DOWN;302 boolean bothDirections = false;303 switch (direction) {304 case UP:305 oppositeDirection = Direction.DOWN;306 break;307 case DOWN:308 oppositeDirection = Direction.UP;309 break;310 case LEFT:311 oppositeDirection = Direction.RIGHT;312 break;313 case RIGHT:314 oppositeDirection = Direction.LEFT;315 break;316 case HORIZONTAL:317 direction = Direction.LEFT;318 oppositeDirection = Direction.RIGHT;319 bothDirections = true;320 break;321 case HORIZONTAL_RIGHT_FIRST:322 direction = Direction.RIGHT;323 oppositeDirection = Direction.LEFT;324 bothDirections = true;325 break;326 case VERTICAL:327 direction = Direction.UP;328 oppositeDirection = Direction.DOWN;329 bothDirections = true;330 break;331 case VERTICAL_DOWN_FIRST:332 direction = Direction.DOWN;333 oppositeDirection = Direction.UP;334 bothDirections = true;335 break;336 default:337 throw new RuntimeException("Unsupported direction for swipeInContainerTillElement: " + direction);338 }339 int currentCount = count;340 while (!isVisible && currentCount-- > 0) {341 UTILS_LOGGER.debug("Element not present! Swipe " + direction + " will be executed to element: " + element.getNameWithLocator().toString());342 swipeInContainer(container, direction, duration);343 UTILS_LOGGER.info("Swipe was executed. Attempts remain: " + currentCount);344 isVisible = element.isVisible(1);345 }346 currentCount = count;347 while (bothDirections && !isVisible && currentCount-- > 0) {348 UTILS_LOGGER.debug(349 "Element not present! Swipe " + oppositeDirection + " will be executed to element: " + element.getNameWithLocator().toString());350 swipeInContainer(container, oppositeDirection, duration);351 UTILS_LOGGER.info("Swipe was executed. Attempts remain: " + currentCount);352 isVisible = element.isVisible(1);353 }354 UTILS_LOGGER.info("Result: " + isVisible);355 return isVisible;356 }357 /**358 * Swipe by coordinates using TouchAction (platform independent)359 *360 * @param startx int361 * @param starty int362 * @param endx int363 * @param endy int364 * @param duration int Millis365 */366 @SuppressWarnings("rawtypes")367 default public void swipe(int startx, int starty, int endx, int endy, int duration) {368 UTILS_LOGGER.debug("Starting swipe...");369 WebDriver drv = castDriver();370 UTILS_LOGGER.debug("Getting driver dimension size...");371 Dimension scrSize = drv.manage().window().getSize();372 UTILS_LOGGER.debug("Finished driver dimension size...");373 // explicitly limit range of coordinates374 if (endx >= scrSize.width) {375 UTILS_LOGGER.warn("endx coordinate is bigger then device width! It will be limited!");376 endx = scrSize.width - 1;377 } else {378 endx = Math.max(1, endx);379 }380 if (endy >= scrSize.height) {381 UTILS_LOGGER.warn("endy coordinate is bigger then device height! It will be limited!");382 endy = scrSize.height - 1;383 } else {384 endy = Math.max(1, endy);385 }386 UTILS_LOGGER.debug("startx: " + startx + "; starty: " + starty + "; endx: " + endx + "; endy: " + endy387 + "; duration: " + duration);388 PointOption<?> startPoint = PointOption.point(startx, starty);389 PointOption<?> endPoint = PointOption.point(endx, endy);390 WaitOptions waitOptions = WaitOptions.waitOptions(Duration.ofMillis(duration));391 new TouchAction((MobileDriver<?>) drv).press(startPoint).waitAction(waitOptions).moveTo(endPoint).release()392 .perform();393 UTILS_LOGGER.debug("Finished swipe...");394 }395 /**396 * swipeInContainer397 *398 * @param container ExtendedWebElement399 * @param direction Direction400 * @param duration int401 * @return boolean402 */403 default public boolean swipeInContainer(ExtendedWebElement container, Direction direction, int duration) {404 return swipeInContainer(container, direction, DEFAULT_MIN_SWIPE_COUNT, duration);405 }406 /**407 * swipeInContainer408 *409 * @param container ExtendedWebElement410 * @param direction Direction411 * @param count int412 * @param duration int413 * @return boolean414 */415 default public boolean swipeInContainer(ExtendedWebElement container, Direction direction, int count, int duration) {416 int startx = 0;417 int starty = 0;418 int endx = 0;419 int endy = 0;420 Point elementLocation = null;421 Dimension elementDimensions = null;422 if (container == null) {423 // whole screen/driver is a container!424 WebDriver driver = castDriver();425 elementLocation = new Point(0, 0); // initial left corner for that case426 elementDimensions = driver.manage().window().getSize();427 } else {428 if (container.isElementNotPresent(5)) {429 Assert.fail("Cannot swipe! Impossible to find element " + container.getName());430 }431 elementLocation = container.getLocation();432 elementDimensions = container.getSize();433 }434 double minCoefficient = 0.3;435 double maxCoefficient = 0.6;436 // calculate default coefficient based on OS type437 String os = IDriverPool.getDefaultDevice().getOs();438 if (os.equalsIgnoreCase(SpecialKeywords.ANDROID)) {439 minCoefficient = 0.25;440 maxCoefficient = 0.5;441 } else if (os.equalsIgnoreCase(SpecialKeywords.IOS) || os.equalsIgnoreCase(SpecialKeywords.MAC) || os.equalsIgnoreCase(SpecialKeywords.TVOS)) {442 minCoefficient = 0.25;443 maxCoefficient = 0.8;444 }445 switch (direction) {446 case LEFT:447 starty = endy = elementLocation.getY() + Math.round(elementDimensions.getHeight() / 2f);448 startx = (int) (elementLocation.getX() + Math.round(maxCoefficient * elementDimensions.getWidth()));449 endx = (int) (elementLocation.getX() + Math.round(minCoefficient * elementDimensions.getWidth()));450 break;451 case RIGHT:452 starty = endy = elementLocation.getY() + Math.round(elementDimensions.getHeight() / 2f);453 startx = (int) (elementLocation.getX() + Math.round(minCoefficient * elementDimensions.getWidth()));454 endx = (int) (elementLocation.getX() + Math.round(maxCoefficient * elementDimensions.getWidth()));455 break;456 case UP:457 startx = endx = elementLocation.getX() + Math.round(elementDimensions.getWidth() / 2f);458 starty = (int) (elementLocation.getY() + Math.round(maxCoefficient * elementDimensions.getHeight()));459 endy = (int) (elementLocation.getY() + Math.round(minCoefficient * elementDimensions.getHeight()));460 break;461 case DOWN:462 startx = endx = elementLocation.getX() + Math.round(elementDimensions.getWidth() / 2f);463 starty = (int) (elementLocation.getY() + Math.round(minCoefficient * elementDimensions.getHeight()));464 endy = (int) (elementLocation.getY() + Math.round(maxCoefficient * elementDimensions.getHeight()));465 break;466 default:467 throw new RuntimeException("Unsupported direction: " + direction);468 }469 UTILS_LOGGER.debug(String.format("Swipe from (X = %d; Y = %d) to (X = %d; Y = %d)", startx, starty, endx, endy));470 try {471 for (int i = 0; i < count; ++i) {472 swipe(startx, starty, endx, endy, duration);473 }474 return true;475 } catch (Exception e) {476 UTILS_LOGGER.error(String.format("Error during Swipe from (X = %d; Y = %d) to (X = %d; Y = %d): %s", startx, starty, endx, endy, e));477 }478 return false;479 }480 /**481 * Swipe up several times482 *483 * @param times int484 * @param duration int485 */486 default public void swipeUp(final int times, final int duration) {487 for (int i = 0; i < times; i++) {488 swipeUp(duration);489 }490 }491 /**492 * Swipe up493 *494 * @param duration int495 */496 default public void swipeUp(final int duration) {497 UTILS_LOGGER.info("Swipe up will be executed.");498 swipeInContainer(null, Direction.UP, duration);499 }500 /**501 * Swipe down several times502 *503 * @param times int504 * @param duration int505 */506 default public void swipeDown(final int times, final int duration) {507 for (int i = 0; i < times; i++) {508 swipeDown(duration);509 }510 }511 /**512 * Swipe down513 *514 * @param duration int515 */516 default public void swipeDown(final int duration) {517 UTILS_LOGGER.info("Swipe down will be executed.");518 swipeInContainer(null, Direction.DOWN, duration);519 }520 /**521 * Swipe left several times522 *523 * @param times int524 * @param duration int525 */526 default public void swipeLeft(final int times, final int duration) {527 for (int i = 0; i < times; i++) {528 swipeLeft(duration);529 }530 }531 /**532 * Swipe left533 *534 * @param duration int535 */536 default public void swipeLeft(final int duration) {537 UTILS_LOGGER.info("Swipe left will be executed.");538 swipeLeft(null, duration);539 }540 /**541 * Swipe left in container542 *543 * @param container544 * ExtendedWebElement545 * @param duration546 * int547 */548 default public void swipeLeft(ExtendedWebElement container, final int duration) {549 UTILS_LOGGER.info("Swipe left will be executed.");550 swipeInContainer(container, Direction.LEFT, duration);551 }552 /**553 * Swipe right several times554 *555 * @param times int556 * @param duration int557 */558 default public void swipeRight(final int times, final int duration) {559 for (int i = 0; i < times; i++) {560 swipeRight(duration);561 }562 }563 /**564 * Swipe right565 *566 * @param duration int567 */568 default public void swipeRight(final int duration) {569 UTILS_LOGGER.info("Swipe right will be executed.");570 swipeRight(null, duration);571 }572 /**573 * Swipe right in container574 *575 * @param container576 * ExtendedWebElement577 * @param duration578 * int579 */580 default public void swipeRight(ExtendedWebElement container, final int duration) {581 UTILS_LOGGER.info("Swipe right will be executed.");582 swipeInContainer(container, Direction.RIGHT, duration);583 }584 /**585 * Set Android Device Default TimeZone And Language based on config or to GMT and En586 * Without restoring actual focused apk.587 */588 default public void setDeviceDefaultTimeZoneAndLanguage() {589 setDeviceDefaultTimeZoneAndLanguage(false);590 }591 /**592 * set Android Device Default TimeZone And Language based on config or to GMT and En593 *594 * @param returnAppFocus - if true store actual Focused apk and activity, than restore after setting Timezone and Language.595 */596 default public void setDeviceDefaultTimeZoneAndLanguage(boolean returnAppFocus) {597 try {598 String baseApp = "";599 String os = IDriverPool.getDefaultDevice().getOs();600 if (os.equalsIgnoreCase(SpecialKeywords.ANDROID)) {601 AndroidService androidService = AndroidService.getInstance();602 if (returnAppFocus) {603 baseApp = androidService.getCurrentFocusedApkDetails();604 }605 String deviceTimezone = Configuration.get(Parameter.DEFAULT_DEVICE_TIMEZONE);606 String deviceTimeFormat = Configuration.get(Parameter.DEFAULT_DEVICE_TIME_FORMAT);607 String deviceLanguage = Configuration.get(Parameter.DEFAULT_DEVICE_LANGUAGE);608 DeviceTimeZone.TimeFormat timeFormat = DeviceTimeZone.TimeFormat.parse(deviceTimeFormat);609 DeviceTimeZone.TimeZoneFormat timeZone = DeviceTimeZone.TimeZoneFormat.parse(deviceTimezone);610 UTILS_LOGGER.info("Set device timezone to " + timeZone.toString());611 UTILS_LOGGER.info("Set device time format to " + timeFormat.toString());612 UTILS_LOGGER.info("Set device language to " + deviceLanguage);613 boolean timeZoneChanged = androidService.setDeviceTimeZone(timeZone.getTimeZone(), timeZone.getSettingsTZ(), timeFormat);614 boolean languageChanged = androidService.setDeviceLanguage(deviceLanguage);615 UTILS_LOGGER.info(String.format("Device TimeZone was changed to timeZone '%s' : %s. Device Language was changed to language '%s': %s",616 deviceTimezone,617 timeZoneChanged, deviceLanguage, languageChanged));618 if (returnAppFocus) {619 androidService.openApp(baseApp);620 }621 } else {622 UTILS_LOGGER.info(String.format("Current OS is %s. But we can set default TimeZone and Language only for Android.", os));623 }624 } catch (Exception e) {625 UTILS_LOGGER.error("Error while setting to device default timezone and language!", e);626 }627 }...

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import java.io.IOException;3import java.util.ArrayList;4import java.util.List;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.support.ui.ExpectedConditions;10import org.openqa.selenium.support.ui.WebDriverWait;11import org.testng.Assert;12import org.testng.annotations.AfterMethod;13import org.testng.annotations.BeforeMethod;14import org.testng.annotations.Test;15import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;16import com.qaprosoft.carina.core.foundation.utils.mobile.MobileUtils;17import com.qaprosoft.carina.core.foundation.webdriver.DriverPool;18import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;19import com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy;20import io.appium.java_client.android.AndroidDriver;21import io.appium.java_client.android.AndroidElement;22public class AndroidTest {23 private AndroidDriver<AndroidElement> driver;24 public void setUp() throws IOException {25 DesiredCapabilities capabilities = new DesiredCapabilities();26 capabilities.setCapability("platformName", "Android");27 capabilities.setCapability("platformVersion", "7.0");28 capabilities.setCapability("deviceName", "emulator-5554");29 capabilities.setCapability("appPackage", "com.android.calculator2");30 capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");31 capabilities.setCapability("automationName", "uiautomator2");32 capabilities.setCapability("noReset", true);33 capabilities.setCapability("newCommandTimeout", 300);34 driver = new AndroidDriver<>(MobileUtils.getMobileServiceUrl(), capabilities);35 DriverPool.setWebDriver(driver);36 }37 public void tearDown() {38 DriverPool.DEFAULT.dismissAll();39 }40 public void test() {41 DeviceTimeZone deviceTimeZone = new DeviceTimeZone(driver);42 deviceTimeZone.setDeviceTimeZone("Asia/Kolkata");43 deviceTimeZone.setDeviceTimeZone("America/Chicago");44 deviceTimeZone.setDeviceTimeZone("Asia/Kolkata");45 }46}47package com.qaprosoft.carina.demo;48import java.io.IOException;49import java.util.ArrayList;50import java.util.List;51import org.openqa.selenium.By;52import org.openqa

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;4public class TestDeviceTimeZone {5 public void testDeviceTimeZone() {6 DeviceTimeZone dtz = new DeviceTimeZone();7 dtz.getDeviceTimeZone();8 }9}

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 DeviceTimeZone tz = new DeviceTimeZone();4 String deviceTimeZone = tz.getDeviceTimeZone();5 System.out.println(deviceTimeZone);6 }7}8public class 2 {9 public static void main(String[] args) {10 DeviceTimeZone tz = new DeviceTimeZone();11 String deviceTimeZone = tz.getDeviceTimeZone();12 System.out.println(deviceTimeZone);13 }14}15public class 3 {16 public static void main(String[] args) {17 DeviceTimeZone tz = new DeviceTimeZone();18 String deviceTimeZone = tz.getDeviceTimeZone();19 System.out.println(deviceTimeZone);20 }21}22public class 4 {23 public static void main(String[] args) {24 DeviceTimeZone tz = new DeviceTimeZone();25 String deviceTimeZone = tz.getDeviceTimeZone();26 System.out.println(deviceTimeZone);27 }28}29public class 5 {30 public static void main(String[] args) {31 DeviceTimeZone tz = new DeviceTimeZone();32 String deviceTimeZone = tz.getDeviceTimeZone();33 System.out.println(deviceTimeZone);34 }35}36public class 6 {37 public static void main(String[] args) {38 DeviceTimeZone tz = new DeviceTimeZone();39 String deviceTimeZone = tz.getDeviceTimeZone();40 System.out.println(deviceTimeZone);41 }42}43public class 7 {44 public static void main(String[] args) {45 DeviceTimeZone tz = new DeviceTimeZone();46 String deviceTimeZone = tz.getDeviceTimeZone();47 System.out.println(deviceTimeZone);48 }49}

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;4public class DeviceTimeZoneDemo {5 public void testDeviceTimeZone() {6 DeviceTimeZone.setDeviceTimeZone("Asia/Kolkata");7 }8}9package com.qaprosoft.carina.demo;10import org.testng.annotations.Test;11import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;12public class DeviceTimeZoneDemo {13 public void testDeviceTimeZone() {14 DeviceTimeZone.setDeviceTimeZone("America/New_York");15 }16}17package com.qaprosoft.carina.demo;18import org.testng.annotations.Test;19import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;20public class DeviceTimeZoneDemo {21 public void testDeviceTimeZone() {22 DeviceTimeZone.setDeviceTimeZone("Europe/Paris");23 }24}25package com.qaprosoft.carina.demo;26import org.testng.annotations.Test;27import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;28public class DeviceTimeZoneDemo {29 public void testDeviceTimeZone() {30 DeviceTimeZone.setDeviceTimeZone("Europe/London");31 }32}33package com.qaprosoft.carina.demo;34import org.testng.annotations.Test;35import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;36public class DeviceTimeZoneDemo {37 public void testDeviceTimeZone() {38 DeviceTimeZone.setDeviceTimeZone("Europe/Moscow");39 }40}

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.core.foundation.utils.android;2import java.util.TimeZone;3import org.testng.Assert;4import org.testng.annotations.Test;5public class DeviceTimeZoneTest {6@Test(description = "Test to get the device time zone")7public void testDeviceTimeZone() {8TimeZone timeZone = DeviceTimeZone.getDeviceTimeZone();9Assert.assertNotNull(timeZone, "Device time zone is null");10System.out.println("Device time zone is : " + timeZone);11}12}

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;2import java.util.TimeZone;3public class 1 {4public static void main(String[] args) {5TimeZone currentTZ = DeviceTimeZone.getCurrentTimeZone();6TimeZone deviceTZ = DeviceTimeZone.getDeviceTimeZone();7DeviceTimeZone.setDeviceTimeZone(TimeZone.getTimeZone("GMT"));8}9}10import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;11import java.util.TimeZone;12public class 2 {13public static void main(String[] args) {14TimeZone currentTZ = DeviceTimeZone.getCurrentTimeZone();15TimeZone deviceTZ = DeviceTimeZone.getDeviceTimeZone();16DeviceTimeZone.setDeviceTimeZone(TimeZone.getTimeZone("GMT"));17}18}19import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;20import java.util.TimeZone;21public class 3 {22public static void main(String[] args) {23TimeZone currentTZ = DeviceTimeZone.getCurrentTimeZone();24TimeZone deviceTZ = DeviceTimeZone.getDeviceTimeZone();25DeviceTimeZone.setDeviceTimeZone(TimeZone.getTimeZone("GMT"));26}27}28import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;29import java.util.TimeZone;30public class 4 {31public static void main(String[] args) {32TimeZone currentTZ = DeviceTimeZone.getCurrentTimeZone();33TimeZone deviceTZ = DeviceTimeZone.getDeviceTimeZone();34DeviceTimeZone.setDeviceTimeZone(TimeZone.getTimeZone("GMT"));35}36}37import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;38import java.util.TimeZone;

Full Screen

Full Screen

DeviceTimeZone

Using AI Code Generation

copy

Full Screen

1import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;2import java.util.TimeZone;3TimeZone timeZone = DeviceTimeZone.getTimeZone();4System.out.println("TimeZone: " + timeZone.getDisplayName());5System.out.println("TimeZone ID: " + timeZone.getID());6System.out.println("TimeZone Offset: " + timeZone.getOffset(System.currentTimeMillis()));7System.out.println("TimeZone Offset: " + timeZone.getOffset(0));8import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;9import java.util.TimeZone;10TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");11DeviceTimeZone.setTimeZone(timeZone);12import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;13import java.util.TimeZone;14TimeZone timeZone = TimeZone.getTimeZone("America/Los_Angeles");15DeviceTimeZone.setTimeZone(timeZone.getID());16import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;17DeviceTimeZone.setTimeZone("America/Los_Angeles");18import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;19DeviceTimeZone.setTimeZone("America/Los_Angeles");20import com.qaprosoft.carina.core.foundation.utils.android.DeviceTimeZone;21import java.util.TimeZone;22TimeZone timeZone = DeviceTimeZone.getTimeZone();23System.out.println("TimeZone: " + timeZone.getDisplayName());24System.out.println("TimeZone ID: " + timeZone.getID());25System.out.println("TimeZone Offset: " + timeZone.getOffset(System.currentTimeMillis()));26System.out.println("TimeZone Offset: " + timeZone.getOffset(0));

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