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

JsonToMobileElementConverter re-design #532

Merged
merged 13 commits into from
Dec 10, 2016
60 changes: 19 additions & 41 deletions src/main/java/io/appium/java_client/AppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.collect.ImmutableMap;

import io.appium.java_client.internal.JsonToMobileElementConverter;
import io.appium.java_client.remote.AppiumCommandExecutor;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
Expand All @@ -39,14 +40,11 @@
import org.openqa.selenium.remote.ErrorHandler;
import org.openqa.selenium.remote.ExecuteMethod;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.html5.RemoteLocationContext;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -80,74 +78,54 @@ public class AppiumDriver<T extends WebElement>
* commands may be specified there.
* @param capabilities take a look
* at {@link org.openqa.selenium.Capabilities}
* @param converterClazz is an instance of a class that extends
* {@link org.openqa.selenium.remote.internal.JsonToWebElementConverter}. It converts
* JSON response to an instance of
* {@link org.openqa.selenium.WebElement}
*/
protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
protected AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
super(executor, capabilities);
this.executeMethod = new AppiumExecutionMethod(this);
locationContext = new RemoteLocationContext(executeMethod);
super.setErrorHandler(errorHandler);
this.remoteAddress = executor.getAddressOfRemoteServer();
try {
Constructor<? extends JsonToWebElementConverter> constructor =
converterClazz.getConstructor(RemoteWebDriver.class);
this.setElementConverter(constructor.newInstance(this));
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException
| InvocationTargetException e) {
throw new RuntimeException(e);
}
this.setElementConverter(new JsonToMobileElementConverter(this, getSessionDetails()));
}

public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress),
desiredCapabilities, converterClazz);
desiredCapabilities);
}

public AppiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory,
Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress,
httpClientFactory), desiredCapabilities, converterClazz);
httpClientFactory), desiredCapabilities);
}

public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(MobileCommand.commandRepository, service),
desiredCapabilities, converterClazz);
desiredCapabilities);
}

public AppiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory,
Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
Capabilities desiredCapabilities) {
this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory),
desiredCapabilities, converterClazz);
desiredCapabilities);
}

public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
this(builder.build(), desiredCapabilities, converterClazz);
public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) {
this(builder.build(), desiredCapabilities);
}

public AppiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory,
Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
this(builder.build(), httpClientFactory, desiredCapabilities, converterClazz);
Capabilities desiredCapabilities) {
this(builder.build(), httpClientFactory, desiredCapabilities);
}

public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory,
desiredCapabilities, converterClazz);
desiredCapabilities);
}

public AppiumDriver(Capabilities desiredCapabilities,
Class<? extends JsonToWebElementConverter> converterClazz) {
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities, converterClazz);
public AppiumDriver(Capabilities desiredCapabilities) {
this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/appium/java_client/AppiumSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package io.appium.java_client;

import io.appium.java_client.android.Setting;

/**
* This enum is deprecated. Was moved to {@link Setting}
* This enum is deprecated. Was moved to
* {@link io.appium.java_client.android.Setting}.
*/
@Deprecated
public enum AppiumSetting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

package io.appium.java_client;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;

import java.util.List;

public interface FindsByAccessibilityId<T extends WebElement> extends FindsByFluentSelector<T> {
/**
* @throws WebDriverException This method is not
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
* applicable with browser/webview UI.
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
*/
default T findElementByAccessibilityId(String using) {
return findElement(MobileSelector.ACCESSIBILITY.toString(), using);
}

/**
* @throws WebDriverException This method is not
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
* applicable with browser/webview UI.
*/
default List<T> findElementsByAccessibilityId(String using) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

package io.appium.java_client;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;

import java.util.List;

public interface FindsByAndroidUIAutomator<T extends WebElement> extends FindsByFluentSelector<T> {

/**
* @throws WebDriverException This method is not
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
* applicable with browser/webview UI.
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
*/
default T findElementByAndroidUIAutomator(String using) {
return findElement(MobileSelector.ANDROID_UI_AUTOMATOR.toString(), using);
}

/**
* @throws WebDriverException This method is not
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
* applicable with browser/webview UI.
*/
default List<T> findElementsByAndroidUIAutomator(String using) {
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/io/appium/java_client/FindsByFluentSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package io.appium.java_client;

import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;

import java.util.List;
Expand All @@ -32,11 +30,11 @@ public interface FindsByFluentSelector<T extends WebElement> {
* @param using is a value of the given selector
* @return the first found element
*
* @throws WebDriverException when current session doesn't support the given selector or when
* value of the selector is not consistent.
* @throws NoSuchElementException when no one element is found
* @throws org.openqa.selenium.WebDriverException when current session doesn't
* support the given selector or when value of the selector is not consistent.
* @throws org.openqa.selenium.NoSuchElementException when no one element is found
*/
T findElement(String by, String using) throws WebDriverException, NoSuchElementException;
T findElement(String by, String using);

/**
* Method performs the searching for a list of elements by some selector defined by string
Expand All @@ -46,8 +44,8 @@ public interface FindsByFluentSelector<T extends WebElement> {
* @param using is a value of the given selector
* @return a list of elements
*
* @throws WebDriverException when current session doesn't support the given selector or when
* value of the selector is not consistent.
* @throws org.openqa.selenium.WebDriverException when current session doesn't support
* the given selector or when value of the selector is not consistent.
*/
List<T> findElements(String by, String using) throws WebDriverException;
List<T> findElements(String by, String using);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

package io.appium.java_client;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;

import java.util.List;

public interface FindsByIosUIAutomation<T extends WebElement> extends FindsByFluentSelector<T> {
/**
* @throws WebDriverException
* @throws {@link org.openqa.selenium.WebDriverException}
* This method is not applicable with browser/webview UI.
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
*/
default T findElementByIosUIAutomation(String using) {
return findElement(MobileSelector.IOS_UI_AUTOMATION.toString(), using);
}

/**
* @throws WebDriverException
* @throws {@link org.openqa.selenium.WebDriverException}
* This method is not applicable with browser/webview UI.
*/
default List<T> findElementsByIosUIAutomation(String using) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public interface FindsByWindowsAutomation<T extends WebElement> extends FindsByF
*
* @param selector a Windows UIAutomation selector
* @return The first element that matches the given selector
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
* applicable with browser/webview UI.
* @throws {@link org.openqa.selenium.NoSuchElementException} when no one element is found
*/
default T findElementByWindowsUIAutomation(String selector) {
return findElement(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector);
Expand All @@ -38,6 +41,8 @@ default T findElementByWindowsUIAutomation(String selector) {
*
* @param selector a Windows UIAutomation selector
* @return a list of elements that match the given selector
* @throws {@link org.openqa.selenium.WebDriverException} This method is not
* applicable with browser/webview UI.
*/
default List<T> findElementsByWindowsUIAutomation(String selector) {
return findElements(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@

package io.appium.java_client;

import static io.appium.java_client.ios.IOSMobileCommandHelper.hideKeyboardCommand;

import static io.appium.java_client.MobileCommand.hideKeyboardCommand;

public interface HidesKeyboardWithKeyName extends HidesKeyboard {

/**
* Hides the keyboard by pressing the button specified by keyName if it is
* showing.
*
* @param keyName The button pressed by the mobile driver to attempt hiding the
* keyboard.
*/
default void hideKeyboard(String keyName) {
CommandExecutionHelper.execute(this, hideKeyboardCommand(keyName));
}

/**
* Hides the keyboard if it is showing. Hiding the keyboard often
* depends on the way an app is implemented, no single strategy always
Expand Down
Loading