Skip to content

Commit ca56f7b

Browse files
1 parent ceeaaeb commit ca56f7b

47 files changed

Lines changed: 617 additions & 235 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 86 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
+Copyright 2014 Appium contributors
3-
+Copyright 2014 Software Freedom Conservancy
2+
+Copyright 2014-2015 Appium contributors
3+
+Copyright 2014-2015 Software Freedom Conservancy
44
+
55
+Licensed under the Apache License, Version 2.0 (the "License");
66
+you may not use this file except in compliance with the License.
@@ -17,31 +17,70 @@
1717

1818
package io.appium.java_client;
1919

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;
2449
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;
3150

32-
import javax.xml.bind.DatatypeConverter;
3351
import java.net.URL;
3452
import java.util.LinkedHashSet;
3553
import java.util.List;
36-
import java.util.Map;
3754
import java.util.Set;
3855

39-
import static io.appium.java_client.MobileCommand.*;
56+
import javax.xml.bind.DatatypeConverter;
4057

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> {
4584

4685
private final static ErrorHandler errorHandler = new ErrorHandler(
4786
new ErrorCodesMobile(), true);
@@ -71,40 +110,47 @@ protected static Capabilities substituteMobilePlatform(
71110
return dc;
72111
}
73112

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);
76121
}
77122

78-
public MobileElement findElementById(String using){
79-
return (MobileElement) super.findElementById(using);
123+
public List<RequiredElementType> findElementsByLinkText(String using) {
124+
return super.findElementsByLinkText(using);
80125
}
81126

82-
public MobileElement findElementByClassName(String using){
83-
return (MobileElement) super.findElementByClassName(using);
127+
public List<RequiredElementType> findElementsByPartialLinkText(String using) {
128+
return super.findElementsByPartialLinkText(using);
84129
}
85130

86-
public MobileElement findElementByName(String using){
87-
return (MobileElement) super.findElementByName(using);
131+
public List<RequiredElementType> findElementsByTagName(String using) {
132+
return super.findElementsByTagName(using);
88133
}
89134

90-
public MobileElement findElementByTagName(String using){
91-
return (MobileElement) super.findElementByTagName(using);
135+
public List<RequiredElementType> findElementsByName(String using) {
136+
return super.findElementsByName(using);
92137
}
93138

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+
}
97142

98-
public MobileElement findElementByLinkText(String using){
99-
return (MobileElement) super.findElementByLinkText(using);
143+
public List<RequiredElementType> findElementsByCssSelector(String using) {
144+
return super.findElementsByCssSelector(using);
100145
}
101146

102-
public MobileElement findElementByPartialLinkText(String using){
103-
return (MobileElement) super.findElementByPartialLinkText(using);
147+
public List<RequiredElementType> findElementsByXPath(String using) {
148+
return super.findElementsByXPath(using);
104149
}
105150

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);
108154
}
109155

110156
/**
@@ -210,15 +256,9 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
210256
super.setErrorHandler(errorHandler);
211257
}
212258

213-
@Override
214-
public Response execute(String driverCommand, Map<String, ?> parameters) {
215-
216-
return super.execute(driverCommand, parameters);
217-
}
218-
219259
@Override
220260
protected Response execute(String command) {
221-
return execute(command, ImmutableMap.<String, Object> of());
261+
return super.execute(command, ImmutableMap.<String, Object>of());
222262
}
223263

224264
@Override
@@ -335,7 +375,7 @@ public TouchAction performTouchAction(TouchAction touchAction) {
335375
* @see PerformsTouchActions#performMultiTouchAction(MultiTouchAction)
336376
*/
337377
@Override
338-
@SuppressWarnings({ "rawtypes", "unchecked" })
378+
@SuppressWarnings({ "rawtypes"})
339379
public void performMultiTouchAction(MultiTouchAction multiAction) {
340380
ImmutableMap<String, ImmutableList> parameters = multiAction
341381
.getParameters();
@@ -562,7 +602,6 @@ public WebDriver context(String name) {
562602
return AppiumDriver.this;
563603
}
564604

565-
@SuppressWarnings("unchecked")
566605
@Override
567606
public Set<String> getContextHandles() {
568607
Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);
@@ -607,16 +646,6 @@ public ScreenOrientation getOrientation() {
607646
}
608647
}
609648

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-
620649
@Override
621650
public Location location() {
622651
return locationContext.location();

src/main/java/io/appium/java_client/AppiumExecutionMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import java.util.Map;
88

99
public class AppiumExecutionMethod implements ExecuteMethod {
10-
private final AppiumDriver driver;
10+
private final AppiumDriver<?> driver;
1111

12-
public AppiumExecutionMethod(AppiumDriver driver) {
12+
public AppiumExecutionMethod(AppiumDriver<?> driver) {
1313
this.driver = driver;
1414
}
1515

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package io.appium.java_client;
2+
3+
import io.appium.java_client.MobileDriver;
4+
import io.appium.java_client.generic.searchcontext.*;
5+
6+
import org.openqa.selenium.By;
7+
import org.openqa.selenium.Capabilities;
8+
import org.openqa.selenium.WebElement;
9+
import org.openqa.selenium.remote.RemoteWebDriver;
10+
import org.openqa.selenium.remote.Response;
11+
12+
import java.net.URL;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@SuppressWarnings({ "unchecked", "rawtypes" })
17+
abstract class DefaultGenericMobileDriver<T extends WebElement> extends RemoteWebDriver implements MobileDriver,
18+
GenericSearchContext<T>, GenericFindsById<T>, GenericFindsByXPath<T>, GenericFindsByLinkText<T>, GenericFindsByTagName<T>,
19+
GenericFindsByClassName<T>, GenericFindsByCssSelector<T>, GenericFindsByName<T>{
20+
21+
public DefaultGenericMobileDriver(URL remoteAddress, Capabilities desiredCapabilities) {
22+
super(remoteAddress, desiredCapabilities);
23+
}
24+
25+
@Override
26+
public Response execute(String driverCommand, Map<String, ?> parameters) {
27+
return super.execute(driverCommand, parameters);
28+
}
29+
30+
@Override
31+
public List findElements(By by){
32+
return super.findElements(by);
33+
}
34+
35+
@Override
36+
public T findElement(By by){
37+
return (T) super.findElement(by);
38+
}
39+
40+
@Override
41+
public List findElementsById(String id){
42+
return super.findElementsById(id);
43+
}
44+
45+
@Override
46+
public T findElementById(String id){
47+
return (T) super.findElementById(id);
48+
}
49+
50+
public T findElementByLinkText(String using) {
51+
return (T) super.findElementByLinkText(using);
52+
}
53+
54+
public List findElementsByLinkText(String using) {
55+
return super.findElementsByLinkText(using);
56+
}
57+
58+
public T findElementByPartialLinkText(String using) {
59+
return (T) super.findElementByPartialLinkText(using);
60+
}
61+
62+
public List findElementsByPartialLinkText(String using) {
63+
return super.findElementsByPartialLinkText(using);
64+
}
65+
66+
public T findElementByTagName(String using) {
67+
return (T) super.findElementByTagName(using);
68+
}
69+
70+
public List findElementsByTagName(String using) {
71+
return super.findElementsByTagName(using);
72+
}
73+
74+
public T findElementByName(String using) {
75+
return (T) super.findElementByName(using);
76+
}
77+
78+
public List findElementsByName(String using) {
79+
return super.findElementsByName(using);
80+
}
81+
82+
public T findElementByClassName(String using) {
83+
return (T) super.findElementByClassName(using);
84+
}
85+
86+
public List findElementsByClassName(String using) {
87+
return super.findElementsByClassName(using);
88+
}
89+
90+
public T findElementByCssSelector(String using) {
91+
return (T) super.findElementByCssSelector(using);
92+
}
93+
94+
public List findElementsByCssSelector(String using) {
95+
return super.findElementsByCssSelector(using);
96+
}
97+
98+
public T findElementByXPath(String using) {
99+
return (T) super.findElementByXPath(using);
100+
}
101+
102+
public List findElementsByXPath(String using) {
103+
return super.findElementsByXPath(using);
104+
}
105+
106+
@Override
107+
public T findElementByAccessibilityId(String using) {
108+
return (T) findElement("accessibility id", using);
109+
}
110+
111+
@Override
112+
public List findElementsByAccessibilityId(String using) {
113+
return (List<T>) findElements("accessibility id", using);
114+
}
115+
}

0 commit comments

Comments
 (0)