|
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.Response; |
| 74 | +import org.openqa.selenium.remote.html5.RemoteLocationContext; |
| 75 | +import org.openqa.selenium.remote.http.HttpMethod; |
| 76 | + |
| 77 | +import com.google.common.collect.ImmutableList; |
| 78 | +import com.google.common.collect.ImmutableMap; |
| 79 | +import com.google.gson.JsonObject; |
| 80 | +import com.google.gson.JsonParser; |
| 81 | + |
| 82 | +@SuppressWarnings("unchecked") |
| 83 | +public abstract class AppiumDriver<RequiredElementType extends WebElement> extends DefaultGenericMobileDriver<RequiredElementType> { |
45 | 84 |
|
46 | 85 | private final static ErrorHandler errorHandler = new ErrorHandler( |
47 | 86 | new ErrorCodesMobile(), true); |
@@ -71,40 +110,47 @@ protected static Capabilities substituteMobilePlatform( |
71 | 110 | return dc; |
72 | 111 | } |
73 | 112 |
|
74 | | - public MobileElement findElement(By by){ |
75 | | - return (MobileElement) super.findElement(by); |
| 113 | + @Override |
| 114 | + public List<RequiredElementType> findElements(By by){ |
| 115 | + return super.findElements(by); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public List<RequiredElementType> findElementsById(String id){ |
| 120 | + return super.findElementsById(id); |
76 | 121 | } |
77 | 122 |
|
78 | | - public MobileElement findElementById(String using){ |
79 | | - return (MobileElement) super.findElementById(using); |
| 123 | + public List<RequiredElementType> findElementsByLinkText(String using) { |
| 124 | + return super.findElementsByLinkText(using); |
80 | 125 | } |
81 | 126 |
|
82 | | - public MobileElement findElementByClassName(String using){ |
83 | | - return (MobileElement) super.findElementByClassName(using); |
| 127 | + public List<RequiredElementType> findElementsByPartialLinkText(String using) { |
| 128 | + return super.findElementsByPartialLinkText(using); |
84 | 129 | } |
85 | 130 |
|
86 | | - public MobileElement findElementByName(String using){ |
87 | | - return (MobileElement) super.findElementByName(using); |
| 131 | + public List<RequiredElementType> findElementsByTagName(String using) { |
| 132 | + return super.findElementsByTagName(using); |
88 | 133 | } |
89 | 134 |
|
90 | | - public MobileElement findElementByTagName(String using){ |
91 | | - return (MobileElement) super.findElementByTagName(using); |
| 135 | + public List<RequiredElementType> findElementsByName(String using) { |
| 136 | + return super.findElementsByName(using); |
92 | 137 | } |
93 | 138 |
|
94 | | - public MobileElement findElementByCssSelector(String using){ |
95 | | - return (MobileElement) super.findElementByCssSelector(using); |
96 | | -} |
| 139 | + public List<RequiredElementType> findElementsByClassName(String using) { |
| 140 | + return super.findElementsByClassName(using); |
| 141 | + } |
97 | 142 |
|
98 | | - public MobileElement findElementByLinkText(String using){ |
99 | | - return (MobileElement) super.findElementByLinkText(using); |
| 143 | + public List<RequiredElementType> findElementsByCssSelector(String using) { |
| 144 | + return super.findElementsByCssSelector(using); |
100 | 145 | } |
101 | 146 |
|
102 | | - public MobileElement findElementByPartialLinkText(String using){ |
103 | | - return (MobileElement) super.findElementByPartialLinkText(using); |
| 147 | + public List<RequiredElementType> findElementsByXPath(String using) { |
| 148 | + return super.findElementsByXPath(using); |
104 | 149 | } |
105 | 150 |
|
106 | | - public MobileElement findElementByXPath(String using){ |
107 | | - return (MobileElement) super.findElementByXPath(using); |
| 151 | + @Override |
| 152 | + public List<RequiredElementType> findElementsByAccessibilityId(String using) { |
| 153 | + return (List<RequiredElementType>) findElements("accessibility id", using); |
108 | 154 | } |
109 | 155 |
|
110 | 156 | /** |
@@ -210,15 +256,9 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { |
210 | 256 | super.setErrorHandler(errorHandler); |
211 | 257 | } |
212 | 258 |
|
213 | | - @Override |
214 | | - public Response execute(String driverCommand, Map<String, ?> parameters) { |
215 | | - |
216 | | - return super.execute(driverCommand, parameters); |
217 | | - } |
218 | | - |
219 | 259 | @Override |
220 | 260 | protected Response execute(String command) { |
221 | | - return execute(command, ImmutableMap.<String, Object> of()); |
| 261 | + return super.execute(command, ImmutableMap.<String, Object>of()); |
222 | 262 | } |
223 | 263 |
|
224 | 264 | @Override |
@@ -335,7 +375,7 @@ public TouchAction performTouchAction(TouchAction touchAction) { |
335 | 375 | * @see PerformsTouchActions#performMultiTouchAction(MultiTouchAction) |
336 | 376 | */ |
337 | 377 | @Override |
338 | | - @SuppressWarnings({ "rawtypes", "unchecked" }) |
| 378 | + @SuppressWarnings({ "rawtypes"}) |
339 | 379 | public void performMultiTouchAction(MultiTouchAction multiAction) { |
340 | 380 | ImmutableMap<String, ImmutableList> parameters = multiAction |
341 | 381 | .getParameters(); |
@@ -562,7 +602,6 @@ public WebDriver context(String name) { |
562 | 602 | return AppiumDriver.this; |
563 | 603 | } |
564 | 604 |
|
565 | | - @SuppressWarnings("unchecked") |
566 | 605 | @Override |
567 | 606 | public Set<String> getContextHandles() { |
568 | 607 | Response response = execute(DriverCommand.GET_CONTEXT_HANDLES); |
@@ -607,16 +646,6 @@ public ScreenOrientation getOrientation() { |
607 | 646 | } |
608 | 647 | } |
609 | 648 |
|
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 | 649 | @Override |
621 | 650 | public Location location() { |
622 | 651 | return locationContext.location(); |
|
0 commit comments