Skip to content

Commit

Permalink
creating classes of common mobile element and removing other ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Jiang authored and alizelzele committed Sep 8, 2016
1 parent 1414098 commit e6b66de
Show file tree
Hide file tree
Showing 94 changed files with 1,045 additions and 3,148 deletions.
34 changes: 25 additions & 9 deletions client/src/main/java/com/paypal/selion/platform/grid/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import io.appium.java_client.MobileElement;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
Expand All @@ -44,15 +45,17 @@
import com.paypal.selion.logger.SeLionLogger;
import com.paypal.test.utilities.logging.SimpleLogger;

import io.appium.java_client.AppiumDriver;

/**
* Utility class making it easy to write tests based on Selenium WebDriver in a multi-thread context.
*/
public final class Grid {

private static SimpleLogger logger = SeLionLogger.getLogger();
private static ThreadLocal<RemoteWebDriver> threadLocalWebDriver = new ThreadLocal<RemoteWebDriver>();
private static ThreadLocal<AbstractTestSession> threadTestSession = new ThreadLocal<AbstractTestSession>();
private static ThreadLocal<Exception> threadLocalException = new ThreadLocal<Exception>();
private static ThreadLocal<RemoteWebDriver> threadLocalWebDriver = new ThreadLocal<>();
private static ThreadLocal<AbstractTestSession> threadTestSession = new ThreadLocal<>();
private static ThreadLocal<Exception> threadLocalException = new ThreadLocal<>();

static {
Logger.getLogger("").setLevel(Level.OFF);
Expand Down Expand Up @@ -113,7 +116,20 @@ public static RemoteWebDriver driver() {
}
return rwd;
}


@SuppressWarnings("unchecked")
public static AppiumDriver<MobileElement> mobileDriver(){
return AppiumDriver.class.cast(driver());
}

public static SeLionAppiumAndroidDriver androidDriver(){
return SeLionAppiumAndroidDriver.class.cast(driver());
}

public static SeLionAppiumIOSDriver iOSDriver(){
return SeLionAppiumIOSDriver.class.cast(driver());
}

/**
* @return A {@link AbstractTestSession} object that represents the basic configurations for the currently running
* <code>{@literal @}WebTest</code>/<code>{@literal @}MobileTest</code> annotated method.
Expand Down Expand Up @@ -196,17 +212,17 @@ private static JSONObject extractObject(HttpResponse resp) throws IOException, J
* represents its port. May return <code>null</code> on error.
*/
public static RemoteNodeInformation getRemoteNodeInfo(String hostName, int port, SessionId session) {
logger.entering(new Object[] { hostName, port, session });
RemoteNodeInformation node = null;
String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: ";
logger.entering(hostName, port, session);

// go ahead and abort if this is a known grid where know we won't be able to extract the proxy info via the hub
// api
if (Config.getBoolConfigProperty(ConfigProperty.SELENIUM_USE_SAUCELAB_GRID)) {
logger.exiting(node);
return node;
logger.exiting();
return null;
}

RemoteNodeInformation node = null;
String errorMsg = "Failed to acquire remote webdriver node and port info. Root cause: ";
try {
HttpHost host = new HttpHost(hostName, port);
CloseableHttpClient client = HttpClientBuilder.create().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,22 @@

package com.paypal.selion.platform.grid;

import com.paypal.selion.logger.SeLionLogger;
import com.paypal.test.utilities.logging.SimpleLogger;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

import java.net.URL;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CommandExecutor;

import com.paypal.selion.logger.SeLionLogger;
import com.paypal.selion.platform.mobile.android.SeLionAndroidBridgeDriver;
import com.paypal.selion.platform.mobile.android.UiObject;
import com.paypal.test.utilities.logging.SimpleLogger;
import java.net.URL;

/**
* <code>SeLionAppiumAndroidDriver</code> provides facility to add custom {@link CommandExecutor} to
* {@link AndroidDriver}. This class also implements the {@link SeLionAndroidBridgeDriver} interface to expose
* methods for {@link UiObject} and its subclasses.
* <code>SeLionAppiumAndroidDriver</code> provides facility to add custom {@link CommandExecutor} to {@link AndroidDriver}.
*/
public class SeLionAppiumAndroidDriver extends AndroidDriver<WebElement> implements SeLionAndroidBridgeDriver {
public class SeLionAppiumAndroidDriver extends AndroidDriver<WebElement> {

private static final int OPERATION_DURATION_MILLI_SECONDS = 1000;
private static final SimpleLogger logger = SeLionLogger.getLogger();
Expand All @@ -50,14 +44,12 @@ public SeLionAppiumAndroidDriver(CommandExecutor commandExecutor, Capabilities c
setCommandExecutor(commandExecutor);
}

@Override
public void click(WebElement webElement) {
logger.entering(webElement);
this.tap(1, webElement, 1);
logger.exiting();
}

@Override
public void clickBottomRight(WebElement webElement) {
logger.entering(webElement);
Point currentPoint = webElement.getLocation();
Expand All @@ -69,7 +61,6 @@ public void clickBottomRight(WebElement webElement) {
logger.exiting();
}

@Override
public void clickTopLeft(WebElement webElement) {
logger.entering(webElement);
Point currentPoint = webElement.getLocation();
Expand All @@ -78,94 +69,82 @@ public void clickTopLeft(WebElement webElement) {
logger.exiting();
}

@Override
public String getText(WebElement webElement) {
logger.entering(webElement);
String text = webElement.getAttribute("text");
logger.exiting(text);
return text;
}

@Override
public boolean isCheckable(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("checkable"));
logger.exiting(result);
return result;
}

@Override
public boolean isChecked(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("checked"));
logger.exiting(result);
return result;
}

@Override
public boolean isClickable(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("clickable"));
logger.exiting(result);
return result;
}

@Override
public boolean isEnabled(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("enabled"));
logger.exiting(result);
return result;
}

@Override
public boolean isFocusable(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("focusable"));
logger.exiting(result);
return result;
}

@Override
public boolean isFocused(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("focused"));
logger.exiting(result);
return result;
}

@Override
public boolean isLongClickable(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("longClickable"));
logger.exiting(result);
return result;
}

@Override
public boolean isScrollable(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("scrollable"));
logger.exiting(result);
return result;
}

@Override
public boolean isSelected(WebElement webElement) {
logger.entering(webElement);
boolean result = Boolean.parseBoolean(webElement.getAttribute("selected"));
logger.exiting(result);
return result;
}

@Override
public void longClick(WebElement webElement) {
logger.entering(webElement);
this.tap(1, webElement, OPERATION_DURATION_MILLI_SECONDS);
logger.exiting();
}

@Override
public void longClickBottomRight(WebElement webElement) {
logger.entering(webElement);
Point currentPoint = webElement.getLocation();
Expand All @@ -177,7 +156,6 @@ public void longClickBottomRight(WebElement webElement) {
logger.exiting();
}

@Override
public void longClickTopLeft(WebElement webElement) {
logger.entering(webElement);
Point currentPoint = webElement.getLocation();
Expand All @@ -186,7 +164,6 @@ public void longClickTopLeft(WebElement webElement) {
logger.exiting();
}

@Override
public void swipeLeft(WebElement webElement) {
logger.entering(webElement);
Point currentLocation = webElement.getLocation();
Expand All @@ -198,7 +175,6 @@ public void swipeLeft(WebElement webElement) {
logger.exiting();
}

@Override
public void swipeRight(WebElement webElement) {
logger.entering(webElement);
Point currentLocation = webElement.getLocation();
Expand All @@ -210,7 +186,6 @@ public void swipeRight(WebElement webElement) {
logger.exiting();
}

@Override
public void swipeUp(WebElement webElement) {
logger.entering(webElement);
Point currentLocation = webElement.getLocation();
Expand All @@ -222,7 +197,6 @@ public void swipeUp(WebElement webElement) {
logger.exiting();
}

@Override
public void swipeDown(WebElement webElement) {
logger.entering(webElement);
Point currentLocation = webElement.getLocation();
Expand All @@ -234,24 +208,17 @@ public void swipeDown(WebElement webElement) {
logger.exiting();
}

@Override
public void clearText(WebElement webElement) {
logger.entering(webElement);
webElement.clear();
logger.exiting();
}

@Override
public void setText(WebElement webElement, String text) {
logger.entering(webElement);
//As per the UI Object API doc a text field will be cleared before setting value
webElement.clear();
webElement.sendKeys(text);
logger.exiting();
}

@Override
public void swipe(int startx, int starty, int endx, int endy) {
super.swipe(startx, starty, endx, endy,OPERATION_DURATION_MILLI_SECONDS );
}
}

0 comments on commit e6b66de

Please sign in to comment.