diff --git a/pom.xml b/pom.xml index a17227b..a25bad0 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ - 5.0.4 + 6.1.0 3.14.0 1.6.0 1.5.0 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 3ec1fb3..4628e9e 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 @@ -22,12 +22,14 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidTouchAction; /** * @author wasiq.bhamla * @since 26-Apr-2017 6:19:46 PM */ -public abstract class AndroidActivity extends DeviceActivity , AndroidDevice> { +public abstract class AndroidActivity + extends DeviceActivity , AndroidDevice, AndroidTouchAction> { private static final Logger log; static { @@ -40,7 +42,7 @@ public abstract class AndroidActivity extends DeviceActivity , AndroidDevice> { +public abstract class AndroidActivityActions extends + DeviceActivityActions , AndroidDevice, AndroidTouchAction> { /** * @author wasiq.bhamla * @since Oct 23, 2017 11:05:14 PM diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDevice.java b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDevice.java index 24c11ed..d72d7ac 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDevice.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDevice.java @@ -20,12 +20,13 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidTouchAction; /** * @author wasiq.bhamla * @since 13-Apr-2017 5:32:01 PM */ -public class AndroidDevice extends Device > { +public class AndroidDevice extends Device , AndroidTouchAction> { /** * @author wasiq.bhamla * @since 13-Apr-2017 9:12:47 PM 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 26d6aff..9d44c09 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 @@ -34,13 +34,16 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; -import io.appium.java_client.android.AndroidKeyCode; +import io.appium.java_client.android.AndroidTouchAction; +import io.appium.java_client.android.nativekey.AndroidKey; +import io.appium.java_client.android.nativekey.KeyEvent; /** * @author wasiq.bhamla * @since 26-Apr-2017 9:05:27 PM */ -public class AndroidDeviceActions extends DeviceActions , AndroidDevice> { +public class AndroidDeviceActions + extends DeviceActions , AndroidDevice, AndroidTouchAction> { private static final Logger log; static { @@ -53,7 +56,7 @@ public class AndroidDeviceActions extends DeviceActions ::currentActivity); + return getValue ("Getting current activity name...", + AndroidDriver ::currentActivity); } /** @@ -76,13 +80,12 @@ public String handleAlert () { try { final AlertActivity perm = new AlertActivity (this.device); final String description = perm.onElement ("Message") - .text (); + .text (); log.trace (String.format (msg, description)); perm.onElement ("OK") - .tap (); + .tap (); return description; - } - catch (final TimeoutException e) { + } catch (final TimeoutException e) { log.warn ("Expected Alert not displayed..."); log.warn (e.getMessage ()); } @@ -102,13 +105,12 @@ public String handlePermissionAlert (final String buttonText) { try { final PermissionActivity perm = new PermissionActivity (this.device); final String description = perm.onElement ("Message") - .text (); + .text (); log.trace (String.format (msg, description)); perm.onElement (buttonText) - .tap (); + .tap (); return description; - } - catch (final TimeoutException e) { + } catch (final TimeoutException e) { log.warn ("Expected Alert not displayed..."); log.warn (e.getMessage ()); } @@ -122,7 +124,8 @@ public String handlePermissionAlert (final String buttonText) { * @return isLocked */ public boolean isLocked () { - return getValue ("Checking if device is locked...", AndroidDriver ::isLocked); + return getValue ("Checking if device is locked...", + AndroidDriver ::isDeviceLocked); } /** @@ -138,7 +141,8 @@ public void lock () { * @since Oct 21, 2017 8:27:50 PM */ public void pressBack () { - perform ("Pressing Back button on Android device...", d -> d.pressKeyCode (AndroidKeyCode.BACK)); + perform ("Pressing Back button on Android device...", + d -> d.pressKey (new KeyEvent (AndroidKey.BACK))); } /** @@ -146,7 +150,8 @@ public void pressBack () { * @since Mar 5, 2018 10:50:09 PM */ public void pressEnter () { - perform ("Pressing Enter button on Android device...", d -> d.pressKeyCode (AndroidKeyCode.ENTER)); + perform ("Pressing Enter button on Android device...", + d -> d.pressKey (new KeyEvent (AndroidKey.ENTER))); } /** @@ -157,25 +162,23 @@ public void unlock () { perform ("Unlocking the Android device...", AndroidDriver ::unlockDevice); } - private T getValue (final String message, final Function , T> action, - final Object... args) { + private T getValue (final String message, + final Function , T> action, final Object... args) { log.info (format (message, args)); try { return action.apply (this.driver); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } return null; } - private void perform (final String message, final Consumer > action, - final Object... args) { + private void perform (final String message, + final Consumer > action, final Object... args) { log.info (format (message, args)); try { action.accept (this.driver); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceElementActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceElementActions.java index e3ecd41..0b74e40 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceElementActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/android/AndroidDeviceElementActions.java @@ -19,12 +19,14 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidTouchAction; /** * @author wasiq.bhamla * @since 02-May-2017 6:31:57 PM */ -public class AndroidDeviceElementActions extends DeviceElementActions , AndroidDevice> { +public class AndroidDeviceElementActions extends + DeviceElementActions , AndroidDevice, AndroidTouchAction> { /** * @author wasiq.bhamla * @since 02-May-2017 6:32:14 PM @@ -32,8 +34,9 @@ public class AndroidDeviceElementActions extends DeviceElementActions , AndroidDevice> { +public class AndroidElementVerify extends + DeviceElementVerify , AndroidDevice, AndroidTouchAction> { /** * @author wasiq.bhamla * @since 20-May-2017 12:26:38 PM 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 2e3e9b7..6d031f1 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 @@ -51,18 +51,18 @@ import static io.appium.java_client.remote.IOSMobileCapabilityType.XCODE_SIGNING_ID; import static io.appium.java_client.remote.MobileCapabilityType.APP; import static io.appium.java_client.remote.MobileCapabilityType.AUTOMATION_NAME; -import static io.appium.java_client.remote.MobileCapabilityType.BROWSER_NAME; import static io.appium.java_client.remote.MobileCapabilityType.CLEAR_SYSTEM_FILES; import static io.appium.java_client.remote.MobileCapabilityType.DEVICE_NAME; import static io.appium.java_client.remote.MobileCapabilityType.EVENT_TIMINGS; import static io.appium.java_client.remote.MobileCapabilityType.FULL_RESET; import static io.appium.java_client.remote.MobileCapabilityType.NEW_COMMAND_TIMEOUT; import static io.appium.java_client.remote.MobileCapabilityType.NO_RESET; -import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_VERSION; import static io.appium.java_client.remote.MobileCapabilityType.UDID; import static java.lang.System.getProperty; import static java.util.concurrent.TimeUnit.SECONDS; +import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME; +import static org.openqa.selenium.remote.CapabilityType.PLATFORM_NAME; import java.io.File; import java.lang.reflect.Constructor; @@ -97,13 +97,15 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; +import io.appium.java_client.TouchAction; /** * @author wasiq.bhamla * @param + * @param * @since 12-Apr-2017 9:38:38 PM */ -public class Device > { +public class Device , T extends TouchAction > { private static final Logger log; static { @@ -124,22 +126,19 @@ public class Device > { public Device (final AppiumServer server, final String name) { this.server = server; this.setting = ConfigLoader.settings () - .withKey (COTEAFS_CONFIG_KEY) - .withDefault (COTEAFS_CONFIG_DEFAULT_FILE) - .load (AppiumSetting.class) - .getDevice (name); + .withKey (COTEAFS_CONFIG_KEY) + .withDefault (COTEAFS_CONFIG_DEFAULT_FILE) + .load (AppiumSetting.class) + .getDevice (name); buildCapabilities (); } /** * @author wasiq.bhamla * @since Nov 17, 2017 3:34:33 PM - * @return device actions */ - public DeviceActions > action () { + public void checkServerRunning () { ServerChecker.checkServerRunning (this.server); - log.info ("Preparing to perform actions on device..."); - return new DeviceActions <> (this); } /** @@ -182,8 +181,7 @@ public void stop () { if (this.driver != null) { quitApp (platform); this.driver = null; - } - else { + } else { final String message = "[%s] device driver already stopped..."; log.trace (String.format (message, platform)); } @@ -202,8 +200,7 @@ private void buildCapabilities () { if (this.setting.getAppType () == ApplicationType.WEB) { setCapability (BROWSER_NAME, this.setting.getBrowser (), this.capabilities, true); - } - else { + } else { final String appPath = this.setting.getAppLocation (); if (appPath != null) { String path = "%s/src/test/resources/%s"; @@ -236,10 +233,10 @@ private D init (final URL url, final Capabilities capability) { try { final Constructor ctor = cls.getDeclaredConstructor (argTypes); return ctor.newInstance (url, capability); - } - catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { - fail (DeviceDriverInitializationFailedError.class, "Error occured while initializing device driver.", e); + } catch (NoSuchMethodException | SecurityException | InstantiationException + | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + fail (DeviceDriverInitializationFailedError.class, + "Error occured while initializing device driver.", e); } return null; } @@ -255,12 +252,11 @@ private void quitApp (final PlatformType platform) { try { this.driver.closeApp (); this.driver.quit (); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); - } - catch (final Exception e) { - fail (DeviceDriverNotStoppingError.class, "Error occured while stopping device driver.", e); + } catch (final Exception e) { + fail (DeviceDriverNotStoppingError.class, "Error occured while stopping device driver.", + e); } } @@ -269,30 +265,35 @@ private void setAndroidCapabilities () { if (android != null) { if (this.setting.getDeviceType () == DeviceType.SIMULATOR) { setCapability (AVD, android.getAvd (), this.capabilities, true); - setCapability (AVD_READY_TIMEOUT, SECONDS.toMillis (android.getAvdReadyTimeout ()), this.capabilities); - setCapability (AVD_LAUNCH_TIMEOUT, SECONDS.toMillis (android.getAvdLaunchTimeout ()), + setCapability (AVD_READY_TIMEOUT, SECONDS.toMillis (android.getAvdReadyTimeout ()), this.capabilities); + setCapability (AVD_LAUNCH_TIMEOUT, + SECONDS.toMillis (android.getAvdLaunchTimeout ()), this.capabilities); } if (this.setting.getAppType () != ApplicationType.WEB) { final String packageName = android.getAppPackage (); final String app = this.setting.getAppLocation (); if (packageName == null && app == null) { - fail (DeviceDesiredCapabilitiesNotSetError.class, "Either App or Package name is mandatory..."); + fail (DeviceDesiredCapabilitiesNotSetError.class, + "Either App or Package name is mandatory..."); } setCapability (APP_ACTIVITY, android.getAppActivity (), this.capabilities); setCapability (APP_PACKAGE, android.getAppPackage (), this.capabilities); setCapability (APP_WAIT_ACTIVITY, android.getAppWaitActivity (), this.capabilities); setCapability (APP_WAIT_DURATION, android.getAppWaitTimeout (), this.capabilities); setCapability (APP_WAIT_PACKAGE, android.getAppWaitPackage (), this.capabilities); - setCapability (ANDROID_INSTALL_TIMEOUT, android.getApkInstallTimeout (), this.capabilities); - setCapability (AUTO_GRANT_PERMISSIONS, android.isAutoGrantPermissions (), this.capabilities); - } - else { - setCapability (CHROMEDRIVER_EXECUTABLE, android.getChromeDriverPath (), this.capabilities); + setCapability (ANDROID_INSTALL_TIMEOUT, android.getApkInstallTimeout (), + this.capabilities); + setCapability (AUTO_GRANT_PERMISSIONS, android.isAutoGrantPermissions (), + this.capabilities); + } else { + setCapability (CHROMEDRIVER_EXECUTABLE, android.getChromeDriverPath (), + this.capabilities); } setCapability (SYSTEM_PORT, android.getSystemPort (), this.capabilities); setCapability (ADB_PORT, android.getAdbPort (), this.capabilities); - setCapability (DEVICE_READY_TIMEOUT, android.getDeviceReadyTimeout (), this.capabilities); + setCapability (DEVICE_READY_TIMEOUT, android.getDeviceReadyTimeout (), + this.capabilities); } } @@ -326,15 +327,14 @@ private void setDeviceSpecificCapabilities () { private void setImplicitWait () { try { this.driver.manage () - .timeouts () - .implicitlyWait (this.setting.getPlayback () - .getDefaultWait (), TimeUnit.SECONDS); - } - catch (final NoSuchSessionException e) { + .timeouts () + .implicitlyWait (this.setting.getPlayback () + .getDefaultWait (), TimeUnit.SECONDS); + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); - } - catch (final Exception e) { - fail (DeviceDriverDefaultWaitError.class, "Error occured while setting device driver default wait.", e); + } catch (final Exception e) { + fail (DeviceDriverDefaultWaitError.class, + "Error occured while setting device driver default wait.", e); } } @@ -347,7 +347,8 @@ private void setIOSCapabilities () { setCapability (XCODE_ORG_ID, ios.getTeamId (), this.capabilities, true); setCapability (XCODE_SIGNING_ID, ios.getSigningId (), this.capabilities, true); setCapability (APP_NAME, ios.getAppName (), this.capabilities, true); - setCapability (WDA_CONNECTION_TIMEOUT, ios.getWdaConnectionTimeout (), this.capabilities, true); + setCapability (WDA_CONNECTION_TIMEOUT, ios.getWdaConnectionTimeout (), + this.capabilities, true); setCapability ("bootstrapPath", ios.getBootstrapPath (), this.capabilities); setCapability ("agentPath", ios.getAgentPath (), this.capabilities); setCapability (UPDATE_WDA_BUNDLEID, ios.getUpdatedWdaBundleId (), this.capabilities); @@ -355,7 +356,8 @@ private void setIOSCapabilities () { setCapability (USE_PREBUILT_WDA, ios.isUsePrebuiltWda (), this.capabilities); setCapability (SHOW_XCODE_LOG, ios.isShowXcodeLog (), this.capabilities); setCapability (WDA_STARTUP_RETRIES, ios.getWdaStartupRetries (), this.capabilities); - setCapability (WDA_STARTUP_RETRY_INTERVAL, ios.getWdaStartupRetryInterval (), this.capabilities); + setCapability (WDA_STARTUP_RETRY_INTERVAL, ios.getWdaStartupRetryInterval (), + this.capabilities); setCapability (AUTO_ACCEPT_ALERTS, ios.isAutoAcceptAlerts (), this.capabilities); setCapability (AUTO_DISMISS_ALERTS, ios.isAutoDismissAlerts (), this.capabilities); setCapability (WDA_LOCAL_PORT, ios.getWdaLocalPort (), this.capabilities); @@ -368,8 +370,7 @@ private void startDriver (final PlatformType platform) { log.trace (String.format (msg, platform)); try { this.driver = init (this.server.getServiceUrl (), this.capabilities); - } - catch (final Exception e) { + } catch (final Exception e) { fail (DeviceDriverNotStartingError.class, "Error occured starting device driver", e); } } 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 d1a7dcc..81ea4dc 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 @@ -44,9 +44,10 @@ * @author wasiq.bhamla * @param * @param + * @param * @since 26-Apr-2017 8:39:17 PM */ -public class DeviceActions , E extends Device > { +public class DeviceActions , E extends Device , T extends TouchAction > { private static final Logger log; static { @@ -62,8 +63,7 @@ public class DeviceActions , E extends De private static void copyFile (final File source, final String destination) { try { FileUtils.copyFile (source, new File (destination)); - } - catch (final IOException e) { + } catch (final IOException e) { log.error ("Error occurred while capturing screensshot..."); log.catching (e); } @@ -72,20 +72,21 @@ private static void copyFile (final File source, final String destination) { protected final E device; protected final D driver; protected final WebDriverWait wait; - private final MultiTouchAction multiTouch; + private final T actions; private final PlaybackSetting setting; /** * @author wasiq.bhamla * @param device + * @param actions * @since 26-Apr-2017 8:39:17 PM */ - public DeviceActions (final E device) { + public DeviceActions (final E device, final T actions) { this.device = device; + this.actions = actions; this.driver = this.device.getDriver (); this.setting = device.setting.getPlayback (); this.wait = new WebDriverWait (this.driver, this.setting.getWaitForElementUntil ()); - this.multiTouch = new MultiTouchAction (this.driver); } /** @@ -97,7 +98,7 @@ public void captureScreenshot () { final String prefix = this.setting.getScreenShotPrefix (); final SimpleDateFormat date = new SimpleDateFormat ("yyyyMMdd-HHmmss"); final String timeStamp = date.format (Calendar.getInstance () - .getTime ()); + .getTime ()); final String fileName = "%s/%s-%s.%s"; captureScreenshot (format (fileName, path, prefix, timeStamp, "jpeg")); } @@ -110,8 +111,7 @@ public void hideKeyboard () { log.info ("Hiding the keyboard..."); try { this.driver.hideKeyboard (); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } } @@ -133,8 +133,8 @@ public void navigateTo (final String url) { */ public void pinch (final int distance) { log.info (format ("Pinching on device screen by [%d]% distance...", distance)); - doubleFingerGesture (SwipeDirection.DOWN, SwipeDirection.UP, SwipeStartPosition.TOP, SwipeStartPosition.BOTTOM, - distance); + doubleFingerGesture (SwipeDirection.DOWN, SwipeDirection.UP, SwipeStartPosition.TOP, + SwipeStartPosition.BOTTOM, distance); } /** @@ -144,9 +144,11 @@ public void pinch (final int distance) { * @param start * @param distance */ - 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)); + 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)); swipeTo (direction, start, distance).perform (); } @@ -172,23 +174,28 @@ private void captureScreenshot (final String path) { try { final File srcFiler = this.driver.getScreenshotAs (OutputType.FILE); copyFile (srcFiler, path); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } } private void doubleFingerGesture (final SwipeDirection finger1, final SwipeDirection finger2, - final SwipeStartPosition start1, final SwipeStartPosition start2, final int distancePercent) { - final TouchAction firstFinger = swipeTo (finger1, start1, distancePercent); - final TouchAction secondFinger = swipeTo (finger2, start2, distancePercent); - this.multiTouch.add (firstFinger) - .add (secondFinger) - .perform (); + final SwipeStartPosition start1, final SwipeStartPosition start2, + final int distancePercent) { + final T firstFinger = swipeTo (finger1, start1, distancePercent); + final T secondFinger = swipeTo (finger2, start2, distancePercent); + final MultiTouchAction multiTouch = new MultiTouchAction (this.driver); + multiTouch.add (firstFinger) + .add (secondFinger) + .perform (); } - private TouchAction swipeTo (final SwipeDirection direction, final SwipeStartPosition start, + private T swipeTo (final SwipeDirection direction, final SwipeStartPosition start, final int distancePercent) { - return SwipeUtils.swipeTo (direction, start, distancePercent, this.setting, this.driver, null); + return SwipeUtils.swipeTo (direction, start, distancePercent, this.setting, + this.driver.manage () + .window () + .getSize (), + null, null, this.actions); } } \ No newline at end of file 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 647d2d4..2357eee 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 @@ -43,14 +43,16 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; +import io.appium.java_client.TouchAction; /** * @author wasiq.bhamla * @param * @param + * @param * @since 26-Apr-2017 4:31:24 PM */ -public abstract class DeviceActivity , E extends Device > { +public abstract class DeviceActivity , E extends Device , T extends TouchAction > { private static final Logger log; static { @@ -60,18 +62,21 @@ public abstract class DeviceActivity , E protected final E device; protected final Map deviceElements; private final PlaybackSetting setting; + private final T touch; private final WebDriverWait wait; /** * @author wasiq.bhamla * @param device + * @param touch * @since 26-Apr-2017 4:32:45 PM */ - public DeviceActivity (final E device) { + public DeviceActivity (final E device, final T touch) { this.device = device; + this.touch = touch; this.deviceElements = new HashMap <> (); this.setting = device.getSetting () - .getPlayback (); + .getPlayback (); this.wait = new WebDriverWait (device.getDriver (), this.setting.getWaitForElementUntil ()); } @@ -93,9 +98,10 @@ public MobileElement getElement (final String name) { * @since 26-Apr-2017 8:41:07 PM * @return device actions */ - @SuppressWarnings ("unchecked") - public DeviceActions onDevice () { - return (DeviceActions ) this.device.action (); + public DeviceActions onDevice () { + this.device.checkServerRunning (); + log.info ("Preparing to perform actions on device..."); + return new DeviceActions <> (this.device, this.touch); } /** @@ -104,11 +110,11 @@ public DeviceActions onDevice () { * @param name * @return element actions */ - public DeviceElementActions onElement (final String name) { + 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)); - return new DeviceElementActions <> (this.device, name, getElement (name)); + return new DeviceElementActions <> (this.device, name, getElement (name), this.touch); } /** @@ -118,12 +124,12 @@ public DeviceElementActions onElement (final String name) { * @param index * @return actions */ - public DeviceElementActions onElement (final String name, final int index) { + 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); - return new DeviceElementActions <> (this.device, name, findElements (element)); + return new DeviceElementActions <> (this.device, name, findElements (element), this.touch); } /** @@ -139,8 +145,8 @@ private void captureScreenshotOnError () { } } - private MobileElement find (final D deviceDriver, final DeviceElement parent, final By locator, final int index, - final WaitStrategy strategy) { + private MobileElement find (final D deviceDriver, final DeviceElement parent, final By locator, + final int index, final WaitStrategy strategy) { try { wait (locator, strategy); List result = null; @@ -149,35 +155,30 @@ private MobileElement find (final D deviceDriver, final DeviceElement parent, fi log.trace (String.format (message, parent.name (), locator, index)); final MobileElement mobileElement = getElement (parent.name ()); result = mobileElement.findElements (locator); - } - else { + } else { final String message = "Finding root element using [%s] at index [%d]..."; log.trace (String.format (message, locator, index)); result = deviceDriver.findElements (locator); } return result.get (index); - } - catch (final TimeoutException e) { + } catch (final TimeoutException e) { captureScreenshotOnError (); final String message = "[%s] locator timed out."; fail (DeviceElementFindTimedOutError.class, String.format (message, locator), e); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); - } - catch (final InvalidSelectorException e) { + } catch (final InvalidSelectorException e) { fail (AppiumSelectorNotImplementedError.class, "Selector not supported", e); - } - catch (final Exception e) { + } catch (final Exception e) { 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); - } - else { + } 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); + fail (DeviceElementNotFoundError.class, + String.format (message, locator, index, parent.name ()), e); } } return null; @@ -192,9 +193,8 @@ private MobileElement findElements (final DeviceElement element) { } private DeviceElement getDeviceElement (final String name) { - if (this.deviceElements.containsKey (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)); return null; diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivityActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivityActions.java index 880848c..b406baa 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivityActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivityActions.java @@ -20,6 +20,7 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; +import io.appium.java_client.TouchAction; /** * @author wasiq.bhamla @@ -27,9 +28,10 @@ * Driver * @param * Device + * @param * @since Oct 23, 2017 10:51:31 PM */ -public abstract class DeviceActivityActions , E extends Device > { +public abstract class DeviceActivityActions , E extends Device , T extends TouchAction > { private final E device; private final Map values; @@ -50,7 +52,8 @@ public DeviceActivityActions (final E device) { * @param value * @return instance */ - public DeviceActivityActions addInputValue (final String element, final Object value) { + public DeviceActivityActions addInputValue (final String element, + final Object value) { this.values.put (element, value); return this; } @@ -71,7 +74,7 @@ public E getDevice () { public abstract void perform (); @SuppressWarnings ("unchecked") - protected T value (final String element) { - return (T) this.values.get (element); + protected X value (final String element) { + return (X) this.values.get (element); } } \ No newline at end of file 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 be366fd..64e91f0 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 @@ -35,14 +35,19 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.MultiTouchAction; import io.appium.java_client.TouchAction; +import io.appium.java_client.touch.LongPressOptions; +import io.appium.java_client.touch.TapOptions; +import io.appium.java_client.touch.WaitOptions; +import io.appium.java_client.touch.offset.ElementOption; /** * @author wasiq.bhamla * @param * @param + * @param * @since 26-Apr-2017 6:39:03 PM */ -public class DeviceElementActions , E extends Device > { +public class DeviceElementActions , E extends Device , T extends TouchAction > { private static final Logger log; static { @@ -54,27 +59,27 @@ public class DeviceElementActions , E ext private final E device; private final D driver; private final MobileElement element; - private final MultiTouchAction multiTouch; private final String name; private final PlaybackSetting setting; - private final TouchAction touch; + private final T touch; /** * @author wasiq.bhamla * @param device * @param name * @param element + * @param touch * @since 26-Apr-2017 6:39:03 PM */ - public DeviceElementActions (final E device, final String name, final MobileElement element) { + public DeviceElementActions (final E device, final String name, final MobileElement element, + final T touch) { this.device = device; this.name = name; this.element = element; this.driver = this.device.getDriver (); - this.touch = new TouchAction (this.driver); - this.multiTouch = new MultiTouchAction (this.driver); + this.touch = touch; this.setting = device.getSetting () - .getPlayback (); + .getPlayback (); DeviceChecker.checkDeviceElementDisplayed (element, name); this.beforeTap = this.setting.getDelayBeforeTap (); this.afterTap = this.setting.getDelayAfterTap (); @@ -105,11 +110,7 @@ public void clear () { */ public void click () { perform ("Clicking on", e -> { - this.touch.waitAction (ofSeconds (this.beforeTap)) - .perform (); e.click (); - this.touch.waitAction (ofSeconds (this.afterTap)) - .perform (); }); } @@ -119,8 +120,9 @@ public void click () { * @param dropElement */ public void dragDrop (final MobileElement dropElement) { - perform ("Performing drag on", e -> SwipeUtils.dragTo (this.driver, this.setting, e, dropElement) - .perform ()); + perform ("Performing drag on", + e -> SwipeUtils.dragTo (this.setting, e, dropElement, this.touch) + .perform ()); } /** @@ -164,13 +166,15 @@ public D getDriver () { /** * @author wasiq.bhamla - * @since 26-Apr-2017 8:54:58 PM + * @since Sep 18, 2018 3:21:26 PM */ public void longPress () { - perform ("Performing long press on", e -> this.touch.waitAction (ofSeconds (this.beforeTap)) - .longPress (e) - .waitAction (ofSeconds (this.afterTap)) - .perform ()); + perform ("Performing long press on", + e -> this.touch.waitAction (WaitOptions.waitOptions (ofSeconds (this.afterTap))) + .longPress (LongPressOptions.longPressOptions () + .withElement (ElementOption.element (e))) + .waitAction (WaitOptions.waitOptions (ofSeconds (this.afterTap))) + .perform ()); } /** @@ -207,12 +211,9 @@ public void submit () { * @param start * @param distance */ - public void swipe (final SwipeDirection direction, final SwipeStartPosition start, final int distance) { - perform ("Swiping on", e -> { - swipeTo (direction, start, distance).perform (); - this.touch.waitAction (ofSeconds (this.setting.getDelayAfterSwipe ())) - .perform (); - }); + public void swipe (final SwipeDirection direction, final SwipeStartPosition start, + final int distance) { + perform ("Swiping on", e -> swipeTo (direction, start, distance).perform ()); } /** @@ -220,10 +221,12 @@ public void swipe (final SwipeDirection direction, final SwipeStartPosition star * @since 12-May-2017 10:08:55 PM */ public void tap () { - perform ("Tapping on", e -> this.touch.waitAction (ofSeconds (this.beforeTap)) - .tap (e) - .waitAction (ofSeconds (this.afterTap)) - .perform ()); + perform ("Tapping on", + e -> this.touch.waitAction (WaitOptions.waitOptions (ofSeconds (this.beforeTap))) + .tap (TapOptions.tapOptions () + .withElement (ElementOption.element (e))) + .waitAction (WaitOptions.waitOptions (ofSeconds (this.afterTap))) + .perform ()); } /** @@ -240,7 +243,7 @@ public String text () { * @since 19-May-2017 10:09:58 PM * @return verify */ - public DeviceElementVerify verifyThat () { + public DeviceElementVerify verifyThat () { return new DeviceElementVerify <> (this); } @@ -268,20 +271,21 @@ private void checkElementEnabled () { } private void doubleFingerGesture (final SwipeDirection finger1, final SwipeDirection finger2, - final SwipeStartPosition start1, final SwipeStartPosition start2, final int distancePercent) { - final TouchAction firstFinger = swipeTo (finger1, start1, distancePercent); - final TouchAction secondFinger = swipeTo (finger2, start2, distancePercent); - this.multiTouch.add (firstFinger) - .add (secondFinger) - .perform (); + final SwipeStartPosition start1, final SwipeStartPosition start2, + final int distancePercent) { + final T firstFinger = swipeTo (finger1, start1, distancePercent); + final T secondFinger = swipeTo (finger2, start2, distancePercent); + final MultiTouchAction multiTouch = new MultiTouchAction (this.driver); + multiTouch.add (firstFinger) + .add (secondFinger) + .perform (); } private R getValue (final String message, final Function func) { log.info (String.format (message, this.name)); try { return func.apply (this.element); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } return null; @@ -292,14 +296,17 @@ private void perform (final String action, final Consumer consum log.info (String.format ("%s element [%s]...", action, this.name)); try { consumer.accept (this.element); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } } - private TouchAction swipeTo (final SwipeDirection direction, final SwipeStartPosition start, + private T swipeTo (final SwipeDirection direction, final SwipeStartPosition start, final int distancePercent) { - return SwipeUtils.swipeTo (direction, start, distancePercent, this.setting, this.driver, this.element); + return SwipeUtils.swipeTo (direction, start, distancePercent, this.setting, + this.driver.manage () + .window () + .getSize (), + this.element.getSize (), this.element.getLocation (), this.touch); } } \ No newline at end of file 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 9ba1dc8..f5bbafd 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 @@ -22,28 +22,30 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; +import io.appium.java_client.TouchAction; /** * @author wasiq.bhamla * @param * @param + * @param * @since 19-May-2017 9:57:58 PM */ -public class DeviceElementVerify , E extends Device > { +public class DeviceElementVerify , E extends Device , T extends TouchAction > { private static final Logger log; static { log = LogManager.getLogger (DeviceElementActions.class); } - private final DeviceElementActions actions; + private final DeviceElementActions actions; /** * @author wasiq.bhamla * @param actions * @since 19-May-2017 9:59:32 PM */ - public DeviceElementVerify (final DeviceElementActions actions) { + public DeviceElementVerify (final DeviceElementActions actions) { this.actions = actions; } @@ -52,7 +54,7 @@ public DeviceElementVerify (final DeviceElementActions actions) { * @since 19-May-2017 10:07:53 PM * @return instance */ - public DeviceElementVerify shouldBeDisabled () { + public DeviceElementVerify shouldBeDisabled () { log.info ("Verifying if element is disabled..."); assertThat (this.actions.enabled ()).isFalse (); return this; @@ -63,7 +65,7 @@ public DeviceElementVerify shouldBeDisabled () { * @since 19-May-2017 10:08:28 PM * @return instance */ - public DeviceElementVerify shouldBeDisplayed () { + public DeviceElementVerify shouldBeDisplayed () { log.info ("Verifying if element is displayed..."); assertThat (this.actions.visible ()).isTrue (); return this; @@ -74,7 +76,7 @@ public DeviceElementVerify shouldBeDisplayed () { * @since 19-May-2017 10:07:22 PM * @return instance */ - public DeviceElementVerify shouldBeEnabled () { + public DeviceElementVerify shouldBeEnabled () { log.info ("Verifying if element is enabled..."); assertThat (this.actions.enabled ()).isTrue (); return this; @@ -85,7 +87,7 @@ public DeviceElementVerify shouldBeEnabled () { * @since 20-May-2017 12:24:26 PM * @return instance */ - public DeviceElementVerify shouldNotBeDisplayed () { + public DeviceElementVerify shouldNotBeDisplayed () { log.info ("Verifying if element is not displayed..."); assertThat (this.actions.visible ()).isFalse (); return this; @@ -97,7 +99,7 @@ public DeviceElementVerify shouldNotBeDisplayed () { * @param expected * @return instance */ - public DeviceElementVerify textShouldBeEqualTo (final String expected) { + public DeviceElementVerify textShouldBeEqualTo (final String expected) { final String msg = "Verifying if element text is equal to [%s]..."; log.info (String.format (msg, expected)); assertThat (this.actions.text ()).isEqualTo (expected); 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 95ee7b5..ee8e5b4 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 @@ -22,12 +22,14 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSTouchAction; /** * @author wasiq.bhamla * @since 26-Apr-2017 7:41:49 PM */ -public abstract class IOSActivity extends DeviceActivity , IOSDevice> { +public abstract class IOSActivity + extends DeviceActivity , IOSDevice, IOSTouchAction> { private static final Logger log; static { @@ -40,7 +42,7 @@ public abstract class IOSActivity extends DeviceActivity , IOSDevice> { +public abstract class IOSActivityActions + extends DeviceActivityActions , IOSDevice, IOSTouchAction> { /** * @author wasiq.bhamla * @since Oct 23, 2017 11:06:33 PM diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDevice.java b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDevice.java index 06f8f27..6ad8959 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDevice.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/ios/IOSDevice.java @@ -20,12 +20,13 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSTouchAction; /** * @author wasiq.bhamla * @since 13-Apr-2017 5:33:35 PM */ -public class IOSDevice extends Device > { +public class IOSDevice extends Device , IOSTouchAction> { /** * @author wasiq.bhamla * @since 13-Apr-2017 9:12:09 PM 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 ab2925a..9f49d77 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 @@ -29,12 +29,14 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSTouchAction; /** * @author wasiq.bhamla * @since 26-Apr-2017 11:34:39 PM */ -public class IOSDeviceActions extends DeviceActions , IOSDevice> { +public class IOSDeviceActions + extends DeviceActions , IOSDevice, IOSTouchAction> { private static final Logger log; static { @@ -47,7 +49,7 @@ public class IOSDeviceActions extends DeviceActions , * @param device */ public IOSDeviceActions (final IOSDevice device) { - super (device); + super (device, new IOSTouchAction (device.getDriver ())); } /** @@ -59,18 +61,16 @@ public String handleAlert () { log.trace ("Handling iOS Alert pop-up..."); try { final Alert alert = this.wait.until (d -> d.switchTo () - .alert ()); + .alert ()); final String description = alert.getText (); final String msg = "Alert Text: [%s]"; log.info (String.format (msg, description)); alert.accept (); return description; - } - catch (final TimeoutException e) { + } catch (final TimeoutException e) { log.warn ("Expecting Alert not displayed..."); log.warn (e.getMessage ()); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } return null; @@ -87,8 +87,7 @@ public void hideKeyboard (final String strategy, final String keyName) { log.info (String.format (msg, strategy, keyName)); try { this.driver.hideKeyboard (strategy, keyName); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } } @@ -101,8 +100,7 @@ public void shake () { log.info ("Shaking the device..."); try { this.driver.shake (); - } - catch (final NoSuchSessionException e) { + } catch (final NoSuchSessionException e) { fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); } } 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 8db0e6f..f2f5608 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 @@ -19,12 +19,14 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; +import io.appium.java_client.ios.IOSTouchAction; /** * @author wasiq.bhamla * @since 02-May-2017 6:37:57 PM */ -public class IOSDeviceElementActions extends DeviceElementActions , IOSDevice> { +public class IOSDeviceElementActions + extends DeviceElementActions , IOSDevice, IOSTouchAction> { /** * @author wasiq.bhamla * @since 02-May-2017 6:38:12 PM @@ -32,8 +34,9 @@ public class IOSDeviceElementActions extends DeviceElementActions , IOSDevice> { +public class IOSElementVerify + extends DeviceElementVerify , IOSDevice, IOSTouchAction> { /** * @author wasiq.bhamla * @since 20-May-2017 12:31:51 PM diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/utils/SwipeUtils.java b/src/main/java/com/github/wasiqb/coteafs/appium/utils/SwipeUtils.java index 653e0f3..7a6de8a 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/utils/SwipeUtils.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/utils/SwipeUtils.java @@ -15,7 +15,7 @@ */ package com.github.wasiqb.coteafs.appium.utils; -import static java.time.Duration.ofSeconds; +import java.time.Duration; import org.openqa.selenium.Dimension; import org.openqa.selenium.Point; @@ -24,10 +24,10 @@ import com.github.wasiqb.coteafs.appium.device.SwipeDirection; import com.github.wasiqb.coteafs.appium.device.SwipeStartPosition; -import io.appium.java_client.AppiumDriver; import io.appium.java_client.MobileElement; -import io.appium.java_client.PerformsTouchActions; import io.appium.java_client.TouchAction; +import io.appium.java_client.touch.WaitOptions; +import io.appium.java_client.touch.offset.PointOption; /** * @author wasiq.bhamla @@ -37,104 +37,93 @@ public final class SwipeUtils { /** * @author wasiq.bhamla * @since Feb 2, 2018 3:25:54 PM - * @param driver * @param setting * @param fromElement * @param toElement + * @param actions * @return touch action */ - public static TouchAction dragTo (final PerformsTouchActions driver, final PlaybackSetting setting, - final MobileElement fromElement, final MobileElement toElement) { - final TouchAction returnAction = new TouchAction (driver); - returnAction.press (fromElement) - .waitAction (ofSeconds (setting.getDelayBeforeSwipe ())) - .moveTo (toElement) - .release () - .waitAction (ofSeconds (setting.getDelayAfterSwipe ())); - return returnAction; + public static > T dragTo (final PlaybackSetting setting, + final MobileElement fromElement, final MobileElement toElement, final T actions) { + final Point source = fromElement.getCenter (); + final Point target = toElement.getCenter (); + return actions.press (PointOption.point (source.getX (), source.getY ())) + .waitAction (WaitOptions + .waitOptions (Duration.ofMillis (setting.getDelayBeforeSwipe ()))) + .moveTo (PointOption.point (target.getX (), target.getY ())) + .release () + .waitAction (WaitOptions + .waitOptions (Duration.ofMillis (setting.getDelayAfterSwipe ()))); } /** * @author wasiq.bhamla - * @since Feb 1, 2018 12:30:56 PM + * @since Sep 18, 2018 8:03:55 PM * @param direction - * @param start + * @param startPosition * @param distancePercent * @param setting - * @param driver - * @param element - * @return touch action + * @param screenSize + * @param elementSize + * @param elementLocation + * @param actions + * @return action */ - public static TouchAction swipeTo (final SwipeDirection direction, final SwipeStartPosition start, - final int distancePercent, final PlaybackSetting setting, final AppiumDriver driver, - final MobileElement element) { - final Dimension screenSize = driver.manage () - .window () - .getSize (); + public static > T swipeTo (final SwipeDirection direction, + final SwipeStartPosition startPosition, final int distancePercent, + final PlaybackSetting setting, final Dimension screenSize, final Dimension elementSize, + final Point elementLocation, final T actions) { final double distance = distancePercent / 100.0; - final int w = screenSize.getWidth (); - final int h = screenSize.getHeight (); - - final Point startPosition = getStartPoint (start, w, h, element); - final int startX = startPosition.getX (); - final int startY = startPosition.getY (); - - int endX = (int) (startX * direction.getX () * distance); - int endY = (int) (startY * direction.getY () * distance); - - final int beforeSwipe = setting.getDelayBeforeSwipe (); - final int afterSwipe = setting.getDelayAfterSwipe (); - final TouchAction returnAction = new TouchAction (driver); - if (element == null) { - returnAction.press (startX, startY) - .waitAction (ofSeconds (beforeSwipe)) - .moveTo (endX, endY) - .release () - .waitAction (ofSeconds (afterSwipe)); + final Point source = getStartPoint (startPosition, screenSize, elementSize, + elementLocation); + int endX = (int) (source.getX () * direction.getX () * distance); + int endY = (int) (source.getY () * direction.getY () * distance); + if (elementSize != null) { + endX = source.getX () + (int) (elementSize.getWidth () * direction.getX () * distance); + endY = source.getY () + (int) (elementSize.getHeight () * direction.getY () * distance); } - else { - final Dimension elementSize = element.getSize (); - endX = startX + (int) (elementSize.getWidth () * direction.getX () * distance); - endY = startY + (int) (elementSize.getHeight () * direction.getY () * distance); - - returnAction.press (element, startX, startY) - .waitAction (ofSeconds (beforeSwipe)) - .moveTo (element, endX, endY) + return actions.press (PointOption.point (source.getX (), source.getY ())) + .waitAction (WaitOptions + .waitOptions (Duration.ofMillis (setting.getDelayBeforeSwipe ()))) + .moveTo (PointOption.point (endX, endY)) + .waitAction ( + WaitOptions.waitOptions (Duration.ofMillis (setting.getDelayAfterSwipe ()))) .release (); - } - - return returnAction; } - private static Point getStartPoint (final SwipeStartPosition start, final int w, final int h, - final MobileElement element) { + private static Point getStartPoint (final SwipeStartPosition start, final Dimension screenSize, + final Dimension elementSize, final Point elementLocation) { int x = 0; int y = 0; - int width = w; - int height = h; + int width = screenSize.getWidth (); + int height = screenSize.getHeight (); Point location = new Point (0, 0); - if (element != null) { - final Dimension size = element.getSize (); - width = size.getWidth (); - height = size.getHeight (); - location = element.getLocation (); + if (elementSize != null) { + width = elementSize.getWidth (); + height = elementSize.getHeight (); + location = elementLocation; } + switch (start) { case BOTTOM: x = width / 2; - y = element != null && height + location.getY () < h ? height : height - 5; + y = elementSize != null && height + location.getY () < screenSize.getHeight () + ? height + : height - 5; break; case CENTER: x = width / 2; y = height / 2; break; case LEFT: - x = element != null && width + location.getX () > 0 ? 0 : 5; + x = elementSize != null && width + location.getX () > 0 ? 0 : 5; y = height / 2; break; case RIGHT: - x = element != null && width + location.getX () < w ? width : width - 5; + x = elementSize != null && width + location.getX () < screenSize.getWidth () + ? width + : width - 5; y = height / 2; break; case TOP: @@ -143,7 +132,7 @@ private static Point getStartPoint (final SwipeStartPosition start, final int w, y = 5; break; } - return new Point (x, y); + return new Point (location.getX () + x, location.getY () + y); } private SwipeUtils () { diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsActivity.java b/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsActivity.java deleted file mode 100644 index 2070945..0000000 --- a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsActivity.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2017, Wasiq Bhamla. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.wasiqb.coteafs.appium.windows; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.github.wasiqb.coteafs.appium.device.DeviceActivity; - -import io.appium.java_client.MobileElement; -import io.appium.java_client.windows.WindowsDriver; - -/** - * @author wasiq.bhamla - * @since Oct 14, 2017 6:30:18 PM - */ -public abstract class WindowsActivity extends DeviceActivity , WindowsDevice> { - private static final Logger log; - - static { - log = LogManager.getLogger (WindowsActivity.class); - } - - /** - * @author wasiq.bhamla - * @since Oct 14, 2017 6:31:42 PM - * @param device - */ - public WindowsActivity (final WindowsDevice device) { - super (device); - } - - /* - * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceActivity#onDevice() - */ - @Override - public WindowsDeviceActions onDevice () { - log.info ("Preparing to perform actions on Windows device..."); - return new WindowsDeviceActions (this.device); - } - - /* - * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceActivity#onElement(java.lang.String) - */ - @Override - public WindowsDeviceElementActions onElement (final String name) { - final String msg = "Preparing to perform actions on Windows device element [%s]..."; - log.info (String.format (msg, name)); - return new WindowsDeviceElementActions (this.device, name, getElement (name)); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsActivityActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsActivityActions.java deleted file mode 100644 index 331be71..0000000 --- a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsActivityActions.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2017, Wasiq Bhamla. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.wasiqb.coteafs.appium.windows; - -import com.github.wasiqb.coteafs.appium.device.DeviceActivityActions; - -import io.appium.java_client.MobileElement; -import io.appium.java_client.windows.WindowsDriver; - -/** - * @author wasiq.bhamla - * @since Oct 23, 2017 11:07:19 PM - */ -public abstract class WindowsActivityActions - extends DeviceActivityActions , WindowsDevice> { - /** - * @author wasiq.bhamla - * @since Oct 23, 2017 11:07:41 PM - * @param device - */ - public WindowsActivityActions (final WindowsDevice device) { - super (device); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDevice.java b/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDevice.java deleted file mode 100644 index a943c23..0000000 --- a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDevice.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2017, Wasiq Bhamla. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.wasiqb.coteafs.appium.windows; - -import com.github.wasiqb.coteafs.appium.device.Device; -import com.github.wasiqb.coteafs.appium.service.AppiumServer; - -import io.appium.java_client.MobileElement; -import io.appium.java_client.windows.WindowsDriver; - -/** - * @author wasiq.bhamla - * @since Oct 14, 2017 6:28:56 PM - */ -public class WindowsDevice extends Device > { - /** - * @author wasiq.bhamla - * @since Oct 14, 2017 6:29:28 PM - * @param server - * @param name - */ - public WindowsDevice (final AppiumServer server, final String name) { - super (server, name); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDeviceActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDeviceActions.java deleted file mode 100644 index 7b57747..0000000 --- a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDeviceActions.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (c) 2017, Wasiq Bhamla. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.wasiqb.coteafs.appium.windows; - -import static com.github.wasiqb.coteafs.appium.constants.ErrorMessage.SERVER_STOPPED; -import static com.github.wasiqb.coteafs.error.util.ErrorUtil.fail; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.openqa.selenium.NoSuchSessionException; - -import com.github.wasiqb.coteafs.appium.device.DeviceActions; -import com.github.wasiqb.coteafs.appium.error.AppiumServerStoppedError; - -import io.appium.java_client.MobileElement; -import io.appium.java_client.windows.WindowsDriver; - -/** - * @author wasiq.bhamla - * @since Oct 14, 2017 7:28:05 PM - */ -public class WindowsDeviceActions extends DeviceActions , WindowsDevice> { - private static final Logger log; - - static { - log = LogManager.getLogger (WindowsDeviceActions.class); - } - - /** - * @author wasiq.bhamla - * @since Oct 14, 2017 7:28:32 PM - * @param device - */ - public WindowsDeviceActions (final WindowsDevice device) { - super (device); - } - - /* - * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceActions#hideKeyboard() - */ - @Override - public void hideKeyboard () { - log.info ("Hiding keyboard on device..."); - try { - this.driver.hideKeyboard (); - } - catch (final NoSuchSessionException e) { - fail (AppiumServerStoppedError.class, SERVER_STOPPED, e); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDeviceElementActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDeviceElementActions.java deleted file mode 100644 index 1b9d563..0000000 --- a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsDeviceElementActions.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) 2017, Wasiq Bhamla. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.wasiqb.coteafs.appium.windows; - -import com.github.wasiqb.coteafs.appium.device.DeviceElementActions; - -import io.appium.java_client.MobileElement; -import io.appium.java_client.windows.WindowsDriver; - -/** - * @author wasiq.bhamla - * @since Oct 14, 2017 7:22:11 PM - */ -public class WindowsDeviceElementActions extends DeviceElementActions , WindowsDevice> { - /** - * @author wasiq.bhamla - * @since Oct 14, 2017 7:22:46 PM - * @param device - * @param name - * @param element - */ - public WindowsDeviceElementActions (final WindowsDevice device, final String name, final MobileElement element) { - super (device, name, element); - } - - /* - * (non-Javadoc) - * @see com.github.wasiqb.coteafs.appium.device.DeviceElementActions#verifyThat() - */ - @Override - public WindowsElementVerify verifyThat () { - return new WindowsElementVerify (this); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsElementVerify.java b/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsElementVerify.java deleted file mode 100644 index 5d5c114..0000000 --- a/src/main/java/com/github/wasiqb/coteafs/appium/windows/WindowsElementVerify.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2017, Wasiq Bhamla. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.wasiqb.coteafs.appium.windows; - -import com.github.wasiqb.coteafs.appium.device.DeviceElementVerify; - -import io.appium.java_client.MobileElement; -import io.appium.java_client.windows.WindowsDriver; - -/** - * @author wasiq.bhamla - * @since Oct 14, 2017 7:19:28 PM - */ -public class WindowsElementVerify extends DeviceElementVerify , WindowsDevice> { - /** - * @author wasiq.bhamla - * @since Oct 14, 2017 7:20:15 PM - * @param actions - */ - public WindowsElementVerify (final WindowsDeviceElementActions actions) { - super (actions); - } -} \ No newline at end of file diff --git a/src/test/java/com/github/wasiqb/coteafs/appium/android/VodQATest.java b/src/test/java/com/github/wasiqb/coteafs/appium/android/VodQATest.java index 37556be..350093c 100644 --- a/src/test/java/com/github/wasiqb/coteafs/appium/android/VodQATest.java +++ b/src/test/java/com/github/wasiqb/coteafs/appium/android/VodQATest.java @@ -15,9 +15,6 @@ */ package com.github.wasiqb.coteafs.appium.android; -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; import org.testng.Assert; import org.testng.annotations.Test; @@ -30,57 +27,11 @@ import com.github.wasiqb.coteafs.appium.device.SwipeDirection; import com.github.wasiqb.coteafs.appium.device.SwipeStartPosition; -import io.appium.java_client.MobileElement; -import io.appium.java_client.MultiTouchAction; -import io.appium.java_client.TouchAction; -import io.appium.java_client.android.AndroidDriver; - /** * @author wasiq.bhamla * @since Jan 23, 2018 8:14:51 PM */ public class VodQATest extends DefaultTest { - /** - * @author wasiq.bhamla - * @since Feb 2, 2018 9:56:28 PM - */ - @Test (enabled = false) - public void test1 () { - this.main.onElement ("PhotoView") - .click (); - - final AndroidDriver driver = this.androidDevice.getDriver (); - final MobileElement img = driver.findElement (By.className ("android.widget.ImageView")); - - final Point location = img.getLocation (); - final Dimension size = img.getSize (); - final int x1 = location.getX (); - final int y1 = location.getY (); - - System.out.println ("x is " + x1 + "y1 is " + y1); - - final int x = size.getWidth () / 2; - final int y = size.getHeight () / 2; - - img.click (); - - // Zoom - System.out.println ("Now zooming"); - final TouchAction finger1 = new TouchAction (driver); - finger1.press (img, x, y - 10) - .moveTo (img, x, y - 400); - - final TouchAction finger2 = new TouchAction (driver); - finger2.press (img, x, y + 10) - .moveTo (img, x, y + 400); - - final MultiTouchAction action = new MultiTouchAction (driver); - action.add (finger1) - .add (finger2) - .perform (); - - } - /** * @author wasiq.bhamla * @since Feb 2, 2018 2:59:25 PM @@ -88,14 +39,14 @@ public void test1 () { @Test public void testDragDrop () { this.main.onElement ("DragDrop") - .click (); + .click (); final DragDropActivity dd = new DragDropActivity (this.androidDevice); dd.onElement ("DropMe") - .dragDrop (dd.getElement ("DropZone")); + .dragDrop (dd.getElement ("DropZone")); dd.onElement ("Success") - .verifyThat () - .textShouldBeEqualTo ("Circle dropped"); + .verifyThat () + .textShouldBeEqualTo ("Circle dropped"); } /** @@ -105,13 +56,13 @@ public void testDragDrop () { @Test public void testLongPress () { this.main.onElement ("LongPress") - .click (); + .click (); final LongPressActivity lp = new LongPressActivity (this.androidDevice); lp.onElement ("Button") - .longPress (); + .longPress (); final String message = lp.onDevice () - .handleAlert (); + .handleAlert (); Assert.assertEquals (message, "you pressed me hard :P"); } @@ -123,18 +74,18 @@ public void testLongPress () { @Test public void testNativeView () throws InterruptedException { this.main.onElement ("ChainedView") - .click (); + .click (); final ChainedViewActivity chained = new ChainedViewActivity (this.androidDevice); chained.onElement ("Text1") - .verifyThat () - .textShouldBeEqualTo ("Hello World, I'm View one "); + .verifyThat () + .textShouldBeEqualTo ("Hello World, I'm View one "); chained.onElement ("Text2") - .verifyThat () - .textShouldBeEqualTo ("Hello World, I'm View two "); + .verifyThat () + .textShouldBeEqualTo ("Hello World, I'm View two "); chained.onElement ("Text3") - .verifyThat () - .textShouldBeEqualTo ("Hello World, I'm View three "); + .verifyThat () + .textShouldBeEqualTo ("Hello World, I'm View three "); } /** @@ -144,13 +95,13 @@ public void testNativeView () throws InterruptedException { @Test public void testSlider () { this.main.onElement ("Slider") - .click (); + .click (); final SliderActivity slide = new SliderActivity (this.androidDevice); slide.onElement ("Slider") - .swipe (SwipeDirection.RIGHT, SwipeStartPosition.LEFT, 25); + .swipe (SwipeDirection.RIGHT, SwipeStartPosition.LEFT, 75); slide.onElement ("Slider1") - .swipe (SwipeDirection.LEFT, SwipeStartPosition.RIGHT, 25); + .swipe (SwipeDirection.LEFT, SwipeStartPosition.RIGHT, 75); } /** @@ -160,13 +111,13 @@ public void testSlider () { @Test public void testVerticleSwipe () { this.main.onElement ("VerticalSwipe") - .click (); + .click (); final VerticleSwipeActivity vs = new VerticleSwipeActivity (this.androidDevice); vs.onElement ("List") - .swipe (SwipeDirection.UP, SwipeStartPosition.BOTTOM, 25); + .swipe (SwipeDirection.UP, SwipeStartPosition.BOTTOM, 25); vs.onElement ("List") - .swipe (SwipeDirection.DOWN, SwipeStartPosition.TOP, 25); + .swipe (SwipeDirection.DOWN, SwipeStartPosition.TOP, 25); } /** @@ -176,13 +127,13 @@ public void testVerticleSwipe () { @Test public void testZoomPinch () { this.main.onElement ("PhotoView") - .click (); + .click (); final PhotoViewActivity p = new PhotoViewActivity (this.androidDevice); p.onElement ("Img") - .zoom (25); + .zoom (25); p.onElement ("Img") - .pinch (25); + .pinch (25); } } \ No newline at end of file diff --git a/src/test/resources/appium-config.yaml b/src/test/resources/appium-config.yaml index 1e71780..3ca4e0d 100644 --- a/src/test/resources/appium-config.yaml +++ b/src/test/resources/appium-config.yaml @@ -2,6 +2,8 @@ servers: android: ip: 127.0.0.1 port: 4723 + appium_js_path: C:\Users\wasiqb\AppData\Roaming\npm\node_modules\appium\build\lib\main.js + node_path: C:\Program Files\nodejs\node.exe external: true arguments: log_level: DEBUG diff --git a/src/test/resources/apps/android/VodQA.apk b/src/test/resources/apps/android/VodQA.apk index 093607e..2749a4f 100644 Binary files a/src/test/resources/apps/android/VodQA.apk and b/src/test/resources/apps/android/VodQA.apk differ diff --git a/src/test/resources/apps/android/com.vinsol.expensetracker.apk b/src/test/resources/apps/android/com.vinsol.expensetracker.apk deleted file mode 100644 index af784d8..0000000 Binary files a/src/test/resources/apps/android/com.vinsol.expensetracker.apk and /dev/null differ