Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes made for issue #38. #77

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,12 +54,16 @@
* @param <T>
* @since 26-Apr-2017 4:31:24 PM
*/
public abstract class DeviceActivity <D extends AppiumDriver <MobileElement>, E extends Device <D, T>, T extends TouchAction <T>> {
public abstract class DeviceActivity <D extends AppiumDriver <MobileElement>,
E extends Device <D, T>, T extends TouchAction <T>> {
private static final Logger log = LogManager.getLogger (DeviceActivity.class);

protected final AutomationType automation;
protected final E device;
protected final Map <String, DeviceElement> 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;

Expand All @@ -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 ());
}

/**
Expand Down Expand Up @@ -136,7 +145,7 @@ public DeviceElementActions <D, E, T> onElement (final String name, final int in
protected abstract DeviceElement prepare ();

private void captureScreenshotOnError () {
if (this.setting.isScreenshotOnError ()) {
if (this.playSetting.isScreenshotOnError ()) {
onDevice ().captureScreenshot ();
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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 ());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,17 +40,18 @@ public static DeviceElement create (final String name) {
return new DeviceElement (name);
}

private By by;
private final List <DeviceElement> childs;
private int index;
private final String name;
private DeviceElement parent;
private WaitStrategy wait;
private final List <DeviceElement> childs;
private int index;
private final Map <PlatformType, Map <AutomationType, By>> 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 <> ();
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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");
Expand All @@ -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 <AutomationType, By> platformLocator = new HashMap <> ();
if (this.locators.containsKey (platform)) {
platformLocator = this.locators.get (platform);
}
platformLocator.put (automation, findBy);
this.locators.put (platform, platformLocator);
return this;
}

Expand Down