Skip to content

#471 FIX #538

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

Merged
merged 4 commits into from
Dec 17, 2016
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
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ You can get it on [WIKI](https://github.com/appium/java-client/wiki)
- API with default implementation. PR [#470](https://github.com/appium/java-client/pull/470)
- Tools that provide _Page Object_ engines were redesigned. The migration to [repeatable annotations](http://docs.oracle.com/javase/tutorial/java/annotations/repeating.html). Details you can read there: [#497](https://github.com/appium/java-client/pull/497). [Documentation was synced as well](https://github.com/appium/java-client/blob/master/docs/Page-objects.md#also-it-is-possible-to-define-chained-or-any-possible-locators).
- **[MAJOR ENHANCEMENT]**: Migration from Maven to Gradle. Feature request is [#214](https://github.com/appium/java-client/issues/214). Fixes: [#442](https://github.com/appium/java-client/pull/442), [#465](https://github.com/appium/java-client/pull/465).
- **[MAJOR ENHANCEMENT]****[MAJOR REFACTORING]**. Non-abstract **AppiumDriver**:
- **[MAJOR ENHANCEMENT]** **[MAJOR REFACTORING]**. Non-abstract **AppiumDriver**:
- Now the `io.appium.java_client.AppiumDriver` can use an instance of any `io.appium.java_client.MobileBy` subclass for the searching. It should work as expected when current session supports the given selector. It will throw `org.openqa.selenium.WebDriverException` otherwise. [#462](https://github.com/appium/java-client/pull/462)
- The new interface `io.appium.java_client.FindsByFluentSelector` was added. [#462](https://github.com/appium/java-client/pull/462)
- API was redesigned:
Expand Down Expand Up @@ -129,22 +129,29 @@ You can get it on [WIKI](https://github.com/appium/java-client/wiki)
- constructors of 'AppiumDriver' were re-designed.
- constructors of 'AndroidDriver' were re-designed.
- constructors of 'IOSDriver' were re-designed.

_The work is not finished yet._


- **[MAJOR ENHANCEMENT]** Windows automation. Epic [#471](https://github.com/appium/java-client/issues/471)
- The new interface `io.appium.java_client.FindsByWindowsAutomation` was added. [#462](https://github.com/appium/java-client/pull/462). With [@jonstoneman](https://github.com/jonstoneman) 's authorship.
- The new selector strategy `io.appium.java_client.MobileBy.ByWindowsAutomation` was added. [#462](https://github.com/appium/java-client/pull/462). With [@jonstoneman](https://github.com/jonstoneman) 's authorship.
- `io.appium.java_client.windows.WindowsDriver` was designed. [#538](https://github.com/appium/java-client/pull/538)
- `io.appium.java_client.windows.WindowsElement` was designed. [#538](https://github.com/appium/java-client/pull/538)
- `io.appium.java_client.windows.WindowsKeyCode ` was added. [#538](https://github.com/appium/java-client/pull/538)
- Page object tools were updated [#538](https://github.com/appium/java-client/pull/538)
- the `io.appium.java_client.pagefactory.WindowsFindBy` annotation was added.
- `io.appium.java_client.pagefactory.AppiumFieldDecorator` and supporting tools were actualized.

- **[MAJOR ENHANCEMENT]**: The new interface `io.appium.java_client.FindsByIosNSPredicate` was added. [#462](https://github.com/appium/java-client/pull/462). With [@rafael-chavez](https://github.com/rafael-chavez) 's authorship.
It is implemented by `io.appium.java_client.ios.IOSDriver` and `io.appium.java_client.ios.IOSElement`.
- **[MAJOR ENHANCEMENT]**: The new interface `io.appium.java_client.MobileBy.ByIosNsPredicate` was added. [#462](https://github.com/appium/java-client/pull/462). With [@rafael-chavez](https://github.com/rafael-chavez) 's authorship.
- **[MAJOR ENHANCEMENT]**: The new interface `io.appium.java_client.FindsByWindowsAutomation` was added. [#462](https://github.com/appium/java-client/pull/462). With [@jonstoneman](https://github.com/jonstoneman) 's authorship.
- **[MAJOR ENHANCEMENT]**: The new interface `io.appium.java_client.MobileBy.ByWindowsAutomation` was added. [#462](https://github.com/appium/java-client/pull/462). With [@jonstoneman](https://github.com/jonstoneman) 's authorship.
- [ENHANCEMENT] Added the ability to set UiAutomator Congfigurator values. [#410](https://github.com/appium/java-client/pull/410).
[#477](https://github.com/appium/java-client/pull/477).
- **[UPDATE]** to Selenium 3.0. [#489](https://github.com/appium/java-client/pull/489)
- [ENHANCEMENT]. Additional methods which perform device rotation were implemented. [#489](https://github.com/appium/java-client/pull/489). [#439](https://github.com/appium/java-client/pull/439). But it works for iOS in XCUIT mode and for Android in UIAutomator2 mode only. The feature request: [#7131](https://github.com/appium/appium/issues/7131)
- [ENHANCEMENT]. TouchID Implementation (iOS Sim Only). Details: [#509](https://github.com/appium/java-client/pull/509)
- [ENHANCEMENT]. The ability to use port, ip and log file as server arguments was provided. Feature request: [#521](https://github.com/appium/java-client/issues/521). Fixes: [#522](https://github.com/appium/java-client/issues/522), [#524](https://github.com/appium/java-client/issues/524).
- [ENHANCEMENT]. The new interface ```io.appium.java_client.android.HasDeviceDetails``` was added. It is implemented by ```io.appium.java_client.android.AndroidDriver``` by default. [#518](https://github.com/appium/java-client/pull/518)
- [ENHANCEMENT].New touch actions were added. ```io.appium.java_client.ios.IOSTouchAction#doubleTap(WebElement, int, int)``` and ```io.appium.java_client.ios.IOSTouchAction#doubleTap(WebElement)```. [#523](https://github.com/appium/java-client/pull/523), [#444](https://github.com/appium/java-client/pull/444)
- [ENHANCEMENT]. New touch actions were added. ```io.appium.java_client.ios.IOSTouchAction#doubleTap(WebElement, int, int)``` and ```io.appium.java_client.ios.IOSTouchAction#doubleTap(WebElement)```. [#523](https://github.com/appium/java-client/pull/523), [#444](https://github.com/appium/java-client/pull/444)
- [ENHANCEMENT]. All constructors declared by `io.appium.java_client.AppiumDriver` are public now.
- [BUG FIX]: There was the issue when "@WithTimeout" was changing general timeout of the waiting for elements. Bug report: [#467](https://github.com/appium/java-client/issues/467). Fixes: [#468](https://github.com/appium/java-client/issues/468), [#469](https://github.com/appium/java-client/issues/469), [#480](https://github.com/appium/java-client/issues/480). Read: [supported-settings](https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/settings.md#supported-settings)
- Added the server flag `io.appium.java_client.service.local.flags.AndroidServerFlag#REBOOT`. [#476](https://github.com/appium/java-client/pull/476)
- Added `io.appium.java_client.remote.AndroidMobileCapabilityType.APP_WAIT_DURATION ` capability. [#461](https://github.com/appium/java-client/pull/461)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class AppiumDriver<T extends WebElement>
* @param capabilities take a look
* at {@link org.openqa.selenium.Capabilities}
*/
protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
super(executor, capabilities);
this.executeMethod = new AppiumExecutionMethod(this);
locationContext = new RemoteLocationContext(executeMethod);
Expand Down Expand Up @@ -335,7 +335,7 @@ public void zoom(int x, int y) {
@Override public String getContext() {
String contextName =
String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());
if (contextName.equals("null")) {
if ("null".equalsIgnoreCase(contextName)) {
return null;
}
return contextName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class AndroidDriver<T extends WebElement>
* at {@link org.openqa.selenium.Capabilities}
*/
public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) {
super(executor, capabilities);
super(executor, substituteMobilePlatform(capabilities, ANDROID_PLATFORM));
}

/**
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/io/appium/java_client/internal/ElementMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobilePlatform;
import io.appium.java_client.windows.WindowsElement;
import io.appium.java_client.youiengine.YouiEngineElement;
import org.openqa.selenium.remote.RemoteWebElement;

import java.util.Map;
import java.util.Optional;
Expand All @@ -34,7 +36,8 @@ public enum ElementMap {
YOUI_ENGINE(AutomationName.YOUI_ENGINE.toLowerCase(), YouiEngineElement.class),
IOS_XCUI_TEST(AutomationName.IOS_XCUI_TEST.toLowerCase(), IOSElement.class),
ANDROID_UI_AUTOMATOR(MobilePlatform.ANDROID.toLowerCase(), AndroidElement.class),
IOS_UI_AUTOMATION(MobilePlatform.IOS.toLowerCase(), IOSElement.class);
IOS_UI_AUTOMATION(MobilePlatform.IOS.toLowerCase(), IOSElement.class),
WINDOWS(MobilePlatform.WINDOWS, WindowsElement.class);


private static final Map<String, ElementMap> mobileElementMap;
Expand All @@ -50,7 +53,7 @@ public enum ElementMap {


private final String platformOrAutomation;
private final Class<? extends MobileElement> elementClass;
private final Class<? extends RemoteWebElement> elementClass;

private ElementMap(String platformOrAutomation, Class<? extends MobileElement> elementClass) {
this.platformOrAutomation = platformOrAutomation;
Expand All @@ -61,7 +64,7 @@ public String getPlatformOrAutomation() {
return platformOrAutomation;
}

public Class<? extends MobileElement> getElementClass() {
public Class<? extends RemoteWebElement> getElementClass() {
return elementClass;
}

Expand All @@ -70,11 +73,12 @@ public Class<? extends MobileElement> getElementClass() {
* @param automation automation name.
* @return subclass of {@link io.appium.java_client.MobileElement} that convenient to current session details.
*/
public static Class<? extends MobileElement> getElementClass(String platform, String automation) {
ElementMap element = Optional.ofNullable(mobileElementMap.get(automation))
.orElse(mobileElementMap.get(platform));
public static Class<? extends RemoteWebElement> getElementClass(String platform, String automation) {
ElementMap element = Optional.ofNullable(mobileElementMap.get(String
.valueOf(automation).toLowerCase().trim()))
.orElse(mobileElementMap.get(String.valueOf(platform).toLowerCase().trim()));
if (element == null) {
return null;
return RemoteWebElement.class;
}
return element.getElementClass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import io.appium.java_client.MobileElement;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -74,7 +73,7 @@ public Object apply(Object result) {
if (result instanceof Map<?, ?>) {
Map<?, ?> resultAsMap = (Map<?, ?>) result;
if (resultAsMap.containsKey("ELEMENT")) {
MobileElement element = newMobileElement();
RemoteWebElement element = newMobileElement();
element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
element.setFileDetector(driver.getFileDetector());
return element;
Expand All @@ -93,19 +92,13 @@ public Object apply(Object result) {
return result;
}

protected MobileElement newMobileElement() {
Class<? extends MobileElement> target =
protected RemoteWebElement newMobileElement() {
Class<? extends RemoteWebElement> target =
getElementClass(platform, automation);

if (target == null) {
throw new WebDriverException(new ClassNotFoundException("The class of mobile element is "
+ "unknown for current session"));
}

try {
Constructor<? extends MobileElement> constructor = target.getDeclaredConstructor();
Constructor<? extends RemoteWebElement> constructor = target.getDeclaredConstructor();
constructor.setAccessible(true);
MobileElement result = constructor.newInstance();
RemoteWebElement result = constructor.newInstance();
result.setParent(driver);
return result;
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class IOSDriver<T extends WebElement>
* at {@link org.openqa.selenium.Capabilities}
*/
public IOSDriver(HttpCommandExecutor executor, Capabilities capabilities) {
super(executor, capabilities);
super(executor, substituteMobilePlatform(capabilities, IOS_PLATFORM));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@

class AppiumElementLocator implements CacheableLocator {

final boolean shouldCache;
final By by;
final TimeOutDuration timeOutDuration;
private final boolean shouldCache;
private final By by;
private final TimeOutDuration timeOutDuration;
private final TimeOutDuration originalTimeOutDuration;
final WebDriver originalWebDriver;
private final WebDriver originalWebDriver;
private final SearchContext searchContext;
private final WaitingFunction waitingFunction;
private WebElement cachedElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.pagefactory.bys.ContentType;
import io.appium.java_client.pagefactory.locator.CacheableLocator;
import io.appium.java_client.windows.WindowsElement;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -43,7 +44,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -69,6 +69,7 @@ public class AppiumFieldDecorator implements FieldDecorator {
add(TouchableElement.class);
add(AndroidElement.class);
add(IOSElement.class);
add(WindowsElement.class);
}

};
Expand All @@ -91,13 +92,7 @@ private static String extractSessionData(WebDriver driver, String parameter) {
return null;
}

Object parameterValue = HasSessionDetails.class.cast(driver).getSessionDetail(parameter);

if (parameterValue == null) {
return null;
}

return String.valueOf(parameterValue).toLowerCase();
return String.valueOf(HasSessionDetails.class.cast(driver).getSessionDetail(parameter));
}

public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut,
Expand Down Expand Up @@ -147,15 +142,12 @@ protected List<WebElement> proxyForListLocator(ClassLoader ignored,

Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];

boolean result = false;
for (Class<? extends WebElement> webElementClass : availableElementClasses) {
if (!webElementClass.equals(listType)) {
continue;
if (webElementClass.equals(listType)) {
return true;
}
result = true;
break;
}
return result;
return false;
}
};

Expand Down Expand Up @@ -235,14 +227,8 @@ private Object decorateWidget(Field field) {
new WidgetInterceptor(locator, originalDriver, null, map, timeOutDuration));
}

private Class<?> getTypeForProxy() {
Optional<Class<?>> optionalClass =
Optional.ofNullable(getElementClass(platform, automation));
return optionalClass.orElse(RemoteWebElement.class);
}

private WebElement proxyForAnElement(ElementLocator locator) {
ElementInterceptor elementInterceptor = new ElementInterceptor(locator, originalDriver);
return (WebElement) getEnhancedProxy(getTypeForProxy(), elementInterceptor);
return getEnhancedProxy(getElementClass(platform, automation), elementInterceptor);
}
}
Loading