Skip to content

Commit

Permalink
Common Android and IOS platform
Browse files Browse the repository at this point in the history
  • Loading branch information
alizelzele committed Dec 12, 2016
1 parent 5682f9e commit c5a8597
Show file tree
Hide file tree
Showing 122 changed files with 934 additions and 2,764 deletions.
28 changes: 22 additions & 6 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,6 +45,8 @@
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.
*/
Expand Down Expand Up @@ -112,7 +115,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 @@ -195,17 +211,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 @@ -27,16 +27,12 @@
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;

/**
* <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 +46,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 +63,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 +71,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 +158,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 +166,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 +177,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 +188,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 +199,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 +210,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 );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.paypal.selion.platform.grid;

import com.paypal.selion.platform.mobile.elements.AbstractMobileElement;
import io.appium.java_client.ios.IOSDriver;

import java.net.URL;
Expand All @@ -28,15 +29,15 @@
import com.paypal.selion.logger.SeLionLogger;
import com.paypal.selion.platform.mobile.ios.GestureOptions;
import com.paypal.selion.platform.mobile.ios.SeLionIOSBridgeDriver;
import com.paypal.selion.platform.mobile.ios.UIAElement;
import com.paypal.test.utilities.logging.SimpleLogger;
import io.appium.java_client.TouchAction;
import org.openqa.selenium.Dimension;

/**
* <code>SeLionAppiumIOSDriver</code> provides facility to add custom {@link CommandExecutor} to {@link IOSDriver}. This
* class also implements the {@link SeLionIOSBridgeDriver} interface to expose methods for {@link UIAElement} and its
* subclasses.
* <code>SeLionAppiumIOSDriver</code> provides facility to add custom
* {@link CommandExecutor} to {@link IOSDriver}. This class also implements the
* {@link SeLionIOSBridgeDriver} interface to expose methods for
* {@link AbstractMobileElement} and its subclasses.
*/
public class SeLionAppiumIOSDriver extends IOSDriver<WebElement> implements SeLionIOSBridgeDriver {

Expand Down Expand Up @@ -104,7 +105,6 @@ public void tap(WebElement webElement) {
}

@Deprecated
@Override
public void tapWithOptions(WebElement webElement, EnumMap<GestureOptions, String> gestureOptions) {
logger.entering(webElement, gestureOptions);
String s = gestureOptions.get(GestureOptions.TOUCH_COUNT);
Expand Down Expand Up @@ -160,4 +160,9 @@ public String getValue(WebElement webElement) {
logger.exiting(value);
return value;
}
}

@Override
public void swipe(int startx, int starty, int endx, int endy, int duration) {
doSwipe(startx, starty, endx, endy, duration);
}
}

0 comments on commit c5a8597

Please sign in to comment.