Skip to content

Commit

Permalink
common interface for android and ios
Browse files Browse the repository at this point in the history
  1. adding a common interface for both android and ios objects
  2. changing yaml reader and code generator to  support new interface and yaml files.
  3. add more elements to Android elements.
  4. add parameters to config Mobile annotation parameters from suite and command line.
  5. creating new android test app that match with ios test app to be able to test common interface.
  6. adding test suites and test cases for testing common interface and updating old test cases to be able to work with new one.
  • Loading branch information
alizelzele authored and Kia committed May 6, 2016
1 parent 1ac0462 commit 1074284
Show file tree
Hide file tree
Showing 101 changed files with 3,525 additions and 990 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ client/ios-driver.log

# Generated files
gen/
out/

# Gradle files
.gradle/
Expand Down
16 changes: 16 additions & 0 deletions client/src/main/java/com/paypal/selion/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ public enum ConfigProperty {
*/
MOBILE_APP_LOCALE("mobileAppLocale", "en_US", false),

/**
* This parameter represents device.
*/
MOBILE_DEVICE("mobileDevice", "", false),

/**
* This parameter represents the device type.
*/
MOBILE_DEVICE_TYPE("mobileDeviceType", "", false),

/**
* Use this parameter to provide SeLion with a custom element listener that implements
* {@link ElementEventListener}. SeLion will invoke the custom implementation when the relevant events happen.
Expand Down Expand Up @@ -531,6 +541,12 @@ public enum ConfigProperty {
*/
SITE_LOCALE("siteLocale", "US", false),

/**
* mobile platform test suite is designed for (IOS or ANDROID)<br>
* Default is set to <b>UNDEFINED</b>
*/
MOBILE_PLATFORM("mobilePlatform", "UNDEFINED", false),

/**
* Browser specified by user.<br>
* Default is set to <b>firefox</b>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014-15 PayPal |
| Copyright (C) 2014-2016 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand Down Expand Up @@ -149,6 +149,15 @@ public void initializeTestSession(InvokedMethodInformation method) {
appLanguage = getLocalConfigProperty(ConfigProperty.MOBILE_APP_LANGUAGE);
}

if (StringUtils.isNotBlank(getLocalConfigProperty(ConfigProperty.MOBILE_DEVICE))) {
String device = getLocalConfigProperty(ConfigProperty.MOBILE_DEVICE);
setDeviceParameters(device);
}

if (StringUtils.isNotBlank(getLocalConfigProperty(ConfigProperty.MOBILE_DEVICE_TYPE))) {
deviceType = getLocalConfigProperty(ConfigProperty.MOBILE_DEVICE_TYPE);
}

// Override values when supplied via the annotation
if (deviceTestAnnotation != null) {
if (StringUtils.isNotBlank(deviceTestAnnotation.appName())) {
Expand All @@ -162,12 +171,7 @@ public void initializeTestSession(InvokedMethodInformation method) {
this.appLocale = deviceTestAnnotation.locale();
}
if (StringUtils.isNotBlank(deviceTestAnnotation.device())) {
this.device = deviceTestAnnotation.device();
String[] devices = StringUtils.split(this.device, ":");
if (StringUtils.contains(device, ":")) {
this.platformVersion = devices[1];
this.device = devices[0];
}
setDeviceParameters(deviceTestAnnotation.device());
}
if (StringUtils.isNotBlank(deviceTestAnnotation.deviceSerial())) {
this.deviceSerial = deviceTestAnnotation.deviceSerial();
Expand Down Expand Up @@ -227,13 +231,22 @@ public void initializeTestSession(InvokedMethodInformation method) {
logger.exiting();
}

private void setDeviceParameters(String device) {
this.device = device;
String[] devices = StringUtils.split(this.device, ":");
if (StringUtils.contains(this.device, ":")) {
this.platformVersion = devices[1];
this.device = devices[0];
}
}

private String getSelionHubStorageUrl(String selionHubAppPath) {
String COLON = ":";
String SLASH = "/";
String appPathTokens[] = StringUtils.split(selionHubAppPath, ":");
String hostName = Config.getConfigProperty(ConfigProperty.SELENIUM_HOST);
int port = Integer.parseInt(Config.getConfigProperty(ConfigProperty.SELENIUM_PORT));
StringBuffer url = new StringBuffer("http://");
StringBuilder url = new StringBuilder("http://");
url.append(hostName);
url.append(COLON);
url.append(port);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014 PayPal |
| Copyright (C) 2014-2016 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand All @@ -15,6 +15,8 @@

package com.paypal.selion.internal.platform.pageyaml;

import com.paypal.selion.internal.platform.grid.WebDriverPlatform;

import java.util.List;
import java.util.Map;

Expand All @@ -31,6 +33,8 @@ public interface GuiMapReader {

Map<String, String> getGuiMap(String locale);

Map<String,String> getGuiMap(String locale, WebDriverPlatform platform);

Map<String, String> getGuiMapForContainer(String containerKey, String locale);

List<String> getPageValidators();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014-15 PayPal |
| Copyright (C) 2014-2016 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand All @@ -25,6 +25,7 @@
import java.util.logging.Level;

import com.google.common.collect.Lists;
import com.paypal.selion.internal.platform.grid.WebDriverPlatform;
import com.paypal.selion.platform.dataprovider.impl.FileSystemResource;

/**
Expand Down Expand Up @@ -63,7 +64,7 @@ public YamlV1Reader(String fileName) throws IOException {
public Map<String, String> getGuiMap(String locale) {
logger.entering(locale);

Map<String, String> instanceMap = new HashMap<String, String>();
Map<String, String> instanceMap = new HashMap<>();
List<Object> allObj = getAllObjects();

for (Object temp : allObj) {
Expand All @@ -84,6 +85,11 @@ public Map<String, String> getGuiMap(String locale) {
return instanceMap;
}

@Override
public Map<String, String> getGuiMap(String locale, WebDriverPlatform platform) {
return getGuiMap(locale);
}

/**
* The user needs to provide the locale for which data needs to be read. After successfully reading the data from
* the input stream, it is placed in the hash map and returned to the users.
Expand All @@ -98,7 +104,7 @@ public Map<String, String> getGuiMap(String locale) {
public Map<String, String> getGuiMapForContainer(String containerKey, String locale) {
logger.entering(new Object[] { containerKey, locale });

Map<String, String> instanceMap = new HashMap<String, String>();
Map<String, String> instanceMap = new HashMap<>();
List<Object> allObj = getAllObjects();

for (Object temp : allObj) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2014-15 PayPal |
| Copyright (C) 2014-2016 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand All @@ -24,6 +24,7 @@
import java.util.Map.Entry;
import java.util.logging.Level;

import com.paypal.selion.internal.platform.grid.WebDriverPlatform;
import com.paypal.selion.platform.dataprovider.impl.FileSystemResource;
import com.paypal.selion.platform.web.GUIElement;
import com.paypal.selion.platform.web.HtmlContainerElement;
Expand Down Expand Up @@ -63,9 +64,18 @@ public YamlV2Reader(String fileName) throws IOException {
@SuppressWarnings("unchecked")
@Override
public Map<String, String> getGuiMap(String locale) {
logger.entering(locale);
return getGuiMap(locale, WebDriverPlatform.UNDEFINED);
}

Map<String, String> instanceMap = new HashMap<String, String>();
@Override
public Map<String, String> getGuiMap(String locale, WebDriverPlatform platform) {
if (platform.equals(WebDriverPlatform.UNDEFINED)) {
logger.entering(locale);
} else {
logger.entering(platform, locale);
}

Map<String, String> instanceMap = new HashMap<>();
List<Object> allObj = getAllObjects();

for (Object temp : allObj) {
Expand All @@ -75,7 +85,13 @@ public Map<String, String> getGuiMap(String locale) {
+ "the Yaml file. Ignoring the Null document.");
continue;
}
String value = map.get(locale);
String value = map.get(platform + "--" + locale);
if (value == null) {
value = map.get(locale);
}
if (value == null) {
value = map.get(platform + "--" + getDefaultLocale());
}
if (value == null) {
value = map.get(getDefaultLocale());
}
Expand All @@ -100,7 +116,7 @@ public Map<String, String> getGuiMap(String locale) {
public Map<String, String> getGuiMapForContainer(String containerKey, String locale) {
logger.entering(new Object[] { containerKey, locale });

Map<String, String> instanceMap = new HashMap<String, String>();
Map<String, String> instanceMap = new HashMap<>();
List<Object> allObj = getAllObjects();

for (Object temp : allObj) {
Expand Down Expand Up @@ -153,13 +169,13 @@ public void processPage(FileSystemResource resource) throws IOException {
try (InputStream input = resource.getInputStream()) {
Page page = PageFactory.getPage(input);

Map<Object, Object> map = new HashMap<Object, Object>();
Map<Object, Object> map = new HashMap<>();
map.put(KEY, "baseClass");
map.put("Value", page.getBaseClass());

appendObject(map);

map = new HashMap<Object, Object>();
map = new HashMap<>();
map.put(KEY, "pageTitle");
for (Entry<String, String> eachPage : page.getAllPageTitles().entrySet()) {
map.put(eachPage.getKey(), eachPage.getValue());
Expand All @@ -168,17 +184,23 @@ public void processPage(FileSystemResource resource) throws IOException {
appendObject(map);

for (Entry<String, GUIElement> eachElement : page.getElements().entrySet()) {
map = new HashMap<Object, Object>();
map = new HashMap<>();
map.put(KEY, eachElement.getKey());
for (Entry<String, String> eachLocale : eachElement.getValue().getAndroid().entrySet()) {
map.put("ANDROID--" + eachLocale.getKey(), eachLocale.getValue());
}
for (Entry<String, String> eachLocale : eachElement.getValue().getIos().entrySet()) {
map.put("IOS--" + eachLocale.getKey(), eachLocale.getValue());
}
for (Entry<String, String> eachLocale : eachElement.getValue().getLocators().entrySet()) {
map.put(eachLocale.getKey(), eachLocale.getValue());
}

Map<String, HtmlContainerElement> containerElements = eachElement.getValue().getContainerElements();
if (eachElement.getKey().endsWith(CONTAINER) && !containerElements.isEmpty()) {
Map<String, Map<String, String>> containerMap = new HashMap<String, Map<String, String>>();
Map<String, Map<String, String>> containerMap = new HashMap<>();
for (Entry<String, HtmlContainerElement> eachContainerElement : containerElements.entrySet()) {
Map<String, String> localeMap = new HashMap<String, String>(eachContainerElement.getValue()
Map<String, String> localeMap = new HashMap<>(eachContainerElement.getValue()
.getLocators());
containerMap.put(eachContainerElement.getKey(), localeMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,9 @@ public void setText(WebElement webElement, String text) {
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
@@ -1,5 +1,5 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2015 PayPal |
| Copyright (C) 2015-2016 PayPal |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| with the License. |
Expand Down Expand Up @@ -296,22 +296,31 @@ public void swipeDown(WebElement webElement) {
logger.exiting();
}

@Override
public void swipe(int startx, int starty, int endx, int endy) {
Point start = new Point(startx, starty);
Point end = new Point(endx, endy);
logger.entering(start, end);
performSwipeAction(start, end);
logger.exiting();
}

private Point getElementCenter(WebElement webElement) {
Point point = webElement.getLocation();
Dimension dimension = webElement.getSize();
int x = point.getX() + dimension.getWidth() / 2;
int y = point.getY() + dimension.getHeight() / 2;
return new Point(x, y);
}

private Point getElementBottomRight(WebElement webElement) {
Point point = webElement.getLocation();
Dimension dimension = webElement.getSize();
int x = point.getX() + dimension.getWidth() - 1;
int y = point.getY() + dimension.getHeight() - 1;
return new Point(x, y);
}

private void performShortClickAction(Point point) {
try {
new TouchActions(this).down(point.getX(), point.getY()).perform();
Expand All @@ -321,7 +330,7 @@ private void performShortClickAction(Point point) {
throw new WebDriverException("InterruptedException occurred during shortClick", exe);
}
}

private void performLongClickAction(Point point) {
try {
new TouchActions(this).down(point.getX(), point.getY()).perform();
Expand All @@ -331,7 +340,7 @@ private void performLongClickAction(Point point) {
throw new WebDriverException("InterruptedException occurred during longClick", exe);
}
}

private void performSwipeAction(Point start, Point end) {
new TouchActions(this).down(start.getX(), start.getY()).move(end.getX(), end.getY()).up(end.getX(), end.getY()).perform();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.paypal.selion.platform.html.support;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.openqa.selenium.By;
Expand All @@ -37,6 +38,10 @@ public ByOrOperator(List<By> bys) {
this.bys = bys;
}

public ByOrOperator(By... bys) {
this(Arrays.asList(bys));
}

@Override
public WebElement findElement(SearchContext context) {
List<WebElement> elements = findElements(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*-------------------------------------------------------------------------------------------------------------------*\
| Copyright (C) 2016 PayPal |
| |
| 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.paypal.selion.platform.mobile;

import com.paypal.selion.platform.mobile.elements.MobileElement;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* this annotation is used to define the implementation of annotated interface
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Implementor {
Class<? extends MobileElement> ios() default MobileElement.class;
Class<? extends MobileElement> android() default MobileElement.class;
}

0 comments on commit 1074284

Please sign in to comment.