|
1 | 1 | /*
|
2 |
| - +Copyright 2014 Appium contributors |
3 |
| - +Copyright 2014 Software Freedom Conservancy |
| 2 | + +Copyright 2014-2015 Appium contributors |
| 3 | + +Copyright 2014-2015 Software Freedom Conservancy |
4 | 4 | +
|
5 | 5 | +Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | +you may not use this file except in compliance with the License.
|
|
17 | 17 |
|
18 | 18 | package io.appium.java_client;
|
19 | 19 |
|
20 |
| -import com.google.common.collect.ImmutableList; |
21 |
| -import com.google.common.collect.ImmutableMap; |
22 |
| -import com.google.gson.JsonObject; |
23 |
| -import com.google.gson.JsonParser; |
| 20 | +import static io.appium.java_client.MobileCommand.CLOSE_APP; |
| 21 | +import static io.appium.java_client.MobileCommand.COMPLEX_FIND; |
| 22 | +import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY; |
| 23 | +import static io.appium.java_client.MobileCommand.END_TEST_COVERAGE; |
| 24 | +import static io.appium.java_client.MobileCommand.GET_NETWORK_CONNECTION; |
| 25 | +import static io.appium.java_client.MobileCommand.GET_SETTINGS; |
| 26 | +import static io.appium.java_client.MobileCommand.GET_STRINGS; |
| 27 | +import static io.appium.java_client.MobileCommand.HIDE_KEYBOARD; |
| 28 | +import static io.appium.java_client.MobileCommand.INSTALL_APP; |
| 29 | +import static io.appium.java_client.MobileCommand.IS_APP_INSTALLED; |
| 30 | +import static io.appium.java_client.MobileCommand.IS_LOCKED; |
| 31 | +import static io.appium.java_client.MobileCommand.KEY_EVENT; |
| 32 | +import static io.appium.java_client.MobileCommand.LAUNCH_APP; |
| 33 | +import static io.appium.java_client.MobileCommand.LOCK; |
| 34 | +import static io.appium.java_client.MobileCommand.OPEN_NOTIFICATIONS; |
| 35 | +import static io.appium.java_client.MobileCommand.PERFORM_MULTI_TOUCH; |
| 36 | +import static io.appium.java_client.MobileCommand.PERFORM_TOUCH_ACTION; |
| 37 | +import static io.appium.java_client.MobileCommand.PULL_FILE; |
| 38 | +import static io.appium.java_client.MobileCommand.PULL_FOLDER; |
| 39 | +import static io.appium.java_client.MobileCommand.PUSH_FILE; |
| 40 | +import static io.appium.java_client.MobileCommand.REMOVE_APP; |
| 41 | +import static io.appium.java_client.MobileCommand.RESET; |
| 42 | +import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND; |
| 43 | +import static io.appium.java_client.MobileCommand.SET_NETWORK_CONNECTION; |
| 44 | +import static io.appium.java_client.MobileCommand.SET_SETTINGS; |
| 45 | +import static io.appium.java_client.MobileCommand.SET_VALUE; |
| 46 | +import static io.appium.java_client.MobileCommand.SHAKE; |
| 47 | +import static io.appium.java_client.MobileCommand.START_ACTIVITY; |
| 48 | +import static io.appium.java_client.MobileCommand.TOGGLE_LOCATION_SERVICES; |
24 | 49 | import io.appium.java_client.remote.MobileCapabilityType;
|
25 |
| -import org.openqa.selenium.*; |
26 |
| -import org.openqa.selenium.html5.Location; |
27 |
| -import org.openqa.selenium.html5.LocationContext; |
28 |
| -import org.openqa.selenium.remote.*; |
29 |
| -import org.openqa.selenium.remote.html5.RemoteLocationContext; |
30 |
| -import org.openqa.selenium.remote.http.HttpMethod; |
31 | 50 |
|
32 |
| -import javax.xml.bind.DatatypeConverter; |
33 | 51 | import java.net.URL;
|
34 | 52 | import java.util.LinkedHashSet;
|
35 | 53 | import java.util.List;
|
36 |
| -import java.util.Map; |
37 | 54 | import java.util.Set;
|
38 | 55 |
|
39 |
| -import static io.appium.java_client.MobileCommand.*; |
| 56 | +import javax.xml.bind.DatatypeConverter; |
40 | 57 |
|
41 |
| -public abstract class AppiumDriver extends RemoteWebDriver implements MobileDriver, |
42 |
| - ContextAware, Rotatable, FindsByAccessibilityId, LocationContext, |
43 |
| - DeviceActionShortcuts, TouchShortcuts, InteractsWithFiles, |
44 |
| - InteractsWithApps, ScrollsTo, HasAppStrings { |
| 58 | +import org.openqa.selenium.By; |
| 59 | +import org.openqa.selenium.Capabilities; |
| 60 | +import org.openqa.selenium.Dimension; |
| 61 | +import org.openqa.selenium.Point; |
| 62 | +import org.openqa.selenium.ScreenOrientation; |
| 63 | +import org.openqa.selenium.WebDriver; |
| 64 | +import org.openqa.selenium.WebDriverException; |
| 65 | +import org.openqa.selenium.WebElement; |
| 66 | +import org.openqa.selenium.html5.Location; |
| 67 | +import org.openqa.selenium.remote.CommandInfo; |
| 68 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 69 | +import org.openqa.selenium.remote.DriverCommand; |
| 70 | +import org.openqa.selenium.remote.ErrorHandler; |
| 71 | +import org.openqa.selenium.remote.ExecuteMethod; |
| 72 | +import org.openqa.selenium.remote.HttpCommandExecutor; |
| 73 | +import org.openqa.selenium.remote.RemoteWebElement; |
| 74 | +import org.openqa.selenium.remote.Response; |
| 75 | +import org.openqa.selenium.remote.html5.RemoteLocationContext; |
| 76 | +import org.openqa.selenium.remote.http.HttpMethod; |
| 77 | + |
| 78 | +import com.google.common.collect.ImmutableList; |
| 79 | +import com.google.common.collect.ImmutableMap; |
| 80 | +import com.google.gson.JsonObject; |
| 81 | +import com.google.gson.JsonParser; |
| 82 | + |
| 83 | +/** |
| 84 | + * @param <RequiredElementType> means the required type from the list of allowed types below |
| 85 | + * that implement {@link WebElement} Instances of the defined type will be |
| 86 | + * returned via findElement* and findElements*. |
| 87 | + * Warning (!!!). Allowed types:<br/> |
| 88 | + * {@link WebElement}<br/> |
| 89 | + * {@link TouchableElement}<br/> |
| 90 | + * {@link RemoteWebElement}<br/> |
| 91 | + * {@link MobileElement} and its subclasses that designed specifically for each target mobile OS (still Android and iOS) |
| 92 | + */ |
| 93 | +@SuppressWarnings("unchecked") |
| 94 | +public abstract class AppiumDriver<RequiredElementType extends WebElement> extends DefaultGenericMobileDriver<RequiredElementType> { |
45 | 95 |
|
46 | 96 | private final static ErrorHandler errorHandler = new ErrorHandler(
|
47 | 97 | new ErrorCodesMobile(), true);
|
@@ -71,40 +121,47 @@ protected static Capabilities substituteMobilePlatform(
|
71 | 121 | return dc;
|
72 | 122 | }
|
73 | 123 |
|
74 |
| - public MobileElement findElement(By by){ |
75 |
| - return (MobileElement) super.findElement(by); |
| 124 | + @Override |
| 125 | + public List<RequiredElementType> findElements(By by){ |
| 126 | + return super.findElements(by); |
| 127 | + } |
| 128 | + |
| 129 | + @Override |
| 130 | + public List<RequiredElementType> findElementsById(String id){ |
| 131 | + return super.findElementsById(id); |
76 | 132 | }
|
77 | 133 |
|
78 |
| - public MobileElement findElementById(String using){ |
79 |
| - return (MobileElement) super.findElementById(using); |
| 134 | + public List<RequiredElementType> findElementsByLinkText(String using) { |
| 135 | + return super.findElementsByLinkText(using); |
80 | 136 | }
|
81 | 137 |
|
82 |
| - public MobileElement findElementByClassName(String using){ |
83 |
| - return (MobileElement) super.findElementByClassName(using); |
| 138 | + public List<RequiredElementType> findElementsByPartialLinkText(String using) { |
| 139 | + return super.findElementsByPartialLinkText(using); |
84 | 140 | }
|
85 | 141 |
|
86 |
| - public MobileElement findElementByName(String using){ |
87 |
| - return (MobileElement) super.findElementByName(using); |
| 142 | + public List<RequiredElementType> findElementsByTagName(String using) { |
| 143 | + return super.findElementsByTagName(using); |
88 | 144 | }
|
89 | 145 |
|
90 |
| - public MobileElement findElementByTagName(String using){ |
91 |
| - return (MobileElement) super.findElementByTagName(using); |
| 146 | + public List<RequiredElementType> findElementsByName(String using) { |
| 147 | + return super.findElementsByName(using); |
92 | 148 | }
|
93 | 149 |
|
94 |
| - public MobileElement findElementByCssSelector(String using){ |
95 |
| - return (MobileElement) super.findElementByCssSelector(using); |
96 |
| -} |
| 150 | + public List<RequiredElementType> findElementsByClassName(String using) { |
| 151 | + return super.findElementsByClassName(using); |
| 152 | + } |
97 | 153 |
|
98 |
| - public MobileElement findElementByLinkText(String using){ |
99 |
| - return (MobileElement) super.findElementByLinkText(using); |
| 154 | + public List<RequiredElementType> findElementsByCssSelector(String using) { |
| 155 | + return super.findElementsByCssSelector(using); |
100 | 156 | }
|
101 | 157 |
|
102 |
| - public MobileElement findElementByPartialLinkText(String using){ |
103 |
| - return (MobileElement) super.findElementByPartialLinkText(using); |
| 158 | + public List<RequiredElementType> findElementsByXPath(String using) { |
| 159 | + return super.findElementsByXPath(using); |
104 | 160 | }
|
105 | 161 |
|
106 |
| - public MobileElement findElementByXPath(String using){ |
107 |
| - return (MobileElement) super.findElementByXPath(using); |
| 162 | + @Override |
| 163 | + public List<RequiredElementType> findElementsByAccessibilityId(String using) { |
| 164 | + return (List<RequiredElementType>) findElements("accessibility id", using); |
108 | 165 | }
|
109 | 166 |
|
110 | 167 | /**
|
@@ -210,15 +267,9 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
|
210 | 267 | super.setErrorHandler(errorHandler);
|
211 | 268 | }
|
212 | 269 |
|
213 |
| - @Override |
214 |
| - public Response execute(String driverCommand, Map<String, ?> parameters) { |
215 |
| - |
216 |
| - return super.execute(driverCommand, parameters); |
217 |
| - } |
218 |
| - |
219 | 270 | @Override
|
220 | 271 | protected Response execute(String command) {
|
221 |
| - return execute(command, ImmutableMap.<String, Object> of()); |
| 272 | + return super.execute(command, ImmutableMap.<String, Object>of()); |
222 | 273 | }
|
223 | 274 |
|
224 | 275 | @Override
|
@@ -335,7 +386,7 @@ public TouchAction performTouchAction(TouchAction touchAction) {
|
335 | 386 | * @see PerformsTouchActions#performMultiTouchAction(MultiTouchAction)
|
336 | 387 | */
|
337 | 388 | @Override
|
338 |
| - @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 389 | + @SuppressWarnings({ "rawtypes"}) |
339 | 390 | public void performMultiTouchAction(MultiTouchAction multiAction) {
|
340 | 391 | ImmutableMap<String, ImmutableList> parameters = multiAction
|
341 | 392 | .getParameters();
|
@@ -562,7 +613,6 @@ public WebDriver context(String name) {
|
562 | 613 | return AppiumDriver.this;
|
563 | 614 | }
|
564 | 615 |
|
565 |
| - @SuppressWarnings("unchecked") |
566 | 616 | @Override
|
567 | 617 | public Set<String> getContextHandles() {
|
568 | 618 | Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);
|
@@ -607,16 +657,6 @@ public ScreenOrientation getOrientation() {
|
607 | 657 | }
|
608 | 658 | }
|
609 | 659 |
|
610 |
| - @Override |
611 |
| - public MobileElement findElementByAccessibilityId(String using) { |
612 |
| - return (MobileElement) findElement("accessibility id", using); |
613 |
| - } |
614 |
| - |
615 |
| - @Override |
616 |
| - public List<WebElement> findElementsByAccessibilityId(String using) { |
617 |
| - return findElements("accessibility id", using); |
618 |
| - } |
619 |
| - |
620 | 660 | @Override
|
621 | 661 | public Location location() {
|
622 | 662 | return locationContext.location();
|
|
0 commit comments