diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index bf2d412b9..74e8540cd 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -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; @@ -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; @@ -80,74 +78,54 @@ public class AppiumDriver * 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 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 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 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 converterClazz) { + Capabilities desiredCapabilities) { this(new AppiumCommandExecutor(MobileCommand.commandRepository, remoteAddress, - httpClientFactory), desiredCapabilities, converterClazz); + httpClientFactory), desiredCapabilities); } - public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities, - Class 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 converterClazz) { + Capabilities desiredCapabilities) { this(new AppiumCommandExecutor(MobileCommand.commandRepository, service, httpClientFactory), - desiredCapabilities, converterClazz); + desiredCapabilities); } - public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities, - Class 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 converterClazz) { - this(builder.build(), httpClientFactory, desiredCapabilities, converterClazz); + Capabilities desiredCapabilities) { + this(builder.build(), httpClientFactory, desiredCapabilities); } - public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities, - Class converterClazz) { + public AppiumDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { this(AppiumDriverLocalService.buildDefaultService(), httpClientFactory, - desiredCapabilities, converterClazz); + desiredCapabilities); } - public AppiumDriver(Capabilities desiredCapabilities, - Class converterClazz) { - this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities, converterClazz); + public AppiumDriver(Capabilities desiredCapabilities) { + this(AppiumDriverLocalService.buildDefaultService(), desiredCapabilities); } /** diff --git a/src/main/java/io/appium/java_client/AppiumSetting.java b/src/main/java/io/appium/java_client/AppiumSetting.java index 71f632989..9fcf32f79 100644 --- a/src/main/java/io/appium/java_client/AppiumSetting.java +++ b/src/main/java/io/appium/java_client/AppiumSetting.java @@ -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 { diff --git a/src/main/java/io/appium/java_client/FindsByAccessibilityId.java b/src/main/java/io/appium/java_client/FindsByAccessibilityId.java index 2d9e5e1cc..d575fc1d1 100644 --- a/src/main/java/io/appium/java_client/FindsByAccessibilityId.java +++ b/src/main/java/io/appium/java_client/FindsByAccessibilityId.java @@ -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 extends FindsByFluentSelector { /** - * @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 findElementsByAccessibilityId(String using) { diff --git a/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java b/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java index 1fe84a79d..8e796c23d 100644 --- a/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java +++ b/src/main/java/io/appium/java_client/FindsByAndroidUIAutomator.java @@ -16,7 +16,6 @@ package io.appium.java_client; -import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import java.util.List; @@ -24,15 +23,16 @@ public interface FindsByAndroidUIAutomator extends FindsByFluentSelector { /** - * @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 findElementsByAndroidUIAutomator(String using) { diff --git a/src/main/java/io/appium/java_client/FindsByFluentSelector.java b/src/main/java/io/appium/java_client/FindsByFluentSelector.java index 3c7459389..037bcf427 100644 --- a/src/main/java/io/appium/java_client/FindsByFluentSelector.java +++ b/src/main/java/io/appium/java_client/FindsByFluentSelector.java @@ -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; @@ -32,11 +30,11 @@ public interface FindsByFluentSelector { * @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 @@ -46,8 +44,8 @@ public interface FindsByFluentSelector { * @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 findElements(String by, String using) throws WebDriverException; + List findElements(String by, String using); } diff --git a/src/main/java/io/appium/java_client/FindsByIosUIAutomation.java b/src/main/java/io/appium/java_client/FindsByIosUIAutomation.java index 32cc91246..5fa217e63 100644 --- a/src/main/java/io/appium/java_client/FindsByIosUIAutomation.java +++ b/src/main/java/io/appium/java_client/FindsByIosUIAutomation.java @@ -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 extends FindsByFluentSelector { /** - * @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 findElementsByIosUIAutomation(String using) { diff --git a/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java b/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java index 6cca26d1f..0d4640b05 100644 --- a/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java +++ b/src/main/java/io/appium/java_client/FindsByWindowsAutomation.java @@ -28,6 +28,9 @@ public interface FindsByWindowsAutomation 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); @@ -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 findElementsByWindowsUIAutomation(String selector) { return findElements(MobileSelector.WINDOWS_UI_AUTOMATION.toString(), selector); diff --git a/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java b/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java index 011d4e0f5..d03473bd0 100644 --- a/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java +++ b/src/main/java/io/appium/java_client/HidesKeyboardWithKeyName.java @@ -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 diff --git a/src/main/java/io/appium/java_client/MobileCommand.java b/src/main/java/io/appium/java_client/MobileCommand.java index 57782caaf..7a87eb8a4 100644 --- a/src/main/java/io/appium/java_client/MobileCommand.java +++ b/src/main/java/io/appium/java_client/MobileCommand.java @@ -32,100 +32,138 @@ */ public class MobileCommand { //General - protected static final String RESET = "reset"; - protected static final String GET_STRINGS = "getStrings"; - protected static final String SET_VALUE = "setValue"; - protected static final String PULL_FILE = "pullFile"; - protected static final String PULL_FOLDER = "pullFolder"; - protected static final String HIDE_KEYBOARD = "hideKeyboard"; - protected static final String RUN_APP_IN_BACKGROUND = "runAppInBackground"; - protected static final String PERFORM_TOUCH_ACTION = "performTouchAction"; - protected static final String PERFORM_MULTI_TOUCH = "performMultiTouch"; - protected static final String IS_APP_INSTALLED = "isAppInstalled"; - protected static final String INSTALL_APP = "installApp"; - protected static final String REMOVE_APP = "removeApp"; - protected static final String LAUNCH_APP = "launchApp"; - protected static final String CLOSE_APP = "closeApp"; - protected static final String LOCK = "lock"; - protected static final String COMPLEX_FIND = "complexFind"; - protected static final String GET_DEVICE_TIME = "getDeviceTime"; - protected static final String GET_SESSION = "getSession"; + protected static final String RESET; + protected static final String GET_STRINGS; + protected static final String SET_VALUE; + protected static final String PULL_FILE; + protected static final String PULL_FOLDER; + protected static final String RUN_APP_IN_BACKGROUND; + protected static final String PERFORM_TOUCH_ACTION; + protected static final String PERFORM_MULTI_TOUCH; + protected static final String IS_APP_INSTALLED; + protected static final String INSTALL_APP; + protected static final String REMOVE_APP; + protected static final String LAUNCH_APP; + protected static final String CLOSE_APP; + protected static final String GET_DEVICE_TIME; + protected static final String GET_SESSION; + + protected static final String HIDE_KEYBOARD; + protected static final String LOCK; //iOS - protected static final String SHAKE = "shake"; - protected static final String TOUCH_ID = "touchId"; + protected static final String SHAKE; + protected static final String TOUCH_ID; //Android - protected static final String CURRENT_ACTIVITY = "currentActivity"; - protected static final String END_TEST_COVERAGE = "endTestCoverage"; - protected static final String GET_DISPLAY_DENSITY = "getDisplayDensity"; - protected static final String GET_NETWORK_CONNECTION = "getNetworkConnection"; - protected static final String GET_SYSTEM_BARS = "getSystemBars"; - protected static final String IS_KEYBOARD_SHOWN = "isKeyboardShown"; - protected static final String IS_LOCKED = "isLocked"; - protected static final String LONG_PRESS_KEY_CODE = "longPressKeyCode"; - protected static final String OPEN_NOTIFICATIONS = "openNotifications"; - protected static final String PRESS_KEY_CODE = "pressKeyCode"; - protected static final String PUSH_FILE = "pushFile"; - protected static final String SET_NETWORK_CONNECTION = "setNetworkConnection"; - protected static final String START_ACTIVITY = "startActivity"; - protected static final String TOGGLE_LOCATION_SERVICES = "toggleLocationServices"; - protected static final String UNLOCK = "unlock"; - protected static final String REPLACE_VALUE = "replaceValue"; - protected static final String GET_SETTINGS = "getSettings"; - protected static final String SET_SETTINGS = "setSettings"; - - public static final Map commandRepository = createCommandRepository(); - - private static Map createCommandRepository() { - HashMap result = new HashMap(); - result.put(RESET, postC("/session/:sessionId/appium/app/reset")); - result.put(GET_STRINGS, postC("/session/:sessionId/appium/app/strings")); - result.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value")); - result.put(PULL_FILE, postC("/session/:sessionId/appium/device/pull_file")); - result.put(PULL_FOLDER, postC("/session/:sessionId/appium/device/pull_folder")); - result.put(HIDE_KEYBOARD, postC("/session/:sessionId/appium/device/hide_keyboard")); - result.put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background")); - result.put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform")); - result.put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform")); - result.put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed")); - result.put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app")); - result.put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app")); - result.put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")); - result.put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")); - result.put(LOCK, postC("/session/:sessionId/appium/device/lock")); - result.put(COMPLEX_FIND, postC("/session/:sessionId/appium/app/complex_find")); - result.put(GET_SETTINGS, getC("/session/:sessionId/appium/settings")); - result.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings")); - result.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time")); - result.put(GET_SESSION,getC("/session/:sessionId/")); + protected static final String CURRENT_ACTIVITY; + protected static final String END_TEST_COVERAGE; + protected static final String GET_DISPLAY_DENSITY; + protected static final String GET_NETWORK_CONNECTION; + protected static final String GET_SYSTEM_BARS; + protected static final String IS_KEYBOARD_SHOWN; + protected static final String IS_LOCKED; + protected static final String LONG_PRESS_KEY_CODE; + protected static final String OPEN_NOTIFICATIONS; + protected static final String PRESS_KEY_CODE; + protected static final String PUSH_FILE; + protected static final String SET_NETWORK_CONNECTION; + protected static final String START_ACTIVITY; + protected static final String TOGGLE_LOCATION_SERVICES; + protected static final String UNLOCK; + protected static final String REPLACE_VALUE; + protected static final String GET_SETTINGS; + protected static final String SET_SETTINGS; + + public static final Map commandRepository; + + static { + RESET = "reset"; + GET_STRINGS = "getStrings"; + SET_VALUE = "setValue"; + PULL_FILE = "pullFile"; + PULL_FOLDER = "pullFolder"; + RUN_APP_IN_BACKGROUND = "runAppInBackground"; + PERFORM_TOUCH_ACTION = "performTouchAction"; + PERFORM_MULTI_TOUCH = "performMultiTouch"; + IS_APP_INSTALLED = "isAppInstalled"; + INSTALL_APP = "installApp"; + REMOVE_APP = "removeApp"; + LAUNCH_APP = "launchApp"; + CLOSE_APP = "closeApp"; + GET_DEVICE_TIME = "getDeviceTime"; + GET_SESSION = "getSession"; + + HIDE_KEYBOARD = "hideKeyboard"; + LOCK = "lock"; + SHAKE = "shake"; + TOUCH_ID = "touchId"; + + CURRENT_ACTIVITY = "currentActivity"; + END_TEST_COVERAGE = "endTestCoverage"; + GET_DISPLAY_DENSITY = "getDisplayDensity"; + GET_NETWORK_CONNECTION = "getNetworkConnection"; + GET_SYSTEM_BARS = "getSystemBars"; + IS_KEYBOARD_SHOWN = "isKeyboardShown"; + IS_LOCKED = "isLocked"; + LONG_PRESS_KEY_CODE = "longPressKeyCode"; + OPEN_NOTIFICATIONS = "openNotifications"; + PRESS_KEY_CODE = "pressKeyCode"; + PUSH_FILE = "pushFile"; + SET_NETWORK_CONNECTION = "setNetworkConnection"; + START_ACTIVITY = "startActivity"; + TOGGLE_LOCATION_SERVICES = "toggleLocationServices"; + UNLOCK = "unlock"; + REPLACE_VALUE = "replaceValue"; + GET_SETTINGS = "getSettings"; + SET_SETTINGS = "setSettings"; + + commandRepository = new HashMap<>(); + commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset")); + commandRepository.put(GET_STRINGS, postC("/session/:sessionId/appium/app/strings")); + commandRepository.put(SET_VALUE, postC("/session/:sessionId/appium/element/:id/value")); + commandRepository.put(PULL_FILE, postC("/session/:sessionId/appium/device/pull_file")); + commandRepository.put(PULL_FOLDER, postC("/session/:sessionId/appium/device/pull_folder")); + commandRepository.put(HIDE_KEYBOARD, postC("/session/:sessionId/appium/device/hide_keyboard")); + commandRepository.put(RUN_APP_IN_BACKGROUND, postC("/session/:sessionId/appium/app/background")); + commandRepository.put(PERFORM_TOUCH_ACTION, postC("/session/:sessionId/touch/perform")); + commandRepository.put(PERFORM_MULTI_TOUCH, postC("/session/:sessionId/touch/multi/perform")); + commandRepository.put(IS_APP_INSTALLED, postC("/session/:sessionId/appium/device/app_installed")); + commandRepository.put(INSTALL_APP, postC("/session/:sessionId/appium/device/install_app")); + commandRepository.put(REMOVE_APP, postC("/session/:sessionId/appium/device/remove_app")); + commandRepository.put(LAUNCH_APP, postC("/session/:sessionId/appium/app/launch")); + commandRepository.put(CLOSE_APP, postC("/session/:sessionId/appium/app/close")); + commandRepository.put(LOCK, postC("/session/:sessionId/appium/device/lock")); + commandRepository.put(GET_SETTINGS, getC("/session/:sessionId/appium/settings")); + commandRepository.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings")); + commandRepository.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time")); + commandRepository.put(GET_SESSION,getC("/session/:sessionId/")); //iOS - result.put(SHAKE, postC("/session/:sessionId/appium/device/shake")); - result.put(TOUCH_ID, postC("/session/:sessionId/appium/simulator/touch_id")); + commandRepository.put(SHAKE, postC("/session/:sessionId/appium/device/shake")); + commandRepository.put(TOUCH_ID, postC("/session/:sessionId/appium/simulator/touch_id")); //Android - result.put(CURRENT_ACTIVITY, - getC("/session/:sessionId/appium/device/current_activity")); - result.put(END_TEST_COVERAGE, - postC("/session/:sessionId/appium/app/end_test_coverage")); - result.put(GET_DISPLAY_DENSITY, getC("/session/:sessionId/appium/device/display_density")); - result.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection")); - result.put(GET_SYSTEM_BARS, getC("/session/:sessionId/appium/device/system_bars")); - result.put(IS_KEYBOARD_SHOWN, getC("/session/:sessionId/appium/device/is_keyboard_shown")); - result.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked")); - result.put(LONG_PRESS_KEY_CODE, - postC("/session/:sessionId/appium/device/long_press_keycode")); - result.put(OPEN_NOTIFICATIONS, - postC("/session/:sessionId/appium/device/open_notifications")); - result.put(PRESS_KEY_CODE, - postC("/session/:sessionId/appium/device/press_keycode")); - result.put(PUSH_FILE, postC("/session/:sessionId/appium/device/push_file")); - result.put(SET_NETWORK_CONNECTION, - postC("/session/:sessionId/network_connection")); - result.put(START_ACTIVITY, - postC("/session/:sessionId/appium/device/start_activity")); - result.put(TOGGLE_LOCATION_SERVICES, - postC("/session/:sessionId/appium/device/toggle_location_services")); - result.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock")); - result.put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value")); - return result; + commandRepository.put(CURRENT_ACTIVITY, + getC("/session/:sessionId/appium/device/current_activity")); + commandRepository.put(END_TEST_COVERAGE, + postC("/session/:sessionId/appium/app/end_test_coverage")); + commandRepository.put(GET_DISPLAY_DENSITY, getC("/session/:sessionId/appium/device/display_density")); + commandRepository.put(GET_NETWORK_CONNECTION, getC("/session/:sessionId/network_connection")); + commandRepository.put(GET_SYSTEM_BARS, getC("/session/:sessionId/appium/device/system_bars")); + commandRepository.put(IS_KEYBOARD_SHOWN, getC("/session/:sessionId/appium/device/is_keyboard_shown")); + commandRepository.put(IS_LOCKED, postC("/session/:sessionId/appium/device/is_locked")); + commandRepository.put(LONG_PRESS_KEY_CODE, + postC("/session/:sessionId/appium/device/long_press_keycode")); + commandRepository.put(OPEN_NOTIFICATIONS, + postC("/session/:sessionId/appium/device/open_notifications")); + commandRepository.put(PRESS_KEY_CODE, + postC("/session/:sessionId/appium/device/press_keycode")); + commandRepository.put(PUSH_FILE, postC("/session/:sessionId/appium/device/push_file")); + commandRepository.put(SET_NETWORK_CONNECTION, + postC("/session/:sessionId/network_connection")); + commandRepository.put(START_ACTIVITY, + postC("/session/:sessionId/appium/device/start_activity")); + commandRepository.put(TOGGLE_LOCATION_SERVICES, + postC("/session/:sessionId/appium/device/toggle_location_services")); + commandRepository.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock")); + commandRepository. put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value")); } /** @@ -158,6 +196,38 @@ public static CommandInfo deleteC(String url) { return new CommandInfo(url, HttpMethod.DELETE); } + /** + * This method forms a {@link java.util.Map} of parameters for the + * keyboard hiding. + * + * @param keyName The button pressed by the mobile driver to attempt hiding the + * keyboard. + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> hideKeyboardCommand(String keyName) { + return new AbstractMap.SimpleEntry<>( + HIDE_KEYBOARD, prepareArguments("keyName", keyName)); + } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * keyboard hiding. + * + * @param strategy HideKeyboardStrategy. + * @param keyName a String, representing the text displayed on the button of the + * keyboard you want to press. For example: "Done". + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> hideKeyboardCommand(String strategy, + String keyName) { + String[] parameters = new String[] {"strategy", "key"}; + Object[] values = new Object[] {strategy, keyName}; + return new AbstractMap.SimpleEntry<>( + HIDE_KEYBOARD, prepareArguments(parameters, values)); + } + /** * @param param is a parameter name. * @param value is the parameter value. @@ -245,4 +315,17 @@ public static ImmutableMap prepareArguments(String[] params, return new AbstractMap.SimpleEntry<>( LONG_PRESS_KEY_CODE, prepareArguments(parameters, values)); } + + /** + * This method forms a {@link java.util.Map} of parameters for the + * device locking. + * + * @param seconds seconds number of seconds to lock the screen for + * @return a key-value pair. The key is the command name. The value is a + * {@link java.util.Map} command arguments. + */ + public static Map.Entry> lockDeviceCommand(int seconds) { + return new AbstractMap.SimpleEntry<>( + LOCK, prepareArguments("seconds", seconds)); + } } diff --git a/src/main/java/io/appium/java_client/MobileDriver.java b/src/main/java/io/appium/java_client/MobileDriver.java index 57a2c71bc..e982d5419 100644 --- a/src/main/java/io/appium/java_client/MobileDriver.java +++ b/src/main/java/io/appium/java_client/MobileDriver.java @@ -29,10 +29,8 @@ import org.openqa.selenium.internal.FindsByName; import org.openqa.selenium.internal.FindsByTagName; import org.openqa.selenium.internal.FindsByXPath; -import org.openqa.selenium.remote.Response; import java.util.List; -import java.util.Map; public interface MobileDriver extends WebDriver, PerformsTouchActions, ContextAware, Rotatable, FindsByAccessibilityId, LocationContext, HidesKeyboard, HasDeviceTime, diff --git a/src/main/java/io/appium/java_client/MobileElement.java b/src/main/java/io/appium/java_client/MobileElement.java index 4cdb7e208..8415d7e6b 100644 --- a/src/main/java/io/appium/java_client/MobileElement.java +++ b/src/main/java/io/appium/java_client/MobileElement.java @@ -26,7 +26,7 @@ import java.util.List; @SuppressWarnings({"unchecked"}) -public class MobileElement +public abstract class MobileElement extends DefaultGenericMobileElement { protected FileDetector fileDetector; diff --git a/src/main/java/io/appium/java_client/android/AndroidDriver.java b/src/main/java/io/appium/java_client/android/AndroidDriver.java index 43e1f0b2f..f95a73643 100644 --- a/src/main/java/io/appium/java_client/android/AndroidDriver.java +++ b/src/main/java/io/appium/java_client/android/AndroidDriver.java @@ -24,7 +24,6 @@ import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.FindsByAndroidUIAutomator; import io.appium.java_client.PressesKeyCode; -import io.appium.java_client.android.internal.JsonToAndroidElementConverter; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; @@ -37,13 +36,13 @@ /** * @param the required type of class which implement {@link org.openqa.selenium.WebElement}. - * Instances of the defined type will be returned via findElement* and findElements*. - * Warning (!!!). Allowed types: - * {@link org.openqa.selenium.WebElement} - * {@link io.appium.java_client.TouchableElement} - * {@link org.openqa.selenium.remote.RemoteWebElement} - * {@link io.appium.java_client.MobileElement} - * {@link io.appium.java_client.android.AndroidElement} + * Instances of the defined type will be returned via findElement* and findElements*. + * Warning (!!!). Allowed types: + * {@link org.openqa.selenium.WebElement} + * {@link io.appium.java_client.TouchableElement} + * {@link org.openqa.selenium.remote.RemoteWebElement} + * {@link io.appium.java_client.MobileElement} + * {@link io.appium.java_client.android.AndroidElement} */ public class AndroidDriver extends AppiumDriver @@ -60,7 +59,7 @@ public class AndroidDriver * at {@link org.openqa.selenium.Capabilities} */ public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) { - super(executor, capabilities, JsonToAndroidElementConverter.class); + super(executor, capabilities); } /** @@ -70,8 +69,7 @@ public AndroidDriver(HttpCommandExecutor executor, Capabilities capabilities) { * at {@link org.openqa.selenium.Capabilities} */ public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) { - super(remoteAddress, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + super(remoteAddress, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -85,8 +83,7 @@ public AndroidDriver(URL remoteAddress, Capabilities desiredCapabilities) { public AndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(remoteAddress, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -96,8 +93,7 @@ public AndroidDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, * at {@link org.openqa.selenium.Capabilities} */ public AndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { - super(service, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + super(service, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -111,8 +107,7 @@ public AndroidDriver(AppiumDriverLocalService service, Capabilities desiredCapab public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(service, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -122,8 +117,7 @@ public AndroidDriver(AppiumDriverLocalService service, HttpClient.Factory httpCl * at {@link org.openqa.selenium.Capabilities} */ public AndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { - super(builder, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + super(builder, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -137,8 +131,7 @@ public AndroidDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilit public AndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(builder, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -148,8 +141,7 @@ public AndroidDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClient * at {@link org.openqa.selenium.Capabilities} */ public AndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } /** @@ -157,8 +149,7 @@ public AndroidDriver(HttpClient.Factory httpClientFactory, Capabilities desiredC * at {@link org.openqa.selenium.Capabilities} */ public AndroidDriver(Capabilities desiredCapabilities) { - super(substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM), - JsonToAndroidElementConverter.class); + super(substituteMobilePlatform(desiredCapabilities, ANDROID_PLATFORM)); } diff --git a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java index e9ea6b6dd..4684ad7c0 100644 --- a/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java @@ -281,12 +281,9 @@ public class AndroidMobileCommandHelper extends MobileCommand { } /** - * This method forms a {@link java.util.Map} of parameters for the - * device locking. - * - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * This method was moved to {@link MobileCommand#hideKeyboardCommand(String, String)}. */ + @Deprecated public static Map.Entry> lockDeviceCommand() { return new AbstractMap.SimpleEntry<>(LOCK, prepareArguments("seconds", 0)); } diff --git a/src/main/java/io/appium/java_client/android/HasSettings.java b/src/main/java/io/appium/java_client/android/HasSettings.java index 9f4516e3c..4bcabd58a 100644 --- a/src/main/java/io/appium/java_client/android/HasSettings.java +++ b/src/main/java/io/appium/java_client/android/HasSettings.java @@ -19,12 +19,10 @@ import static io.appium.java_client.android.AndroidMobileCommandHelper.getSettingsCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.setSettingsCommand; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; +import org.aspectj.lang.annotation.SuppressAjWarnings; import org.openqa.selenium.remote.Response; import java.util.Map; @@ -49,12 +47,12 @@ default void setSetting(Setting setting, Object value) { * * @return JsonObject, a straight-up hash of settings. */ - default JsonObject getSettings() { + @SuppressAjWarnings("unchecked") + default Map getSettings() { Map.Entry> keyValuePair = getSettingsCommand(); Response response = execute(keyValuePair.getKey(), keyValuePair.getValue()); - JsonParser parser = new JsonParser(); - return (JsonObject) parser.parse(response.getValue().toString()); + return (Map) response.getValue(); } /** diff --git a/src/main/java/io/appium/java_client/android/LocksAndroidDevice.java b/src/main/java/io/appium/java_client/android/LocksAndroidDevice.java index 282f0e2da..c97d59123 100644 --- a/src/main/java/io/appium/java_client/android/LocksAndroidDevice.java +++ b/src/main/java/io/appium/java_client/android/LocksAndroidDevice.java @@ -16,8 +16,8 @@ package io.appium.java_client.android; +import static io.appium.java_client.MobileCommand.lockDeviceCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.isLockedCommand; -import static io.appium.java_client.android.AndroidMobileCommandHelper.lockDeviceCommand; import static io.appium.java_client.android.AndroidMobileCommandHelper.unlockCommand; import io.appium.java_client.CommandExecutionHelper; @@ -37,7 +37,7 @@ default boolean isLocked() { * This method locks a device. */ default void lockDevice() { - CommandExecutionHelper.execute(this, lockDeviceCommand()); + CommandExecutionHelper.execute(this, lockDeviceCommand(0)); } /** diff --git a/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java b/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java index bb8a5f82f..7196065dd 100644 --- a/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java +++ b/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java @@ -21,10 +21,15 @@ import io.appium.java_client.internal.JsonToMobileElementConverter; import org.openqa.selenium.remote.RemoteWebDriver; +/** + * It is never used now. Please use {@link io.appium.java_client.internal.JsonToMobileElementConverter} + * instead + */ +@Deprecated public class JsonToAndroidElementConverter extends JsonToMobileElementConverter { public JsonToAndroidElementConverter(RemoteWebDriver driver) { - super(driver); + super(driver, null); } @Override protected MobileElement newMobileElement() { diff --git a/src/main/java/io/appium/java_client/events/DefaultAspect.java b/src/main/java/io/appium/java_client/events/DefaultAspect.java index 245aecc14..b0ed39e7f 100644 --- a/src/main/java/io/appium/java_client/events/DefaultAspect.java +++ b/src/main/java/io/appium/java_client/events/DefaultAspect.java @@ -27,14 +27,9 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.openqa.selenium.Alert; -import org.openqa.selenium.By; import org.openqa.selenium.ContextAware; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; -import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.security.Credentials; import org.springframework.context.support.AbstractApplicationContext; import java.lang.reflect.InvocationTargetException; @@ -273,10 +268,10 @@ public void beforeFindBy(JoinPoint joinPoint) throws Throwable { try { Object target = joinPoint.getTarget(); if (!WebElement.class.isAssignableFrom(target.getClass())) { - listener.beforeFindBy((By) castArgument(joinPoint, 0), null, driver); + listener.beforeFindBy(castArgument(joinPoint, 0), null, driver); } else { - listener.beforeFindBy((By) castArgument(joinPoint, 0), - (WebElement) castTarget(joinPoint), driver); + listener.beforeFindBy(castArgument(joinPoint, 0), + castTarget(joinPoint), driver); } } catch (Throwable t) { throw getRootCause(t); @@ -288,10 +283,10 @@ public void afterFindBy(JoinPoint joinPoint) throws Throwable { try { Object target = joinPoint.getTarget(); if (!WebElement.class.isAssignableFrom(target.getClass())) { - listener.afterFindBy((By) castArgument(joinPoint, 0), null, driver); + listener.afterFindBy(castArgument(joinPoint, 0), null, driver); } else { - listener.afterFindBy((By) castArgument(joinPoint, 0), - (WebElement) castTarget(joinPoint), driver); + listener.afterFindBy(castArgument(joinPoint, 0), + castTarget(joinPoint), driver); } } catch (Throwable t) { throw getRootCause(t); @@ -301,7 +296,7 @@ public void afterFindBy(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_CLICK) public void beforeClickOn(JoinPoint joinPoint) throws Throwable { try { - listener.beforeClickOn((WebElement) castTarget(joinPoint), driver); + listener.beforeClickOn(castTarget(joinPoint), driver); } catch (Throwable t) { throw getRootCause(t); } @@ -310,7 +305,7 @@ public void beforeClickOn(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_CLICK) public void afterClickOn(JoinPoint joinPoint) throws Throwable { try { - listener.afterClickOn((WebElement) castTarget(joinPoint), driver); + listener.afterClickOn(castTarget(joinPoint), driver); } catch (Throwable t) { throw getRootCause(t); } @@ -319,7 +314,7 @@ public void afterClickOn(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_CHANGE_VALUE) public void beforeChangeValueOf(JoinPoint joinPoint) throws Throwable { try { - listener.beforeChangeValueOf((WebElement) castTarget(joinPoint), driver); + listener.beforeChangeValueOf(castTarget(joinPoint), driver); } catch (Throwable t) { throw getRootCause(t); } @@ -328,7 +323,7 @@ public void beforeChangeValueOf(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_CHANGE_VALUE) public void afterChangeValueOf(JoinPoint joinPoint) throws Throwable { try { - listener.afterChangeValueOf((WebElement) castTarget(joinPoint), driver); + listener.afterChangeValueOf(castTarget(joinPoint), driver); } catch (Throwable t) { throw getRootCause(t); } @@ -355,7 +350,7 @@ public void afterScript(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_ALERT_ACCEPT) public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable { try { - listener.beforeAlertAccept(driver, (Alert) castTarget(joinPoint)); + listener.beforeAlertAccept(driver, castTarget(joinPoint)); } catch (Throwable t) { throw getRootCause(t); } @@ -364,7 +359,7 @@ public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_ALERT_ACCEPT) public void afterAlertAccept(JoinPoint joinPoint) throws Throwable { try { - listener.afterAlertAccept(driver, (Alert) castTarget(joinPoint)); + listener.afterAlertAccept(driver, castTarget(joinPoint)); } catch (Throwable t) { throw getRootCause(t); } @@ -373,7 +368,7 @@ public void afterAlertAccept(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_ALERT_DISMISS) public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable { try { - listener.beforeAlertDismiss(driver, (Alert) castTarget(joinPoint)); + listener.beforeAlertDismiss(driver, castTarget(joinPoint)); } catch (Throwable t) { throw getRootCause(t); } @@ -382,7 +377,7 @@ public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_ALERT_DISMISS) public void afterAlertDismiss(JoinPoint joinPoint) throws Throwable { try { - listener.afterAlertDismiss(driver, (Alert) castTarget(joinPoint)); + listener.afterAlertDismiss(driver, castTarget(joinPoint)); } catch (Throwable t) { throw getRootCause(t); } @@ -391,7 +386,7 @@ public void afterAlertDismiss(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_ALERT_SEND_KEYS) public void beforeAlertSendKeys(JoinPoint joinPoint) throws Throwable { try { - listener.beforeAlertSendKeys(driver, (Alert) castTarget(joinPoint), + listener.beforeAlertSendKeys(driver, castTarget(joinPoint), String.valueOf(joinPoint.getArgs()[0])); } catch (Throwable t) { throw getRootCause(t); @@ -401,7 +396,7 @@ public void beforeAlertSendKeys(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_ALERT_SEND_KEYS) public void afterAlertSendKeys(JoinPoint joinPoint) throws Throwable { try { - listener.afterAlertSendKeys(driver, (Alert) castTarget(joinPoint), + listener.afterAlertSendKeys(driver, castTarget(joinPoint), String.valueOf(joinPoint.getArgs()[0])); } catch (Throwable t) { throw getRootCause(t); @@ -412,7 +407,7 @@ public void afterAlertSendKeys(JoinPoint joinPoint) throws Throwable { public void beforeAlertAuthentication(JoinPoint joinPoint) throws Throwable { try { listener.beforeAuthentication(driver, - (Alert) castTarget(joinPoint), (Credentials) castArgument(joinPoint, 0)); + castTarget(joinPoint), castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -421,8 +416,8 @@ public void beforeAlertAuthentication(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_ALERT_AUTHENTICATION) public void afterAlertAuthentication(JoinPoint joinPoint) throws Throwable { try { - listener.afterAuthentication(driver, (Alert) castTarget(joinPoint), - (Credentials) castArgument(joinPoint, 0)); + listener.afterAuthentication(driver, castTarget(joinPoint), + castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -432,7 +427,7 @@ public void afterAlertAuthentication(JoinPoint joinPoint) throws Throwable { public void beforeWindowIsResized(JoinPoint joinPoint) throws Throwable { try { listener.beforeWindowChangeSize(driver, - (WebDriver.Window) castTarget(joinPoint), (Dimension) castArgument(joinPoint, 0)); + castTarget(joinPoint), castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -441,8 +436,8 @@ public void beforeWindowIsResized(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_WINDOW_SET_SIZE) public void afterWindowIsResized(JoinPoint joinPoint) throws Throwable { try { - listener.afterWindowChangeSize(driver, (WebDriver.Window) castTarget(joinPoint), - (Dimension) castArgument(joinPoint, 0)); + listener.afterWindowChangeSize(driver, castTarget(joinPoint), + castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -451,8 +446,8 @@ public void afterWindowIsResized(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_WINDOW_SET_POSITION) public void beforeWindowIsMoved(JoinPoint joinPoint) throws Throwable { try { - listener.beforeWindowIsMoved(driver, (WebDriver.Window) castTarget(joinPoint), - (Point) castArgument(joinPoint, 0)); + listener.beforeWindowIsMoved(driver, castTarget(joinPoint), + castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -461,8 +456,8 @@ public void beforeWindowIsMoved(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_WINDOW_SET_POSITION) public void afterWindowIsMoved(JoinPoint joinPoint) throws Throwable { try { - listener.afterWindowIsMoved(driver, (WebDriver.Window) castTarget(joinPoint), - (Point) castArgument(joinPoint, 0)); + listener.afterWindowIsMoved(driver, castTarget(joinPoint), + castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -471,7 +466,7 @@ public void afterWindowIsMoved(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_WINDOW_MAXIMIZE) public void beforeMaximization(JoinPoint joinPoint) throws Throwable { try { - listener.beforeWindowIsMaximized(driver, (WebDriver.Window) castTarget(joinPoint)); + listener.beforeWindowIsMaximized(driver, castTarget(joinPoint)); } catch (Throwable t) { throw getRootCause(t); } @@ -480,7 +475,7 @@ public void beforeMaximization(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_WINDOW_MAXIMIZE) public void afterMaximization(JoinPoint joinPoint) throws Throwable { try { - listener.afterWindowIsMaximized(driver, (WebDriver.Window) castTarget(joinPoint)); + listener.afterWindowIsMaximized(driver, castTarget(joinPoint)); } catch (Throwable t) { throw getRootCause(t); } @@ -489,7 +484,7 @@ public void afterMaximization(JoinPoint joinPoint) throws Throwable { @Before(EXECUTION_ROTATE) public void beforeRotation(JoinPoint joinPoint) throws Throwable { try { - listener.beforeRotation(driver, (ScreenOrientation) castArgument(joinPoint, 0)); + listener.beforeRotation(driver, castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -499,7 +494,7 @@ public void beforeRotation(JoinPoint joinPoint) throws Throwable { @After(EXECUTION_ROTATE) public void afterRotation(JoinPoint joinPoint) throws Throwable { try { - listener.afterRotation(driver, (ScreenOrientation) castArgument(joinPoint, 0)); + listener.afterRotation(driver, castArgument(joinPoint, 0)); } catch (Throwable t) { throw getRootCause(t); } @@ -540,10 +535,10 @@ public Object doAround(ProceedingJoinPoint point) throws Throwable { } if (result == null) { // maybe it was "void" - return result; + return null; } if (List.class.isAssignableFrom(result.getClass())) { - return returnProxyList((List) result); + return returnProxyList((List) (result)); } return transformToListenable(result); diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index 4a95d5177..e8713e082 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -16,29 +16,59 @@ package io.appium.java_client.internal; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import io.appium.java_client.MobileElement; -import org.openqa.selenium.WebElement; +import io.appium.java_client.android.AndroidElement; +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.youiengine.YouiEngineElement; +import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.internal.JsonToWebElementConverter; +import java.lang.reflect.Constructor; import java.util.Collection; import java.util.Map; /** - * Reconstitutes {@link WebElement}s from their JSON representation. Will recursively convert Lists + * Reconstitutes {@link org.openqa.selenium.WebElement}s from their JSON representation. Will recursively convert Lists * and Maps to catch nested references. All other values pass through the converter unchanged. */ -public abstract class JsonToMobileElementConverter extends JsonToWebElementConverter { - protected RemoteWebDriver driver; +public class JsonToMobileElementConverter extends JsonToWebElementConverter { - public JsonToMobileElementConverter(RemoteWebDriver driver) { + private static final Map> mobileElementMap = + new ImmutableMap.Builder>() + .put(AutomationName.ANDROID_UIAUTOMATOR2.toLowerCase(), AndroidElement.class) + .put(AutomationName.SELENDROID.toLowerCase(), AndroidElement.class) + .put(AutomationName.YOUI_ENGINE.toLowerCase(), YouiEngineElement.class) + .put(AutomationName.IOS_XCUI_TEST.toLowerCase(), IOSElement.class) + .put(MobilePlatform.ANDROID.toLowerCase(), AndroidElement.class) + .put(MobilePlatform.IOS.toLowerCase(), IOSElement.class).build(); + private static final String AUTOMATION_NAME_PARAMETER = "automationName"; + private static final String PLATFORM_NAME_PARAMETER = "platformName"; + + + protected final RemoteWebDriver driver; + private final String automation; + private final String platform; + + /** + * @param driver an instance of {@link org.openqa.selenium.remote.RemoteWebDriver} subclass + * @param sessionParameters the map of current session parameters + */ + public JsonToMobileElementConverter(RemoteWebDriver driver, Map sessionParameters) { super(driver); this.driver = driver; + automation = String.valueOf(sessionParameters + .get(AUTOMATION_NAME_PARAMETER)).toLowerCase(); + platform = String.valueOf(sessionParameters + .get(PLATFORM_NAME_PARAMETER)).toLowerCase(); } /** @@ -75,5 +105,26 @@ public Object apply(Object result) { return result; } - protected abstract MobileElement newMobileElement(); + protected MobileElement newMobileElement() { + Class target = mobileElementMap.get(automation); + + if (target == null) { + target = mobileElementMap.get(platform); + } + + if (target == null) { + throw new WebDriverException(new ClassNotFoundException("The class of mobile element is " + + "unknown for current session")); + } + + try { + Constructor constructor = target.getDeclaredConstructor(); + constructor.setAccessible(true); + MobileElement result = constructor.newInstance(); + result.setParent(driver); + return result; + } catch (Exception e) { + throw new WebDriverException(e); + } + } } diff --git a/src/main/java/io/appium/java_client/internal/MobileElementToJsonConverter.java b/src/main/java/io/appium/java_client/internal/MobileElementToJsonConverter.java deleted file mode 100644 index 8f1c58ef5..000000000 --- a/src/main/java/io/appium/java_client/internal/MobileElementToJsonConverter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client.internal; - -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import io.appium.java_client.MobileElement; - -import org.openqa.selenium.internal.WrapsElement; -import org.openqa.selenium.remote.RemoteWebElement; -import org.openqa.selenium.remote.internal.WebElementToJsonConverter; - -import java.util.Collection; -import java.util.Map; - -/** - * Converts {@link RemoteWebElement} objects, which may be - * {@link WrapsElement wrapped}, into their JSON representation as defined by - * the WebDriver wire protocol. This class will recursively convert Lists and - * Maps to catch nested references. - */ -public class MobileElementToJsonConverter extends WebElementToJsonConverter { - - /** - * Converts {@link RemoteWebElement} objects, which may be - * {@link WrapsElement wrapped}, into their JSON representation as defined by - * the WebDriver wire protocol. - * - * @param arg is the argument - * @return the result - */ - public Object apply(Object arg) { - if (arg == null - || arg instanceof String - || arg instanceof Boolean - || arg instanceof Number) { - return arg; - } - - while (arg instanceof WrapsElement) { - arg = ((WrapsElement) arg).getWrappedElement(); - } - - if (arg instanceof MobileElement) { - return ImmutableMap.of("ELEMENT", ((MobileElement) arg).getId()); - } - - if (arg.getClass().isArray()) { - arg = Lists.newArrayList((Object[]) arg); - } - - if (arg instanceof Collection) { - Collection args = (Collection) arg; - return Collections2.transform(args, this); - } - - if (arg instanceof Map) { - Map args = (Map) arg; - Map converted = Maps.newHashMapWithExpectedSize(args.size()); - for (Map.Entry entry : args.entrySet()) { - Object key = entry.getKey(); - if (!(key instanceof String)) { - throw new IllegalArgumentException( - "All keys in Map script arguments must be strings: " + key.getClass() - .getName()); - } - converted.put((String) key, apply(entry.getValue())); - } - return converted; - } - - throw new IllegalArgumentException( - "Argument is of an illegal type: " + arg.getClass().getName()); - } -} diff --git a/src/main/java/io/appium/java_client/ios/IOSDriver.java b/src/main/java/io/appium/java_client/ios/IOSDriver.java index 3e606de84..f8e531b09 100644 --- a/src/main/java/io/appium/java_client/ios/IOSDriver.java +++ b/src/main/java/io/appium/java_client/ios/IOSDriver.java @@ -19,9 +19,9 @@ import static io.appium.java_client.MobileCommand.prepareArguments; import io.appium.java_client.AppiumDriver; +import io.appium.java_client.FindsByIosNSPredicate; import io.appium.java_client.FindsByIosUIAutomation; import io.appium.java_client.HidesKeyboardWithKeyName; -import io.appium.java_client.ios.internal.JsonToIOSElementConverter; import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; @@ -36,22 +36,21 @@ import java.net.URL; - /** * @param the required type of class which implement - * {@link org.openqa.selenium.WebElement}. - * Instances of the defined type will be returned via findElement* and findElements*. - * Warning (!!!). Allowed types: - * {@link org.openqa.selenium.WebElement} - * {@link io.appium.java_client.TouchableElement} - * {@link org.openqa.selenium.remote.RemoteWebElement} - * {@link io.appium.java_client.MobileElement} - * {@link io.appium.java_client.ios.IOSElement} + * {@link org.openqa.selenium.WebElement}. + * Instances of the defined type will be returned via findElement* and findElements*. + * Warning (!!!). Allowed types: + * {@link org.openqa.selenium.WebElement} + * {@link io.appium.java_client.TouchableElement} + * {@link org.openqa.selenium.remote.RemoteWebElement} + * {@link io.appium.java_client.MobileElement} + * {@link io.appium.java_client.ios.IOSElement} */ public class IOSDriver extends AppiumDriver implements HidesKeyboardWithKeyName, ShakesDevice, - FindsByIosUIAutomation, LocksIOSDevice, PerformsTouchID { + FindsByIosUIAutomation, LocksIOSDevice, PerformsTouchID, FindsByIosNSPredicate { private static final String IOS_PLATFORM = MobilePlatform.IOS; @@ -63,7 +62,7 @@ public class IOSDriver * at {@link org.openqa.selenium.Capabilities} */ public IOSDriver(HttpCommandExecutor executor, Capabilities capabilities) { - super(executor, capabilities, JsonToIOSElementConverter.class); + super(executor, capabilities); } /** @@ -73,8 +72,7 @@ public IOSDriver(HttpCommandExecutor executor, Capabilities capabilities) { * at {@link org.openqa.selenium.Capabilities} */ public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) { - super(remoteAddress, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + super(remoteAddress, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -88,8 +86,7 @@ public IOSDriver(URL remoteAddress, Capabilities desiredCapabilities) { public IOSDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(remoteAddress, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -99,8 +96,7 @@ public IOSDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, * at {@link org.openqa.selenium.Capabilities} */ public IOSDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) { - super(service, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + super(service, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -114,8 +110,7 @@ public IOSDriver(AppiumDriverLocalService service, Capabilities desiredCapabilit public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(service, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -125,8 +120,7 @@ public IOSDriver(AppiumDriverLocalService service, HttpClient.Factory httpClient * at {@link org.openqa.selenium.Capabilities} */ public IOSDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) { - super(builder, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + super(builder, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -140,8 +134,7 @@ public IOSDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities) public IOSDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { super(builder, httpClientFactory, - substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -151,8 +144,7 @@ public IOSDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFact * at {@link org.openqa.selenium.Capabilities} */ public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapabilities) { - super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + super(httpClientFactory, substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** @@ -160,8 +152,7 @@ public IOSDriver(HttpClient.Factory httpClientFactory, Capabilities desiredCapab * at {@link org.openqa.selenium.Capabilities} */ public IOSDriver(Capabilities desiredCapabilities) { - super(substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM), - JsonToIOSElementConverter.class); + super(substituteMobilePlatform(desiredCapabilities, IOS_PLATFORM)); } /** diff --git a/src/main/java/io/appium/java_client/ios/IOSMobileCommandHelper.java b/src/main/java/io/appium/java_client/ios/IOSMobileCommandHelper.java index 9f55698a1..74a0a6f52 100644 --- a/src/main/java/io/appium/java_client/ios/IOSMobileCommandHelper.java +++ b/src/main/java/io/appium/java_client/ios/IOSMobileCommandHelper.java @@ -26,29 +26,18 @@ public class IOSMobileCommandHelper extends MobileCommand { /** - * This method forms a {@link java.util.Map} of parameters for the - * keyboard hiding. - * - * @param keyName The button pressed by the mobile driver to attempt hiding the - * keyboard. - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * This method was moved to {@link MobileCommand#hideKeyboardCommand(String)}. */ + @Deprecated public static Map.Entry> hideKeyboardCommand(String keyName) { return new AbstractMap.SimpleEntry<>( HIDE_KEYBOARD, prepareArguments("keyName", keyName)); } /** - * This method forms a {@link java.util.Map} of parameters for the - * keyboard hiding. - * - * @param strategy HideKeyboardStrategy. - * @param keyName a String, representing the text displayed on the button of the - * keyboard you want to press. For example: "Done". - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * This method was moved to {@link MobileCommand#hideKeyboardCommand(String, String)}. */ + @Deprecated public static Map.Entry> hideKeyboardCommand(String strategy, String keyName) { String[] parameters = new String[] {"strategy", "key"}; @@ -58,13 +47,9 @@ public class IOSMobileCommandHelper extends MobileCommand { } /** - * This method forms a {@link java.util.Map} of parameters for the - * device locking. - * - * @param seconds seconds number of seconds to lock the screen for - * @return a key-value pair. The key is the command name. The value is a - * {@link java.util.Map} command arguments. + * This method was moved to {@link MobileCommand#lockDeviceCommand(int)}. */ + @Deprecated public static Map.Entry> lockDeviceCommand(int seconds) { return new AbstractMap.SimpleEntry<>( LOCK, prepareArguments("seconds", seconds)); diff --git a/src/main/java/io/appium/java_client/ios/LocksIOSDevice.java b/src/main/java/io/appium/java_client/ios/LocksIOSDevice.java index e8586cb22..5c55d467c 100644 --- a/src/main/java/io/appium/java_client/ios/LocksIOSDevice.java +++ b/src/main/java/io/appium/java_client/ios/LocksIOSDevice.java @@ -16,7 +16,7 @@ package io.appium.java_client.ios; -import static io.appium.java_client.ios.IOSMobileCommandHelper.lockDeviceCommand; +import static io.appium.java_client.MobileCommand.lockDeviceCommand; import io.appium.java_client.CommandExecutionHelper; import io.appium.java_client.ExecutesMethod; diff --git a/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java b/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java index 9d3a8aa36..d88b01779 100644 --- a/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java +++ b/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java @@ -21,10 +21,15 @@ import io.appium.java_client.ios.IOSElement; import org.openqa.selenium.remote.RemoteWebDriver; +/** + * It is never used now. Please use {@link io.appium.java_client.internal.JsonToMobileElementConverter} + * instead + */ +@Deprecated public class JsonToIOSElementConverter extends JsonToMobileElementConverter { public JsonToIOSElementConverter(RemoteWebDriver driver) { - super(driver); + super(driver, null); } @Override protected MobileElement newMobileElement() { diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java index f26c221f1..7bd0e8a6a 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java +++ b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java @@ -201,7 +201,7 @@ private Object decorateWidget(Field field) { return null; } - Class widgetType = null; + Class widgetType; boolean isAlist = false; if (List.class.isAssignableFrom(type)) { isAlist = true; diff --git a/src/main/java/io/appium/java_client/pagefactory/ElementInterceptor.java b/src/main/java/io/appium/java_client/pagefactory/ElementInterceptor.java index 7bfb323e7..17d4a2a6e 100644 --- a/src/main/java/io/appium/java_client/pagefactory/ElementInterceptor.java +++ b/src/main/java/io/appium/java_client/pagefactory/ElementInterceptor.java @@ -16,7 +16,6 @@ package io.appium.java_client.pagefactory; -import io.appium.java_client.MobileElement; import io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -25,7 +24,7 @@ import java.lang.reflect.Method; /** - * Intercepts requests to {@link MobileElement}. + * Intercepts requests to {@link io.appium.java_client.MobileElement}. */ class ElementInterceptor extends InterceptorOfASingleElement { diff --git a/src/main/java/io/appium/java_client/pagefactory/ElementListInterceptor.java b/src/main/java/io/appium/java_client/pagefactory/ElementListInterceptor.java index cf246505f..0c326c2f8 100644 --- a/src/main/java/io/appium/java_client/pagefactory/ElementListInterceptor.java +++ b/src/main/java/io/appium/java_client/pagefactory/ElementListInterceptor.java @@ -16,7 +16,6 @@ package io.appium.java_client.pagefactory; -import io.appium.java_client.MobileElement; import io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.pagefactory.ElementLocator; @@ -25,7 +24,7 @@ import java.util.List; /** - * Intercepts requests to the list of {@link MobileElement}. + * Intercepts requests to the list of {@link io.appium.java_client.MobileElement}. */ class ElementListInterceptor extends InterceptorOfAListOfElements { diff --git a/src/main/java/io/appium/java_client/remote/AutomationName.java b/src/main/java/io/appium/java_client/remote/AutomationName.java index f4b031ab1..1c7cfa8a4 100644 --- a/src/main/java/io/appium/java_client/remote/AutomationName.java +++ b/src/main/java/io/appium/java_client/remote/AutomationName.java @@ -22,4 +22,5 @@ public interface AutomationName { String SELENDROID = "Selendroid"; String IOS_XCUI_TEST = "XCuiTest"; String ANDROID_UIAUTOMATOR2 = "UIAutomator2"; + String YOUI_ENGINE = "youiengine"; } diff --git a/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java index daa0bd653..81a04062f 100644 --- a/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java @@ -162,4 +162,21 @@ public interface IOSMobileCapabilityType extends CapabilityType { * the app in iOS 9+. */ String APP_NAME = "appName"; + + /** + * Capability to pre-authorize a specific SSL cert in the iOS trust store. + */ + String CUSTOM_SSL_CERT = "customSSLCert"; + + /** + * The desired capability to specify a length for tapping, if the regular + * tap is too long for the app under test. The XCUITest specific capability. + */ + String TAP_WITH_SHORT_PRESS_DURATION = "tapWithShortPressDuration"; + + /** + * The capability to direct Appium to set the simulator scale. + * The XCUITest specific capability. + */ + String SCALE_FACTOR = "scaleFactor"; } diff --git a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java index 9956432be..7726b0a71 100644 --- a/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/MobileCapabilityType.java @@ -108,4 +108,10 @@ public interface MobileCapabilityType extends CapabilityType { * On Android, this will also remove the app after the session is complete. Default false. */ String FULL_RESET = "fullReset"; + + /** + * The desired capability which specifies whether to delete any generated files at + * the end of a session (see iOS and Android entries for particulars). + */ + String CLEAR_SYSTEM_FILES = "clearSystemFiles"; } diff --git a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java index 8cbb0be26..9dec96efe 100644 --- a/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java +++ b/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java @@ -318,10 +318,10 @@ private String parseCapabilitiesIfWindows() { String result = StringUtils.EMPTY; if (capabilities != null) { - Map capabilitiesMap = (Map) capabilities.asMap(); - Set> entries = capabilitiesMap.entrySet(); + Map capabilitiesMap = capabilities.asMap(); + Set> entries = capabilitiesMap.entrySet(); - for (Map.Entry entry : entries) { + for (Map.Entry entry : entries) { Object value = entry.getValue(); if (value == null) { @@ -354,10 +354,10 @@ private String parseCapabilitiesIfUNIX() { String result = StringUtils.EMPTY; if (capabilities != null) { - Map capabilitiesMap = (Map) capabilities.asMap(); - Set> entries = capabilitiesMap.entrySet(); + Map capabilitiesMap = capabilities.asMap(); + Set> entries = capabilitiesMap.entrySet(); - for (Map.Entry entry : entries) { + for (Map.Entry entry : entries) { Object value = entry.getValue(); if (value == null) { diff --git a/src/main/java/io/appium/java_client/youiengine/YouiEngineDriver.java b/src/main/java/io/appium/java_client/youiengine/YouiEngineDriver.java index 215d85264..e800a524a 100644 --- a/src/main/java/io/appium/java_client/youiengine/YouiEngineDriver.java +++ b/src/main/java/io/appium/java_client/youiengine/YouiEngineDriver.java @@ -18,7 +18,6 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.TouchAction; -import io.appium.java_client.youiengine.internal.JsonToYouiEngineElementConverter; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebElement; @@ -29,7 +28,7 @@ public class YouiEngineDriver extends AppiumDriver { /** Constructor takes in the Appium Server URL and the capabilities you want to use for this * test execution. **/ public YouiEngineDriver(URL remoteAddress, Capabilities desiredCapabilities) { - super(remoteAddress, desiredCapabilities, JsonToYouiEngineElementConverter.class); + super(remoteAddress, desiredCapabilities); } @Override diff --git a/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java b/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java index 7aa09a52c..c1071c57c 100644 --- a/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java +++ b/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java @@ -22,10 +22,14 @@ import org.openqa.selenium.remote.RemoteWebDriver; - +/** + * It is never used now. Please use {@link io.appium.java_client.internal.JsonToMobileElementConverter} + * instead + */ +@Deprecated public class JsonToYouiEngineElementConverter extends JsonToMobileElementConverter { public JsonToYouiEngineElementConverter(RemoteWebDriver driver) { - super(driver); + super(driver, null); } @Override diff --git a/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java b/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java index 6fe81212f..f6df58129 100644 --- a/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidConnectionTest.java @@ -18,63 +18,20 @@ import static org.junit.Assert.assertEquals; -import io.appium.java_client.MobileElement; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.FixMethodOrder; import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; +import org.junit.runners.MethodSorters; -import java.io.File; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class AndroidConnectionTest extends BaseAndroidTest { -public class AndroidConnectionTest { - - private static AppiumDriverLocalService service; - private static AndroidDriver driver; - - /** - * initialization. - */ - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new AndroidDriver<>(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass public static void afterClass() { - if (driver != null) { - try { - driver.setConnection(Connection.DATA); - } finally { - driver.quit(); - } - } - if (service != null) { - service.stop(); - } - } - - @Test public void setWiFi() { + @Test public void test1() { driver.setConnection(Connection.WIFI); assertEquals(Connection.WIFI, driver.getConnection()); } - @Test public void setNoneAndAirplane() { + @Test public void test2() { driver.setConnection(Connection.NONE); assertEquals(Connection.NONE, driver.getConnection()); @@ -83,7 +40,7 @@ public class AndroidConnectionTest { driver.getConnection()); } - @Test public void setAll() { + @Test public void test3() { driver.setConnection(Connection.ALL); assertEquals(Connection.ALL, driver.getConnection()); diff --git a/src/test/java/io/appium/java_client/android/AndroidContextTest.java b/src/test/java/io/appium/java_client/android/AndroidContextTest.java index f7d481681..363f6a139 100644 --- a/src/test/java/io/appium/java_client/android/AndroidContextTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidContextTest.java @@ -19,61 +19,16 @@ import static org.junit.Assert.assertEquals; import io.appium.java_client.NoSuchContextException; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.DesiredCapabilities; -import java.io.File; +public class AndroidContextTest extends BaseAndroidTest { -public class AndroidContextTest { - - private static AndroidDriver driver; - private static AppiumDriverLocalService service; - - /** - * initialization. - */ - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); - } - - if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120); - driver = new AndroidDriver(service.getUrl(), capabilities); + @BeforeClass public static void beforeClass2() throws Exception { driver.startActivity("io.appium.android.apis", ".view.WebView1"); Thread.sleep(20000); } - /** - * finishing. - */ - @AfterClass public static void tearDown() throws Exception { - if (driver != null) { - driver.quit(); - } - - if (service.isRunning()) { - service.stop(); - } - } - @Test public void testGetContext() { assertEquals("NATIVE_APP", driver.getContext()); } diff --git a/src/test/java/io/appium/java_client/android/IntentTest.java b/src/test/java/io/appium/java_client/android/IntentTest.java index a23b4c6af..1e700d6a4 100644 --- a/src/test/java/io/appium/java_client/android/IntentTest.java +++ b/src/test/java/io/appium/java_client/android/IntentTest.java @@ -13,7 +13,7 @@ public class IntentTest { private static AppiumDriverLocalService service; - protected static AndroidDriver driver; + protected static AndroidDriver driver; /** * initialization. diff --git a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java index 27fba4d63..a0aaaf2fc 100644 --- a/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java +++ b/src/test/java/io/appium/java_client/android/OpenNotificationsTest.java @@ -2,14 +2,33 @@ import static org.junit.Assert.assertNotEquals; +import com.google.common.base.Function; + import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.List; + public class OpenNotificationsTest extends BaseAndroidTest { @Test public void openNotification() throws Exception { + driver.closeApp(); driver.openNotifications(); - assertNotEquals(0, driver - .findElementsById("com.android.systemui:id/carrier_label").size()); - driver.openNotifications(); + WebDriverWait wait = new WebDriverWait(driver, 20); + assertNotEquals(0, wait.until(new Function>() { + @Override + public List apply(WebDriver input) { + List result = driver + .findElementsById("com.android.systemui:id/carrier_label"); + + if (result.size() == 0) { + return null; + } + + return result; + } + }).size()); } } diff --git a/src/test/java/io/appium/java_client/android/SettingTest.java b/src/test/java/io/appium/java_client/android/SettingTest.java index 5af30fb09..99470a218 100644 --- a/src/test/java/io/appium/java_client/android/SettingTest.java +++ b/src/test/java/io/appium/java_client/android/SettingTest.java @@ -1,8 +1,6 @@ package io.appium.java_client.android; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -10,14 +8,12 @@ public class SettingTest extends BaseAndroidTest { @Test public void ignoreUnimportantViewsTest() { driver.ignoreUnimportantViews(true); - boolean ignoreViews = - driver.getSettings().get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString()) - .getAsBoolean(); - assertTrue(ignoreViews); + assertEquals(true, driver.getSettings() + .get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString())); + driver.ignoreUnimportantViews(false); - ignoreViews = driver.getSettings().get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString()) - .getAsBoolean(); - assertFalse(ignoreViews); + assertEquals(false, driver.getSettings() + .get(Setting.IGNORE_UNIMPORTANT_VIEWS.toString())); } @Test public void configuratorTest() { @@ -37,8 +33,7 @@ public class SettingTest extends BaseAndroidTest { assertJSONElementContains(Setting.WAIT_FOR_SELECTOR_TIMEOUT, 1000); } - private void assertJSONElementContains(Setting setting, int value) { - assertEquals(driver.getSettings().get(setting.toString()) - .getAsInt(), value); + private void assertJSONElementContains(Setting setting, long value) { + assertEquals(driver.getSettings().get(setting.toString()), value); } } diff --git a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java index bb8d98e7e..2ccd67248 100644 --- a/src/test/java/io/appium/java_client/android/UIAutomator2Test.java +++ b/src/test/java/io/appium/java_client/android/UIAutomator2Test.java @@ -1,5 +1,7 @@ package io.appium.java_client.android; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; @@ -20,9 +22,6 @@ import java.io.File; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - public class UIAutomator2Test { private static AppiumDriverLocalService service; protected static AndroidDriver driver; diff --git a/src/test/java/io/appium/java_client/appium/AndroidTest.java b/src/test/java/io/appium/java_client/appium/AndroidTest.java new file mode 100644 index 000000000..99f5668ef --- /dev/null +++ b/src/test/java/io/appium/java_client/appium/AndroidTest.java @@ -0,0 +1,145 @@ +package io.appium.java_client.appium; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.MobileBy; +import io.appium.java_client.MobileElement; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.android.StartsActivity; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.remote.MobilePlatform; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.Response; + +import java.io.File; +import java.util.Map; + +public class AndroidTest { + + private static AppiumDriverLocalService service; + private static AppiumDriver driver; + private StartsActivity startsActivity; + + /** + * initialization. + */ + @BeforeClass + public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException( + "An appium server node is not started!"); + } + + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "ApiDemos-debug.apk"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new AppiumDriver<>(service.getUrl(), capabilities); + } + + /** + * finishing. + */ + @AfterClass + public static void afterClass() { + if (driver != null) { + driver.quit(); + } + if (service != null) { + service.stop(); + } + } + + @Before + public void setUp() throws Exception { + startsActivity = new StartsActivity() { + @Override + public Response execute(String driverCommand, Map parameters) { + return driver.execute(driverCommand, parameters); + } + + @Override + public Response execute(String driverCommand) { + return driver.execute(driverCommand); + } + }; + startsActivity.startActivity("io.appium.android.apis", ".ApiDemos"); + } + + @Test + public void findByAccessibilityIdFromDriverTest() { + assertNotEquals(driver.findElementByAccessibilityId("Graphics").getText(), null); + assertEquals(driver.findElementsByAccessibilityId("Graphics").size(), 1); + } + + @Test public void findByAndroidUIAutomatorFromDriverTest() { + assertNotEquals(driver + .findElement(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); + assertNotEquals(driver + .findElements(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); + assertNotEquals(driver + .findElements(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); + } + + @Test public void findByAccessibilityIdFromElementTest() { + assertNotEquals(driver.findElementById("android:id/content") + .findElement(MobileBy.AccessibilityId("Graphics")).getText(), null); + assertEquals(driver.findElementById("android:id/content") + .findElements(MobileBy.AccessibilityId("Graphics")).size(), 1); + } + + @Test public void findByAndroidUIAutomatorFromElementTest() { + assertNotEquals(driver.findElementById("android:id/content") + .findElement(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).getText(), null); + assertNotEquals(driver.findElementById("android:id/content") + .findElements(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 0); + assertNotEquals(driver.findElementById("android:id/content") + .findElements(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")).size(), 1); + } + + @Test public void replaceValueTest() { + String originalValue = "original value"; + + startsActivity.startActivity("io.appium.android.apis", ".view.Controls1"); + AndroidElement editElement = driver + .findElement(MobileBy + .AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")")); + editElement.sendKeys(originalValue); + assertEquals(originalValue, editElement.getText()); + String replacedValue = "replaced value"; + editElement.replaceValue(replacedValue); + assertEquals(replacedValue, editElement.getText()); + } + + @Test public void scrollingToSubElement() { + driver.findElementByAccessibilityId("Views").click(); + AndroidElement list = driver.findElement(By.id("android:id/list")); + MobileElement radioGroup = list + .findElement(MobileBy + .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(" + + "new UiSelector().text(\"Radio Group\"));")); + assertNotNull(radioGroup.getLocation()); + } + +} diff --git a/src/test/java/io/appium/java_client/appium/IOSTest.java b/src/test/java/io/appium/java_client/appium/IOSTest.java new file mode 100644 index 000000000..8469b6bd0 --- /dev/null +++ b/src/test/java/io/appium/java_client/appium/IOSTest.java @@ -0,0 +1,91 @@ +package io.appium.java_client.appium; + +import static org.junit.Assert.assertNotEquals; + +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.MobileBy; +import io.appium.java_client.ios.IOSElement; +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.remote.MobilePlatform; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.io.File; + +public class IOSTest { + private static AppiumDriverLocalService service; + private static AppiumDriver driver; + + /** + * initialization. + */ + @BeforeClass + public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException("An appium server node is not started!"); + } + + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "TestApp.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new AppiumDriver<>(service.getUrl(), capabilities); + } + + /** + * finishing. + */ + @AfterClass + public static void afterClass() { + if (driver != null) { + driver.quit(); + } + if (service != null) { + service.stop(); + } + } + + @Test + public void findByAccessibilityIdFromDriverTest() { + assertNotEquals(driver + .findElementByAccessibilityId("ComputeSumButton") + .getText(), null); + assertNotEquals(driver + .findElementsByAccessibilityId("ComputeSumButton") + .size(), 0); + } + + @Test public void findByByIosUIAutomationFromDriverTest() { + assertNotEquals(driver + .findElement(MobileBy.IosUIAutomation(".elements().withName(\"Answer\")")) + .getText(), null); + assertNotEquals(driver + .findElements(MobileBy.IosUIAutomation(".elements().withName(\"Answer\")")) + .size(), 0); + } + + @Test public void findByAccessibilityIdFromElementTest() { + assertNotEquals(driver.findElementsByClassName("UIAWindow").get(1) + .findElementsByAccessibilityId("ComputeSumButton").size(), 0); + } + + @Test public void findByByIosUIAutomationTest() { + assertNotEquals((driver.findElementsByClassName("UIAWindow") + .get(1)) + .findElementByIosUIAutomation(".elements().withName(\"Answer\")").getText(), null); + } +} diff --git a/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java b/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java index 47945dbd6..d1e9af493 100644 --- a/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java +++ b/src/test/java/io/appium/java_client/events/ExtendedEventListenerTest.java @@ -4,8 +4,6 @@ import static org.junit.Assert.assertThat; import io.appium.java_client.MobileBy; -import io.appium.java_client.android.AndroidElement; -import io.appium.java_client.events.listeners.ElementListener; import io.appium.java_client.events.listeners.SearchingListener; import io.appium.java_client.events.listeners.SingleListeners; import org.junit.BeforeClass; diff --git a/src/test/java/io/appium/java_client/ios/AppIOSTest.java b/src/test/java/io/appium/java_client/ios/AppIOSTest.java new file mode 100644 index 000000000..647160c67 --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/AppIOSTest.java @@ -0,0 +1,33 @@ +package io.appium.java_client.ios; + +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import org.junit.BeforeClass; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.io.File; + +public class AppIOSTest extends BaseIOSTest { + + @BeforeClass + public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new RuntimeException("An appium server node is not started!"); + } + + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "TestApp.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new IOSDriver<>(service.getUrl(), capabilities); + } +} diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java index 27509a6fa..63df68d2f 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSTest.java @@ -16,43 +16,13 @@ package io.appium.java_client.ios; -import io.appium.java_client.MobileElement; -import io.appium.java_client.remote.IOSMobileCapabilityType; -import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.openqa.selenium.remote.DesiredCapabilities; - -import java.io.File; public class BaseIOSTest { - private static AppiumDriverLocalService service; - protected static IOSDriver driver; - - /** - * initialization. - */ - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new RuntimeException("An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "TestApp.app.zip"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } + protected static AppiumDriverLocalService service; + protected static IOSDriver driver; /** * finishing. diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java index b4fabded0..d16cc2207 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java @@ -16,24 +16,16 @@ package io.appium.java_client.ios; -import io.appium.java_client.AppiumDriver; import io.appium.java_client.remote.IOSMobileCapabilityType; import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.AfterClass; import org.junit.BeforeClass; -import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; -public class BaseIOSWebViewTest { - protected static AppiumDriver driver; - private static AppiumDriverLocalService service; +public class BaseIOSWebViewTest extends BaseIOSTest { - /** - * initialization. - */ @BeforeClass public static void beforeClass() throws Exception { service = AppiumDriverLocalService.buildDefaultService(); service.start(); @@ -51,19 +43,6 @@ public class BaseIOSWebViewTest { capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass public static void tearDown() throws Exception { - if (driver != null) { - driver.quit(); - } - - if (service.isRunning()) { - service.stop(); - } + driver = new IOSDriver<>(service.getUrl(), capabilities); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java index 7da559e30..4c1489dee 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAlertTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAlertTest.java @@ -27,7 +27,7 @@ import org.openqa.selenium.support.ui.WebDriverWait; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class IOSAlertTest extends BaseIOSTest { +public class IOSAlertTest extends AppIOSTest { WebDriverWait waiting = new WebDriverWait(driver, 10000); static final String iOSAutomationText = ".elements().withName(\"show alert\")"; diff --git a/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java b/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java index 61d02607d..d1cb976d0 100644 --- a/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSAppStringsTest.java @@ -20,7 +20,7 @@ import org.junit.Test; -public class IOSAppStringsTest extends BaseIOSTest { +public class IOSAppStringsTest extends AppIOSTest { @Test public void getAppStrings() { assertNotEquals(0, driver.getAppStringMap().size()); diff --git a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java index 7f60192d3..b376882f4 100644 --- a/src/test/java/io/appium/java_client/ios/IOSDriverTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSDriverTest.java @@ -27,7 +27,7 @@ import org.openqa.selenium.ScreenOrientation; import org.openqa.selenium.html5.Location; -public class IOSDriverTest extends BaseIOSTest { +public class IOSDriverTest extends AppIOSTest { //TODO There is no ability to check this function usibg simulators. // When CI will have been set up then this test will be returned diff --git a/src/test/java/io/appium/java_client/ios/IOSElementTest.java b/src/test/java/io/appium/java_client/ios/IOSElementTest.java index 5eaf52a0b..b3305d720 100644 --- a/src/test/java/io/appium/java_client/ios/IOSElementTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSElementTest.java @@ -1,41 +1,47 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * 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 io.appium.java_client.ios; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThat; + +import com.google.common.base.Function; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.List; -public class IOSElementTest extends BaseIOSTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class IOSElementTest extends UICatalogIOSTest { @Test public void findByAccessibilityIdTest() { - assertNotEquals(driver.findElementsByClassName("UIAWindow").get(1) - .findElementsByAccessibilityId("ComputeSumButton").size(), 0); + assertThat((driver.findElementsByClassName("UIAWindow").get(1)) + .findElementsByAccessibilityId("Sliders").size(), + not(is(0))); } - @Test public void findByByIosUIAutomationTest() { - assertNotEquals(((IOSElement) driver.findElementsByClassName("UIAWindow") - .get(1)) - .findElementByIosUIAutomation(".elements().withName(\"Answer\")").getText(), null); - } + @Test public void setValueTest() { + driver.findElementsByClassName("UIAWindow").get(1) + .findElementByAccessibilityId("Sliders").click(); + + WebDriverWait wait = new WebDriverWait(driver, 20); - @Test public void setValuerTest() { - IOSElement slider = (IOSElement) driver.findElementByClassName("UIASlider"); + IOSElement slider = (IOSElement) wait.until(new Function>() { + @Override + public List apply(WebDriver input) { + List result = input.findElements(By.className("UIASlider")); + if (result.size() == 0) { + return null; + } + return result; + } + }).get(1); slider.setValue("0%"); assertEquals("0%", slider.getAttribute("value")); } diff --git a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java index 39b8fa1bd..7e5940a1c 100644 --- a/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSGesturesTest.java @@ -22,7 +22,7 @@ import io.appium.java_client.MultiTouchAction; import org.junit.Test; -public class IOSGesturesTest extends BaseIOSTest { +public class IOSGesturesTest extends AppIOSTest { @Test public void tapTest() { driver.findElementById("IntegerA").sendKeys("2"); diff --git a/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java b/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java index 0e55343b9..c17f4b854 100644 --- a/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSScrollingSearchingTest.java @@ -20,56 +20,9 @@ import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; -import io.appium.java_client.remote.IOSMobileCapabilityType; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; -import java.io.File; - -public class IOSScrollingSearchingTest { - - private static AppiumDriverLocalService service; - protected static IOSDriver driver; - - @BeforeClass - public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new AppiumServerHasNotBeenStartedLocallyException( - "An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "UICatalog.app.zip"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass - public static void afterClass() { - if (driver != null) { - driver.quit(); - } - if (service != null) { - service.stop(); - } - } +public class IOSScrollingSearchingTest extends UICatalogIOSTest { @Test public void scrollByDriver() { MobileElement slider = driver diff --git a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java b/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java index 15943ec7c..ff8ce5dee 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSearchingTest.java @@ -20,7 +20,7 @@ import org.junit.Test; -public class IOSSearchingTest extends BaseIOSTest { +public class IOSSearchingTest extends AppIOSTest { @Test public void findByAccessibilityIdTest() { assertNotEquals(driver diff --git a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java index 3916f2777..17706b57d 100644 --- a/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSSwipeGestureTest.java @@ -7,59 +7,13 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.SwipeElementDirection; -import io.appium.java_client.remote.IOSMobileCapabilityType; -import io.appium.java_client.remote.MobileCapabilityType; import io.appium.java_client.service.local.AppiumDriverLocalService; -import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.Point; import org.openqa.selenium.interactions.internal.Coordinates; -import org.openqa.selenium.remote.DesiredCapabilities; - -import java.io.File; - -public class IOSSwipeGestureTest { - - private static AppiumDriverLocalService service; - protected static IOSDriver driver; - - @BeforeClass - public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - if (service == null || !service.isRunning()) { - throw new AppiumServerHasNotBeenStartedLocallyException( - "An appium server node is not started!"); - } - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "UICatalog.app.zip"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } - /** - * finishing. - */ - @AfterClass - public static void afterClass() { - if (driver != null) { - driver.quit(); - } - if (service != null) { - service.stop(); - } - } +public class IOSSwipeGestureTest extends UICatalogIOSTest { @After public void afterMethod() { driver.resetApp(); diff --git a/src/test/java/io/appium/java_client/ios/UICatalogIOSTest.java b/src/test/java/io/appium/java_client/ios/UICatalogIOSTest.java new file mode 100644 index 000000000..29962fc0f --- /dev/null +++ b/src/test/java/io/appium/java_client/ios/UICatalogIOSTest.java @@ -0,0 +1,35 @@ +package io.appium.java_client.ios; + +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumDriverLocalService; +import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; +import org.junit.BeforeClass; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.io.File; + +public class UICatalogIOSTest extends BaseIOSTest { + + @BeforeClass + public static void beforeClass() throws Exception { + service = AppiumDriverLocalService.buildDefaultService(); + service.start(); + + if (service == null || !service.isRunning()) { + throw new AppiumServerHasNotBeenStartedLocallyException( + "An appium server node is not started!"); + } + + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "UICatalog.app.zip"); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); + capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); + capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + //sometimes environment has performance problems + capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + driver = new IOSDriver<>(service.getUrl(), capabilities); + } +} diff --git a/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java b/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java index 2b1f3a1f9..40a1c1917 100644 --- a/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java +++ b/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.remote.AndroidMobileCapabilityType; @@ -45,7 +44,7 @@ public class StartingAppLocallyTest { capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM); - AndroidDriver driver = new AndroidDriver<>(capabilities); + AndroidDriver driver = new AndroidDriver<>(capabilities); try { Capabilities caps = driver.getCapabilities(); @@ -72,7 +71,7 @@ public class StartingAppLocallyTest { new AppiumServiceBuilder().withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS); - AndroidDriver driver = new AndroidDriver<>(builder, capabilities); + AndroidDriver driver = new AndroidDriver<>(builder, capabilities); try { Capabilities caps = driver.getCapabilities(); @@ -109,7 +108,7 @@ public class StartingAppLocallyTest { clientCapabilities .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); - AndroidDriver driver = new AndroidDriver<>(builder, clientCapabilities); + AndroidDriver driver = new AndroidDriver<>(builder, clientCapabilities); try { Capabilities caps = driver.getCapabilities(); @@ -147,7 +146,7 @@ public class StartingAppLocallyTest { clientCapabilities .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); - AndroidDriver driver = new AndroidDriver<>(builder, clientCapabilities); + AndroidDriver driver = new AndroidDriver<>(builder, clientCapabilities); try { Capabilities caps = driver.getCapabilities(); @@ -171,7 +170,7 @@ public class StartingAppLocallyTest { capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.APPIUM); - IOSDriver driver = new IOSDriver<>(capabilities); + IOSDriver driver = new IOSDriver<>(capabilities); try { Capabilities caps = driver.getCapabilities(); @@ -206,7 +205,7 @@ public class StartingAppLocallyTest { new AppiumServiceBuilder().withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS); - IOSDriver driver = new IOSDriver<>(builder, capabilities); + IOSDriver driver = new IOSDriver<>(builder, capabilities); try { Capabilities caps = driver.getCapabilities(); assertEquals(true, @@ -232,7 +231,7 @@ public class StartingAppLocallyTest { AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); - IOSDriver driver = new IOSDriver<>(builder, clientCapabilities); + IOSDriver driver = new IOSDriver<>(builder, clientCapabilities); try { Capabilities caps = driver.getCapabilities(); assertEquals(true, @@ -259,7 +258,7 @@ public class StartingAppLocallyTest { new AppiumServiceBuilder().withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS).withCapabilities(serverCapabilities); - IOSDriver driver = new IOSDriver<>(builder, clientCapabilities); + IOSDriver driver = new IOSDriver<>(builder, clientCapabilities); try { Capabilities caps = driver.getCapabilities(); assertEquals(true, diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java index 748e04a56..5bc6ca93d 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/AndroidPageObjectTest.java @@ -23,40 +23,31 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.TouchableElement; -import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.android.BaseAndroidTest; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; import io.appium.java_client.pagefactory.SelendroidFindBy; import io.appium.java_client.pagefactory.iOSFindBy; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.internal.WrapsDriver; -import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.support.CacheLookup; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; -import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -public class AndroidPageObjectTest { +public class AndroidPageObjectTest extends BaseAndroidTest { - private static WebDriver driver; - private static AppiumDriverLocalService service; private boolean populated = false; @FindBy(className = "android.widget.TextView") @@ -166,7 +157,7 @@ public class AndroidPageObjectTest { private WebElement textAndroidId; @AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/text1\")") - private TouchableElement touchabletextVieW; + private TouchableElement touchabletextVieW; @iOSFindBy(uiAutomator = ".elements()[0]") @FindBy(css = "e.e1.e2") private List elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy; @@ -184,34 +175,6 @@ public class AndroidPageObjectTest { @FindBy(className = "android.widget.TextView") private MobileElement cached; - /** - * initialization. - */ - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new AndroidDriver<>(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass public static void afterClass() throws Exception { - if (driver != null) { - driver.quit(); - } - - if (service != null) { - service.stop(); - } - } - /** * The setting up. */ @@ -354,12 +317,12 @@ public class AndroidPageObjectTest { } @Test - @SuppressWarnings("unused") public void isTheFieldAndroidElement() { AndroidElement androidElement = (AndroidElement) mobiletextVieW; //declared as MobileElement androidElement = (AndroidElement) androidTextView; //declared as WedElement androidElement = (AndroidElement) remotetextVieW; //declared as RemoteWedElement androidElement = (AndroidElement) touchabletextVieW; //declared as TouchABLEElement + assertNotNull(androidElement); } @Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() { diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java index df269a4fe..f7151caf5 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/IOSPageFactoryTest.java @@ -23,38 +23,28 @@ import io.appium.java_client.MobileElement; import io.appium.java_client.TouchableElement; -import io.appium.java_client.ios.IOSDriver; -import io.appium.java_client.ios.IOSElement; +import io.appium.java_client.ios.AppIOSTest; +import io.appium.java_client.ios.IOSElement; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; import io.appium.java_client.pagefactory.iOSFindBy; -import io.appium.java_client.remote.IOSMobileCapabilityType; -import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebElement; import org.openqa.selenium.support.CacheLookup; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; -import java.io.File; import java.util.List; -public class IOSPageFactoryTest { +public class IOSPageFactoryTest extends AppIOSTest { - private static WebDriver driver; - private static AppiumDriverLocalService service; private boolean populated = false; @FindBy(className = "UIAButton") @@ -110,7 +100,7 @@ public class IOSPageFactoryTest { private MobileElement mobileButton; @iOSFindBy(uiAutomator = ".elements()[0]") - private TouchableElement touchableButton; + private TouchableElement touchableButton; @iOSFindBy(uiAutomator = ".elements()[0]") private List touchableButtons; @@ -147,38 +137,6 @@ public class IOSPageFactoryTest { @AndroidFindBy(className = "android.widget.TextView") @FindBy(css = "e.e1.e2") private WebElement elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy; - /** - * initialization. - */ - @BeforeClass public static void beforeClass() throws Exception { - service = AppiumDriverLocalService.buildDefaultService(); - service.start(); - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "TestApp.app.zip"); - DesiredCapabilities capabilities = new DesiredCapabilities(); - capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, ""); - capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); - capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - //sometimes environment has performance problems - capabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); - capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - driver = new IOSDriver<>(service.getUrl(), capabilities); - } - - /** - * finishing. - */ - @AfterClass public static void afterClass() throws Exception { - if (driver != null) { - driver.quit(); - } - - if (service != null) { - service.stop(); - } - } - /** * The setting up. */ @@ -303,13 +261,13 @@ public class IOSPageFactoryTest { assertNotEquals(0, touchableButtons.size()); } - @SuppressWarnings("unused") @Test public void isTheFieldIOSElement() { IOSElement iOSElement = (IOSElement) mobileButton; //declared as MobileElement iOSElement = (IOSElement) iosUIAutomatorButton; //declared as WebElement iOSElement = (IOSElement) remotetextVieW; //declared as RemoteWebElement iOSElement = (IOSElement) touchableButton; //declared as TouchABLEElement + assertNotNull(iOSElement); } @Test public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy() { diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java index 707661bc3..fe6e501a9 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/SelendroidModeTest.java @@ -25,6 +25,7 @@ import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.AndroidElement; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.HowToUseLocators; @@ -50,7 +51,7 @@ public class SelendroidModeTest { private static int SELENDROID_PORT = 9999; - private static AppiumDriver driver; + private static AppiumDriver driver; private static AppiumDriverLocalService service; private boolean populated = false; @@ -106,7 +107,7 @@ public class SelendroidModeTest { capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); capabilities.setCapability(AndroidMobileCapabilityType.SELENDROID_PORT, SELENDROID_PORT); capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.SELENDROID); - driver = new AndroidDriver(service.getUrl(), capabilities); + driver = new AndroidDriver<>(service.getUrl(), capabilities); driver.context("NATIVE_APP"); } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java index dd7ea5a84..ab491514c 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/AndroidOverrideWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -24,7 +25,7 @@ public class AndroidOverrideWidgetTest implements WidgetTest { - private static AndroidDriver driver; + private static AndroidDriver driver; private static AppiumDriverLocalService service; private static RottenTomatoes rottenTomatoes; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/IOSOverrideWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/IOSOverrideWidgetTest.java index 04825a147..4946946c9 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/IOSOverrideWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/IOSOverrideWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -30,7 +31,7 @@ public class IOSOverrideWidgetTest implements WidgetTest { private static AppiumDriverLocalService service; private static RottenTomatoes rottenTomatoes; - private IOSDriver driver; + private IOSDriver driver; /** * initialization. diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/PartiallyOverrideNegativeWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/PartiallyOverrideNegativeWidgetTest.java index 25f9e48ee..1df5c6d22 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/PartiallyOverrideNegativeWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/PartiallyOverrideNegativeWidgetTest.java @@ -1,6 +1,7 @@ package io.appium.java_client.pagefactory_tests.widgets; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -17,7 +18,7 @@ public class PartiallyOverrideNegativeWidgetTest { - private static AndroidDriver driver; + private static AndroidDriver driver; private static AppiumDriverLocalService service; private static PartiallyOverrideRottenTomatoes rottenTomatoes; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/SelendroidOverrideWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/SelendroidOverrideWidgetTest.java index 03b8d9dd5..759ca2b38 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/SelendroidOverrideWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/SelendroidOverrideWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -27,7 +28,7 @@ public class SelendroidOverrideWidgetTest implements WidgetTest { private static AppiumDriverLocalService service; - private AndroidDriver driver; + private AndroidDriver driver; private RottenTomatoes rottenTomatoes; private TimeOutDuration duration; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java index 4eaf2d3c1..714340caa 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/android/AndroidWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -24,7 +25,7 @@ public class AndroidWidgetTest implements WidgetTest { - private static AndroidDriver driver; + private static AndroidDriver driver; private static AppiumDriverLocalService service; private static RottenTomatoesApp rottenTomatoesApp; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java index e7ae2e8d9..0a7c5d220 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/AndroidCombinedWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -24,7 +25,7 @@ public class AndroidCombinedWidgetTest implements WidgetTest { - private static AndroidDriver driver; + private static AndroidDriver driver; private static AppiumDriverLocalService service; private static RottenTomatoesAppWithCombinedWidgets rottenTomatoes; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java index f381960e3..d0696b686 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/combined/SelendroidCombinedWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -28,7 +29,7 @@ public class SelendroidCombinedWidgetTest implements WidgetTest { private static AppiumDriverLocalService service; - private AndroidDriver driver; + private AndroidDriver driver; private RottenTomatoesAppWithCombinedWidgets rottenTomatoes; private TimeOutDuration duration; diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/IOSWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/IOSWidgetTest.java index b6ff73608..b883eb2ae 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/IOSWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/IOSWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.ios.IOSDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -27,7 +28,7 @@ public class IOSWidgetTest implements WidgetTest { private static AppiumDriverLocalService service; - private IOSDriver driver; + private IOSDriver driver; private RottenTomatoesIOSApp rottenTomatoesApp; /** diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/simple/IOSMovie.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/simple/IOSMovie.java index dc790164b..432783bdc 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/simple/IOSMovie.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/ios/simple/IOSMovie.java @@ -29,6 +29,6 @@ protected IOSMovie(WebElement element) { } @Override public void goToReview() { - ((TouchableElement) getWrappedElement()).tap(1, 1500); + TouchableElement.class.cast(getWrappedElement()).tap(1, 1500); } } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/selendroid/SelendroidWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/selendroid/SelendroidWidgetTest.java index d1a6c3f78..a2b04350e 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widgets/selendroid/SelendroidWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widgets/selendroid/SelendroidWidgetTest.java @@ -3,6 +3,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AppiumFieldDecorator; import io.appium.java_client.pagefactory.TimeOutDuration; @@ -29,7 +30,7 @@ public class SelendroidWidgetTest implements WidgetTest { private static AppiumDriverLocalService service; TimeOutDuration duration; - private AndroidDriver driver; + private AndroidDriver driver; private RottenTomatoesSelendroidApp rottenTomatoesApp; /**