From 1c5c242d12f382064c647b27c56f6da10e0dc281 Mon Sep 17 00:00:00 2001 From: WasiqB Date: Tue, 23 Oct 2018 22:37:14 +0530 Subject: [PATCH] Changes made for issue #38. --- .../coteafs/appium/device/DeviceActivity.java | 26 ++++-- .../coteafs/appium/device/DeviceElement.java | 83 ++++++++++++++++--- 2 files changed, 87 insertions(+), 22 deletions(-) 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 69a59ad..e8850f4 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 @@ -33,7 +33,9 @@ import org.openqa.selenium.support.ui.WebDriverWait; import com.github.wasiqb.coteafs.appium.checker.ServerChecker; +import com.github.wasiqb.coteafs.appium.config.DeviceSetting; import com.github.wasiqb.coteafs.appium.config.PlaybackSetting; +import com.github.wasiqb.coteafs.appium.config.enums.AutomationType; import com.github.wasiqb.coteafs.appium.config.enums.PlatformType; import com.github.wasiqb.coteafs.appium.error.AppiumSelectorNotImplementedError; import com.github.wasiqb.coteafs.appium.error.AppiumServerStoppedError; @@ -52,12 +54,16 @@ * @param * @since 26-Apr-2017 4:31:24 PM */ -public abstract class DeviceActivity , E extends Device , T extends TouchAction > { +public abstract class DeviceActivity , + E extends Device , T extends TouchAction > { private static final Logger log = LogManager.getLogger (DeviceActivity.class); + protected final AutomationType automation; protected final E device; protected final Map deviceElements; - private final PlaybackSetting setting; + protected final PlatformType platform; + private final DeviceSetting deviceSetting; + private final PlaybackSetting playSetting; private final T touch; private final WebDriverWait wait; @@ -71,9 +77,12 @@ public DeviceActivity (final E device, final T touch) { this.device = device; this.touch = touch; this.deviceElements = new HashMap <> (); - this.setting = device.getSetting () - .getPlayback (); - this.wait = new WebDriverWait (device.getDriver (), this.setting.getWaitForElementUntil ()); + this.deviceSetting = device.getSetting (); + this.automation = this.deviceSetting.getAutomationName (); + this.platform = this.deviceSetting.getPlatformType (); + this.playSetting = this.deviceSetting.getPlayback (); + this.wait = new WebDriverWait (device.getDriver (), + this.playSetting.getWaitForElementUntil ()); } /** @@ -136,7 +145,7 @@ public DeviceElementActions onElement (final String name, final int in protected abstract DeviceElement prepare (); private void captureScreenshotOnError () { - if (this.setting.isScreenshotOnError ()) { + if (this.playSetting.isScreenshotOnError ()) { onDevice ().captureScreenshot (); } } @@ -188,7 +197,7 @@ private MobileElement find (final D deviceDriver, final DeviceElement parent, fi private MobileElement findElements (final DeviceElement element) { final DeviceElement parent = element.parent (); - final By locator = element.locator (); + final By locator = element.locator (this.platform, this.automation); final int index = element.index (); final WaitStrategy strategy = element.waitStrategy (); return find (this.device.getDriver (), parent, locator, index, strategy); @@ -204,9 +213,8 @@ private DeviceElement getDeviceElement (final String name) { private void load () { if (this.deviceElements.size () == 0) { - final PlatformType platform = this.device.setting.getPlatformType (); final String msg = "Loading elements on [%s] activity..."; - log.trace (String.format (msg, platform)); + log.trace (String.format (msg, this.platform)); loadElements (prepare ()); } } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElement.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElement.java index 087e061..5d876c0 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElement.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElement.java @@ -16,10 +16,15 @@ package com.github.wasiqb.coteafs.appium.device; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.openqa.selenium.By; +import com.github.wasiqb.coteafs.appium.config.enums.AutomationType; +import com.github.wasiqb.coteafs.appium.config.enums.PlatformType; + /** * @author wasiq.bhamla * @since 25-Apr-2017 7:29:23 PM @@ -35,17 +40,18 @@ public static DeviceElement create (final String name) { return new DeviceElement (name); } - private By by; - private final List childs; - private int index; - private final String name; - private DeviceElement parent; - private WaitStrategy wait; + private final List childs; + private int index; + private final Map > locators; + private final String name; + private DeviceElement parent; + private WaitStrategy wait; private DeviceElement (final String name) { this.childs = new ArrayList <> (); this.name = name; this.wait = WaitStrategy.VISIBLE; + this.locators = new HashMap <> (); } /** @@ -78,12 +84,34 @@ public DeviceElement index (final int location) { } /** - * @author wasiq.bhamla - * @since 25-Apr-2017 7:40:30 PM - * @return locator + * @author wasiqb + * @since Oct 23, 2018 + * @return by locator */ public By locator () { - return this.by; + return locator (AutomationType.APPIUM); + } + + /** + * @author wasiqb + * @since Oct 23, 2018 + * @param automation + * @return by locator + */ + public By locator (final AutomationType automation) { + return locator (PlatformType.ANDROID, automation); + } + + /** + * @author wasiqb + * @since Oct 23, 2018 + * @param platform + * @param automation + * @return by locator + */ + public By locator (final PlatformType platform, final AutomationType automation) { + return this.locators.get (platform) + .get (automation); } /** @@ -132,7 +160,7 @@ public String toString () { final String line4 = "Index: %d"; final String line3 = "Childs: %s"; final StringBuilder sb = new StringBuilder (String.format (line1, this.name)).append ("\n"); - sb.append (String.format (line2, this.by)) + sb.append (String.format (line2, this.locators)) .append ("\n"); sb.append (String.format (line4, this.index)) .append ("\n"); @@ -141,14 +169,43 @@ public String toString () { return sb.toString (); } + /** + * @author wasiqb + * @since Oct 23, 2018 + * @param automation + * @param findBy + * @return instance + */ + public DeviceElement using (final AutomationType automation, final By findBy) { + return using (PlatformType.ANDROID, automation, findBy); + } + + /** + * @author wasiqb + * @since Oct 23, 2018 + * @param findBy + * @return instance + */ + public DeviceElement using (final By findBy) { + return using (AutomationType.APPIUM, findBy); + } + /** * @author wasiq.bhamla + * @param platform + * @param automation * @since 25-Apr-2017 7:36:32 PM * @param findBy * @return instance */ - public DeviceElement using (final By findBy) { - this.by = findBy; + public DeviceElement using (final PlatformType platform, final AutomationType automation, + final By findBy) { + Map platformLocator = new HashMap <> (); + if (this.locators.containsKey (platform)) { + platformLocator = this.locators.get (platform); + } + platformLocator.put (automation, findBy); + this.locators.put (platform, platformLocator); return this; }