From b0165602145ee3ff4676d9ece804e8d1671e7a97 Mon Sep 17 00:00:00 2001 From: Wasiq Bhamla Date: Mon, 2 Sep 2019 14:32:09 +0530 Subject: [PATCH] Release v3.1.0 (#93) * Added funding option (#89) * Updated dependencies for Appium, Selenium and other supporting libraries. (#88) * Updated outdated dependencies. * Fixed SonarCloud issues. (#91) * Released beta 1 for v3.1.0 --- pom.xml | 2 +- .../appium/android/AndroidActivity.java | 11 +++-- .../appium/android/AndroidDeviceActions.java | 39 +++++++-------- .../wasiqb/coteafs/appium/device/Device.java | 18 +++---- .../coteafs/appium/device/DeviceActions.java | 29 +++++------- .../coteafs/appium/device/DeviceActivity.java | 47 ++++++++++--------- .../appium/device/DeviceElementActions.java | 14 +++--- .../appium/device/DeviceElementVerify.java | 15 +++--- .../coteafs/appium/ios/IOSActivity.java | 7 +-- .../coteafs/appium/ios/IOSDeviceActions.java | 15 +++--- .../appium/ios/IOSDeviceElementActions.java | 21 ++++----- .../coteafs/appium/utils/BatteryHealth.java | 5 +- .../coteafs/appium/utils/CapabilityUtils.java | 14 +++--- .../coteafs/appium/utils/ErrorUtils.java | 9 ++-- .../coteafs/appium/utils/ScreenRecorder.java | 2 +- 15 files changed, 114 insertions(+), 134 deletions(-) diff --git a/pom.xml b/pom.xml index 7846b20..a52730d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 appium - 3.0.0 + 3.1.0-beta1 ${project.groupId}:${project.artifactId} Robust Automation Framework wrapped over Appium. https://github.com/WasiqB/coteafs-appium diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidActivity.java b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidActivity.java index 4db118a..884a2b3 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidActivity.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidActivity.java @@ -34,7 +34,7 @@ */ public abstract class AndroidActivity extends DeviceActivity , AndroidDevice, AndroidTouchAction> { - private static final Logger log = LogManager.getLogger (AndroidActivity.class); + private static final Logger LOG = LogManager.getLogger (AndroidActivity.class); /** * @author wasiq.bhamla @@ -52,19 +52,20 @@ public AndroidActivity (final AndroidDevice device) { @Override public AndroidDeviceActions onDevice () { checkBattery (); - log.trace ("Preparing to perform actions on Android device..."); + LOG.trace ("Preparing to perform actions on Android device..."); return new AndroidDeviceActions (this.device); } /* * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceActivity#onElement(java.lang.String) + * @see + * com.github.wasiqb.coteafs.appium.device.DeviceActivity#onElement(java.lang. + * String) */ @Override public AndroidDeviceElementActions onElement (final String name) { checkBattery (); - final String msg = "Preparing to perform actions on Android device element [%s]..."; - log.trace (String.format (msg, name)); + LOG.trace ("Preparing to perform actions on Android device element [{}]...", name); return new AndroidDeviceElementActions (this.device, name, getElement (name)); } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceActions.java index cc26fa0..d225421 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceActions.java @@ -17,7 +17,6 @@ import static com.github.wasiqb.coteafs.appium.constants.ErrorMessage.SERVER_STOPPED; import static com.github.wasiqb.coteafs.appium.utils.ErrorUtils.fail; -import static java.lang.String.format; import java.util.function.Consumer; import java.util.function.Function; @@ -46,7 +45,7 @@ */ public class AndroidDeviceActions extends DeviceActions , AndroidDevice, AndroidTouchAction> { - private static final Logger log = LogManager.getLogger (AndroidDeviceActions.class); + private static final Logger LOG = LogManager.getLogger (AndroidDeviceActions.class); /** * @author wasiq.bhamla @@ -63,7 +62,7 @@ public AndroidDeviceActions (final AndroidDevice device) { * @return clipboard text */ public String clipboard () { - log.info ("Getting clipboard text..."); + LOG.info ("Getting clipboard text..."); return this.driver.getClipboardText (); } @@ -74,7 +73,7 @@ public String clipboard () { * @return clipboard */ public String clipboard (final ClipboardType type) { - log.info (format ("Getting clipboard for [%s]...", type)); + LOG.info ("Getting clipboard for [{}]...", type); return this.driver.getClipboard (type.getType ()); } @@ -95,19 +94,18 @@ public String currentActivity () { */ public String handleAlert () { return getValue ("Handling Android Alert pop-up...", d -> { - final String msg = "Alert Text: %s"; try { final AlertActivity perm = new AlertActivity (this.device); final String description = perm.onElement ("Message") .text (); - log.trace (String.format (msg, description)); + LOG.trace ("Alert Text: {}", description); perm.onElement ("OK") .tap (); return description; } catch (final TimeoutException e) { - log.warn ("Expected Alert not displayed..."); - log.warn (e.getMessage ()); + LOG.warn ("Expected Alert not displayed..."); + LOG.warn (e.getMessage ()); } return null; }); @@ -121,19 +119,18 @@ public String handleAlert () { */ public String handlePermissionAlert (final String buttonText) { return getValue ("Handling Android Permission Alert pop-up...", d -> { - final String msg = "Alert Text: %s"; try { final PermissionActivity perm = new PermissionActivity (this.device); final String description = perm.onElement ("Message") .text (); - log.trace (String.format (msg, description)); + LOG.trace ("Alert Text: {}", description); perm.onElement (buttonText) .tap (); return description; } catch (final TimeoutException e) { - log.warn ("Expected Alert not displayed..."); - log.warn (e.getMessage ()); + LOG.warn ("Expected Alert not displayed..."); + LOG.warn (e.getMessage ()); } return null; }); @@ -144,7 +141,7 @@ public String handlePermissionAlert (final String buttonText) { * @since Oct 20, 2018 */ public void hideKeyboard () { - log.info ("Hiding the keyboard..."); + LOG.info ("Hiding the keyboard..."); try { if (this.driver.isKeyboardShown ()) { this.driver.hideKeyboard (); @@ -184,7 +181,7 @@ public void pinch (final int distance) { super.pinch (distance); } else { - log.warn ("Pinch is only available when Automation type is Espresso..."); + LOG.warn ("Pinch is only available when Automation type is Espresso..."); } } @@ -211,7 +208,7 @@ public void pressEnter () { * @since Nov 2, 2018 */ public void toggleAirplane () { - log.info ("Toggling Airplane..."); + LOG.info ("Toggling Airplane..."); this.driver.toggleAirplaneMode (); } @@ -220,7 +217,7 @@ public void toggleAirplane () { * @since Nov 2, 2018 */ public void toggleData () { - log.info ("Toggling Data..."); + LOG.info ("Toggling Data..."); this.driver.toggleData (); } @@ -229,7 +226,7 @@ public void toggleData () { * @since Nov 2, 2018 */ public void toggleLocation () { - log.info ("Toggling Location services..."); + LOG.info ("Toggling Location services..."); this.driver.toggleLocationServices (); } @@ -238,7 +235,7 @@ public void toggleLocation () { * @since Nov 2, 2018 */ public void toggleWifi () { - log.info ("Toggling Wifi..."); + LOG.info ("Toggling Wifi..."); this.driver.toggleWifi (); } @@ -261,13 +258,13 @@ public void zoom (final int distance) { super.zoom (distance); } else { - log.warn ("Zoom is only available when Automation type is Espresso..."); + LOG.warn ("Zoom is only available when Automation type is Espresso..."); } } private T getValue (final String message, final Function , T> action, final Object... args) { - log.info (format (message, args)); + LOG.info (message, args); try { return action.apply (this.driver); } @@ -279,7 +276,7 @@ private T getValue (final String message, private void perform (final String message, final Consumer > action, final Object... args) { - log.info (format (message, args)); + LOG.info (message, args); try { action.accept (this.driver); } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java index b39f573..dd446af 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java @@ -164,8 +164,7 @@ public void executeCommand (final String command, final Map arg * @return driver */ public D getDriver () { - final String msg = "Getting [%s] device driver..."; - LOG.trace (format (msg, this.platform)); + LOG.trace ("Getting [{}] device driver...", this.platform); return this.driver; } @@ -205,8 +204,7 @@ public void stop () { this.driver = null; } else { - final String message = "[%s] device driver already stopped..."; - LOG.trace (format (message, this.platform)); + LOG.trace ("[{}] device driver already stopped...", this.platform); } } @@ -243,9 +241,9 @@ private void buildCapabilities () { } final File file = new File (path); if (!file.exists ()) { - final String msg = "App not found on mentioned location [%s]..."; - LOG.error (format (msg, path)); - fail (DeviceAppNotFoundError.class, format (msg, path)); + final String msg = format ("App not found on mentioned location [%s]...", path); + LOG.error (msg); + fail (DeviceAppNotFoundError.class, msg); } appPath = path; } @@ -277,8 +275,7 @@ private D init (final URL url, final Capabilities capability) { } private void quitApp () { - final String message = "Closing & Quitting [%s] device driver..."; - LOG.trace (format (message, this.platform)); + LOG.trace ("Closing & Quitting [{}] device driver...", this.platform); try { this.driver.closeApp (); this.driver.quit (); @@ -402,8 +399,7 @@ private void setIOSCapabilities () { } private void startDriver () { - final String msg = "Starting [%s] device driver..."; - LOG.trace (format (msg, this.platform)); + LOG.trace ("Starting [{}] device driver...", this.platform); try { this.driver = init (this.server.getServiceUrl (), this.capabilities); } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActions.java index 46acc68..4bc3d76 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActions.java @@ -53,7 +53,7 @@ */ public class DeviceActions , E extends Device , T extends TouchAction > { - private static final Logger log = LogManager.getLogger (DeviceActions.class); + private static final Logger LOG = LogManager.getLogger (DeviceActions.class); /** * @author wasiq.bhamla @@ -66,8 +66,8 @@ private static void copyFile (final File source, final String destination) { FileUtils.copyFile (source, new File (destination)); } catch (final IOException e) { - log.error ("Error occurred while capturing screensshot..."); - log.catching (e); + LOG.error ("Error occurred while capturing screensshot..."); + LOG.catching (e); } } @@ -112,7 +112,7 @@ public void captureScreenshot () { * @param url */ public void navigateTo (final String url) { - log.info (format ("Navigating to URL [%S]...", url)); + LOG.info ("Navigating to URL [{}]...", url); this.driver.get (url); } @@ -122,7 +122,7 @@ public void navigateTo (final String url) { * @param distance */ public void pinch (final int distance) { - log.info (format ("Pinching on device screen by [%d]% distance...", distance)); + LOG.info ("Pinching on device screen by [{}]% distance...", distance); doubleFingerGesture (SwipeDirection.DOWN, SwipeDirection.UP, SwipeStartPosition.TOP, SwipeStartPosition.BOTTOM, distance); } @@ -133,7 +133,7 @@ public void pinch (final int distance) { * @param type */ public void rotate (final ScreenOrientation type) { - log.info (format ("Rotating device screen as [%s]c...", type)); + LOG.info ("Rotating device screen as [{}]...", type); this.driver.rotate (type); } @@ -143,7 +143,7 @@ public void rotate (final ScreenOrientation type) { * @return rotation */ public ScreenOrientation rotation () { - log.info ("Getting rotation type for device..."); + LOG.info ("Getting rotation type for device..."); return this.driver.getOrientation (); } @@ -156,9 +156,8 @@ public ScreenOrientation rotation () { */ public void swipe (final SwipeDirection direction, final SwipeStartPosition start, final int distance) { - log.info (format ( - "Swiping [%s] on device screen by [%d] perc distance from [%s] of the screen...", - direction, distance, start)); + LOG.info ("Swiping [%s] on device screen by [{}] perc distance from [%s] of the screen...", + direction, distance, start); swipeTo (direction, start, distance).perform (); } @@ -168,19 +167,13 @@ public void swipe (final SwipeDirection direction, final SwipeStartPosition star * @param distance */ public void zoom (final int distance) { - log.info (format ("Zooming in device screen by [%d]% distance...", distance)); + LOG.info ("Zooming in device screen by [{}]% distance...", distance); doubleFingerGesture (SwipeDirection.UP, SwipeDirection.DOWN, SwipeStartPosition.CENTER, SwipeStartPosition.CENTER, distance); } - /** - * @author wasiq.bhamla - * @since 01-May-2017 8:24:34 PM - * @param path - */ private void captureScreenshot (final String path) { - final String msg = "Capturing screenshot and saving at [%s]..."; - log.info (format (msg, path)); + LOG.info ("Capturing screenshot and saving at [{}]...", path); try { final File srcFiler = this.driver.getScreenshotAs (OutputType.FILE); copyFile (srcFiler, path); diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java index b058102..7fcc4c3 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -95,8 +96,7 @@ public DeviceActivity (final E device, final T touch) { */ public MobileElement getElement (final String name) { load (); - final String msg = "Getting element with name [%s]..."; - log.trace (String.format (msg, name)); + log.trace ("Getting element with name [{}]...", name); return findElements (getDeviceElement (name)); } @@ -119,8 +119,7 @@ public DeviceActions onDevice () { */ public DeviceElementActions onElement (final String name) { ServerChecker.checkServerRunning (this.device.server); - final String msg = "Preparing to perform actions on device element [%s]..."; - log.trace (String.format (msg, name)); + log.trace ("Preparing to perform actions on device element [{}]...", name); return new DeviceElementActions <> (this.device, name, getElement (name), this.touch); } @@ -133,9 +132,11 @@ public DeviceElementActions onElement (final String name) { */ public DeviceElementActions onElement (final String name, final int index) { ServerChecker.checkServerRunning (this.device.server); - final String msg = "Preparing to perform actions on dynamic device element [%s] on index [%d]..."; - log.trace (String.format (msg, name, index)); - final DeviceElement element = getDeviceElement (name).index (index); + log.trace ("Preparing to perform actions on dynamic device element [{}] on index [{}]...", + name, index); + final DeviceElement e = getDeviceElement (name); + final DeviceElement element = Objects.requireNonNull (e, "Element not found.") + .index (index); return new DeviceElementActions <> (this.device, name, findElements (element), this.touch); } @@ -158,22 +159,21 @@ private MobileElement find (final D deviceDriver, final DeviceElement parent, fi wait (locator, strategy); List result = null; if (parent != null) { - final String message = "Finding child element of [%s] parent using [%s] at index [%d]..."; - log.trace (String.format (message, parent.name (), locator, index)); + log.trace ("Finding child element of [{}] parent using [{}] at index [{}]...", + parent.name (), locator, index); final MobileElement mobileElement = getElement (parent.name ()); result = mobileElement.findElements (locator); } else { - final String message = "Finding root element using [%s] at index [%d]..."; - log.trace (String.format (message, locator, index)); + log.trace ("Finding root element using [{}] at index [{}]...", locator, index); result = deviceDriver.findElements (locator); } return result.get (index); } catch (final TimeoutException e) { captureScreenshotOnError (); - final String message = "[%s] locator timed out."; - fail (DeviceElementFindTimedOutError.class, String.format (message, locator), e); + final String message = String.format ("[%s] locator timed out.", locator); + fail (DeviceElementFindTimedOutError.class, message, e); } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); @@ -185,19 +185,23 @@ private MobileElement find (final D deviceDriver, final DeviceElement parent, fi captureScreenshotOnError (); String message = ""; if (parent == null) { - message = "Error occured while finding root device element with locator [%s] at index [%d]."; - fail (DeviceElementNotFoundError.class, String.format (message, locator, index), e); + message = String.format ( + "Error occured while finding root device element with locator [%s] at index [%d].", + locator, index); + fail (DeviceElementNotFoundError.class, message, e); } else { - message = "Error occured while finding device element with locator [%s] at index [%d] under parent %s."; - fail (DeviceElementNotFoundError.class, - String.format (message, locator, index, parent.name ()), e); + message = String.format ( + "Error occured while finding device element with locator [%s] at index [%d] under parent %s.", + locator, index, parent.name ()); + fail (DeviceElementNotFoundError.class, message, e); } } return null; } private MobileElement findElements (final DeviceElement element) { + Objects.requireNonNull (element, "Element is required."); final DeviceElement parent = element.parent (); final By locator = element.locator (this.platform, this.automation); final int index = element.index (); @@ -207,15 +211,14 @@ private MobileElement findElements (final DeviceElement element) { private DeviceElement getDeviceElement (final String name) { if (this.deviceElements.containsKey (name)) return this.deviceElements.get (name); - final String msg = "DeviceElement with name [%s] not found."; - fail (DeviceElementNameNotFoundError.class, String.format (msg, name)); + final String msg = String.format ("DeviceElement with name [%s] not found.", name); + fail (DeviceElementNameNotFoundError.class, msg); return null; } private void load () { if (this.deviceElements.size () == 0) { - final String msg = "Loading elements on [%s] activity..."; - log.trace (String.format (msg, this.platform)); + log.trace ("Loading elements on [{}] activity...", this.platform); loadElements (prepare ()); } } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java index 24491e6..51140bb 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java @@ -54,7 +54,7 @@ */ public class DeviceElementActions , E extends Device , T extends TouchAction > { - private static final Logger log = LogManager.getLogger (DeviceElementActions.class); + private static final Logger log = LogManager.getLogger (DeviceElementActions.class); protected final E device; protected final MobileElement element; @@ -139,7 +139,7 @@ public void dragDrop (final MobileElement dropElement) { * @return enabled */ public boolean enabled () { - return getValue ("Checking if element [%s] is enabled...", MobileElement::isEnabled); + return getValue ("Checking if element [{}] is enabled...", MobileElement::isEnabled); } /** @@ -217,7 +217,7 @@ public void pinch (final int distance) { * @return selected */ public boolean selected () { - return getValue ("Checking if element [%s] is selected...", MobileElement::isSelected); + return getValue ("Checking if element [{}] is selected...", MobileElement::isSelected); } /** @@ -259,7 +259,7 @@ public void tap () { * @return text */ public String text () { - return getValue ("Getting text on element [%s]...", MobileElement::getText); + return getValue ("Getting text on element [{}]...", MobileElement::getText); } /** @@ -277,7 +277,7 @@ public DeviceElementVerify verifyThat () { * @return visible */ public boolean visible () { - return getValue ("Checking if element [%s] is visible...", MobileElement::isDisplayed); + return getValue ("Checking if element [{}] is visible...", MobileElement::isDisplayed); } /** @@ -306,7 +306,7 @@ private void doubleFingerGesture (final SwipeDirection finger1, final SwipeDirec } private R getValue (final String message, final Function func) { - log.info (String.format (message, this.name)); + log.info (message, this.name); try { return func.apply (this.element); } @@ -318,7 +318,7 @@ private R getValue (final String message, final Function private void perform (final String action, final Consumer consumer) { checkElementEnabled (); - log.info (String.format ("%s element [%s]...", action, this.name)); + log.info ("{} element [{}]...", action, this.name); try { consumer.accept (this.element); } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementVerify.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementVerify.java index f5bbafd..c497927 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementVerify.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementVerify.java @@ -31,14 +31,12 @@ * @param * @since 19-May-2017 9:57:58 PM */ -public class DeviceElementVerify , E extends Device , T extends TouchAction > { - private static final Logger log; +public class DeviceElementVerify , E extends Device , + T extends TouchAction > { + private static final Logger log = LogManager + .getLogger (DeviceElementVerify.class); - static { - log = LogManager.getLogger (DeviceElementActions.class); - } - - private final DeviceElementActions actions; + private final DeviceElementActions actions; /** * @author wasiq.bhamla @@ -100,8 +98,7 @@ public DeviceElementVerify shouldNotBeDisplayed () { * @return instance */ public DeviceElementVerify textShouldBeEqualTo (final String expected) { - final String msg = "Verifying if element text is equal to [%s]..."; - log.info (String.format (msg, expected)); + log.info ("Verifying if element text is equal to [{}]...", expected); assertThat (this.actions.text ()).isEqualTo (expected); return this; } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSActivity.java b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSActivity.java index 674b649..287b604 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSActivity.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSActivity.java @@ -58,13 +58,14 @@ public IOSDeviceActions onDevice () { /* * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceActivity#onElement(java.lang.String) + * @see + * com.github.wasiqb.coteafs.appium.device.DeviceActivity#onElement(java.lang. + * String) */ @Override public IOSDeviceElementActions onElement (final String name) { checkBattery (); - final String msg = "Preparing to perform actions on iOS device element [%s]..."; - log.trace (String.format (msg, name)); + log.trace ("Preparing to perform actions on iOS device element [{}]...", name); return new IOSDeviceElementActions (this.device, name, getElement (name)); } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceActions.java index 312e3e3..8f59a65 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceActions.java @@ -17,7 +17,6 @@ import static com.github.wasiqb.coteafs.appium.constants.ErrorMessage.SERVER_STOPPED; import static com.github.wasiqb.coteafs.appium.utils.ErrorUtils.fail; -import static java.lang.String.format; import java.util.HashMap; import java.util.Map; @@ -71,7 +70,7 @@ public String clipboard () { * @return clipboard */ public String clipboard (final ClipboardType type) { - log.info (format ("Getting clipboard for [%s]...", type)); + log.info ("Getting clipboard for [{}]...", type); return this.driver.getClipboard (type.getType ()); } @@ -86,8 +85,7 @@ public String handleAlert () { final Alert alert = this.wait.until (d -> d.switchTo () .alert ()); final String description = alert.getText (); - final String msg = "Alert Text: [%s]"; - log.info (format (msg, description)); + log.info ("Alert Text: [{}]", description); alert.accept (); return description; } @@ -108,8 +106,7 @@ public String handleAlert () { * @param keyName */ public void hideKeyboard (final String strategy, final String keyName) { - final String msg = "Hiding keyboard on device using %s strategy for key %s..."; - log.info (format (msg, strategy, keyName)); + log.info ("Hiding keyboard on device using %s strategy for key {}...", strategy, keyName); try { if (this.driver.isKeyboardShown ()) { this.driver.hideKeyboard (strategy, keyName); @@ -126,7 +123,7 @@ public void hideKeyboard (final String strategy, final String keyName) { */ @Override public void pinch (final int distance) { - log.info (format ("Pinching on device screen by [%d] distance...", distance)); + log.info ("Pinching on device screen by [{}] distance...", distance); final Map param = new HashMap <> (); param.put ("scale", 0.5); param.put ("velocity", distance); @@ -153,7 +150,7 @@ public void shake () { * @param direction */ public void swipe (final SwipeDirection direction) { - log.info (format ("Swiping [%s] on device screen...", direction)); + log.info ("Swiping [{}] on device screen...", direction); final Map param = new HashMap <> (); param.put ("direction", direction.name () .toLowerCase ()); @@ -166,7 +163,7 @@ public void swipe (final SwipeDirection direction) { */ @Override public void zoom (final int distance) { - log.info (format ("Zooming in device screen by [%d] distance...", distance)); + log.info ("Zooming in device screen by [{}] distance...", distance); final Map param = new HashMap <> (); param.put ("scale", 1.5); param.put ("velocity", distance); diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceElementActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceElementActions.java index f7fd534..a848a7a 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceElementActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDeviceElementActions.java @@ -15,8 +15,6 @@ */ package com.github.wasiqb.coteafs.appium.ios; -import static java.lang.String.format; - import java.util.HashMap; import java.util.Map; @@ -54,12 +52,12 @@ public IOSDeviceElementActions (final IOSDevice device, final String name, /* * (non-Javadoc) * @see - * com.github.wasiqb.coteafs.appium.device.DeviceElementActions#dragDrop(io.appium.java_client. - * MobileElement) + * com.github.wasiqb.coteafs.appium.device.DeviceElementActions#dragDrop(io. + * appium.java_client. MobileElement) */ @Override public void dragDrop (final MobileElement dropElement) { - log.info (format ("Performing drag on element [%s]...", this.name)); + log.info ("Performing drag on element [{}]...", this.name); final Point fromCenter = this.element.getCenter (); final Point fromLocation = this.element.getLocation (); final Point toCenter = dropElement.getCenter (); @@ -79,7 +77,7 @@ public void dragDrop (final MobileElement dropElement) { */ @Override public void longPress () { - log.info (format ("Long pressing on element [%s]...", this.name)); + log.info ("Long pressing on element [{}]...", this.name); final Map param = prepareParam (); param.put ("duration", 1.0); @@ -92,7 +90,7 @@ public void longPress () { */ @Override public void pinch (final int distance) { - log.info (format ("Pinching on element [%s]...", this.name)); + log.info ("Pinching on element [{}]...", this.name); final Map param = prepareParam (); param.put ("scale", 0.5); @@ -106,7 +104,7 @@ public void pinch (final int distance) { * @param direction */ public void swipe (final SwipeDirection direction) { - log.info (format ("Swiping on element [%s]...", this.name)); + log.info ("Swiping on element [{}]...", this.name); final Map param = prepareParam (); param.put ("direction", direction.name () @@ -120,7 +118,7 @@ public void swipe (final SwipeDirection direction) { */ @Override public void tap () { - log.info (format ("Tapping on element [%s]...", this.name)); + log.info ("Tapping on element [{}]...", this.name); final Point center = this.element.getCenter (); final Point location = this.element.getLocation (); @@ -132,7 +130,8 @@ public void tap () { /* * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceElementActions#verifyThat() + * @see + * com.github.wasiqb.coteafs.appium.device.DeviceElementActions#verifyThat() */ @Override public IOSElementVerify verifyThat () { @@ -145,7 +144,7 @@ public IOSElementVerify verifyThat () { */ @Override public void zoom (final int distance) { - log.info (format ("Zooming on element [%s]...", this.name)); + log.info ("Zooming on element [{}]...", this.name); final Map param = prepareParam (); param.put ("scale", 1.5); diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/utils/BatteryHealth.java b/src/main/java/com/github/wasiqb/coteafs/appium/utils/BatteryHealth.java index 3082628..14ab73c 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/utils/BatteryHealth.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/utils/BatteryHealth.java @@ -16,7 +16,6 @@ package com.github.wasiqb.coteafs.appium.utils; import static com.github.wasiqb.coteafs.appium.utils.ErrorUtils.fail; -import static java.text.MessageFormat.format; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -37,8 +36,8 @@ public final class BatteryHealth { * @param level */ public static void check (final String state, final double level) { - log.trace (format ("Current Battery status is [{0}] with charge level as [{1}%]...", state, - level * 100)); + log.trace ("Current Battery status is [{}] with charge level as [{}%]...", state, + level * 100); if (!state.equals ("CHARGING") && !state.equals ("FULL") && level < 0.2) { fail (NotEnoughBatteryChargeError.class, "Battery does not have enough charging, to continue, put your device on USB..."); diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/utils/CapabilityUtils.java b/src/main/java/com/github/wasiqb/coteafs/appium/utils/CapabilityUtils.java index 3c1d19b..9d8f7e6 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/utils/CapabilityUtils.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/utils/CapabilityUtils.java @@ -39,7 +39,8 @@ public final class CapabilityUtils { * @param value * @param capabilities */ - public static void setCapability (final String key, final T value, final DesiredCapabilities capabilities) { + public static void setCapability (final String key, final T value, + final DesiredCapabilities capabilities) { setCapability (key, value, capabilities, false); } @@ -51,17 +52,14 @@ public static void setCapability (final String key, final T value, final Des * @param capabilities * @param mandatory */ - public static void setCapability (final String key, final T value, final DesiredCapabilities capabilities, - final boolean mandatory) { + public static void setCapability (final String key, final T value, + final DesiredCapabilities capabilities, final boolean mandatory) { if (mandatory) { DeviceChecker.checkCapabilitiesParams (key, value); } if (value != null) { - if (value instanceof Integer && (Integer) value == 0) { - return; - } - String msg = "Setting capability [key: %s, value: %s]..."; - log.trace (String.format (msg, key, value)); + if (value instanceof Integer && (Integer) value == 0) return; + log.trace ("Setting capability [key: {}, value: {}]...", key, value); capabilities.setCapability (key, value); } } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/utils/ErrorUtils.java b/src/main/java/com/github/wasiqb/coteafs/appium/utils/ErrorUtils.java index 68e19fb..71bd65a 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/utils/ErrorUtils.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/utils/ErrorUtils.java @@ -15,8 +15,6 @@ */ package com.github.wasiqb.coteafs.appium.utils; -import static java.lang.String.format; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -48,10 +46,11 @@ public static void fail (final Class error, final S * @param ex */ public static void fail (final Class error, final String message, - final Throwable ex) { + final Throwable ex) { try { ErrorUtil.fail (error, message, ex); - } catch (final CoteafsError err) { + } + catch (final CoteafsError err) { logError (err, message); throw err; } @@ -66,7 +65,7 @@ private static void logError (final Throwable error, final String message) { log.error (error); final StackTraceElement [] traces = error.getStackTrace (); for (final StackTraceElement s : traces) { - log.error (format ("\tat %s", s)); + log.error ("\tat {}", s); } final Throwable root = error.getCause (); if (root != null) { diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/utils/ScreenRecorder.java b/src/main/java/com/github/wasiqb/coteafs/appium/utils/ScreenRecorder.java index 1a18b61..e1d94e5 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/utils/ScreenRecorder.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/utils/ScreenRecorder.java @@ -52,7 +52,7 @@ public static void saveRecording (final String content, final RecordSetting sett final String timeStamp = date.format (Calendar.getInstance () .getTime ()); final String fileName = format ("%s/%s-%s.%s", path, prefix, timeStamp, "mp4"); - LOG.info (format ("Saving video recording to [%s] path...", fileName)); + LOG.info ("Saving video recording to [{}] path...", fileName); writeByteArrayToFile (new File (fileName), decode); } catch (final IOException e) {