Skip to content

Commit 4881341

Browse files
committed
Merge pull request #182 from TikhomirovSergey/returning_of_mobileelement
Generic AppiumDriver #178 #162 fix
2 parents 80e9131 + e2676a0 commit 4881341

Some content is hidden

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

48 files changed

+641
-212
lines changed

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,19 @@
123123
<plugin>
124124
<groupId>org.apache.maven.plugins</groupId>
125125
<artifactId>maven-compiler-plugin</artifactId>
126-
<version>2.3.2</version>
126+
<version>3.3</version>
127127
<configuration>
128128
<source>1.7</source>
129129
<target>1.7</target>
130+
<compilerId>eclipse</compilerId>
130131
</configuration>
132+
<dependencies>
133+
<dependency>
134+
<groupId>org.codehaus.plexus</groupId>
135+
<artifactId>plexus-compiler-eclipse</artifactId>
136+
<version>2.5</version>
137+
</dependency>
138+
</dependencies>
131139
</plugin>
132140
</plugins>
133141
</build>

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

Lines changed: 97 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,81 @@
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.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> {
4595

4696
private final static ErrorHandler errorHandler = new ErrorHandler(
4797
new ErrorCodesMobile(), true);
@@ -71,40 +121,47 @@ protected static Capabilities substituteMobilePlatform(
71121
return dc;
72122
}
73123

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);
76132
}
77133

78-
public MobileElement findElementById(String using){
79-
return (MobileElement) super.findElementById(using);
134+
public List<RequiredElementType> findElementsByLinkText(String using) {
135+
return super.findElementsByLinkText(using);
80136
}
81137

82-
public MobileElement findElementByClassName(String using){
83-
return (MobileElement) super.findElementByClassName(using);
138+
public List<RequiredElementType> findElementsByPartialLinkText(String using) {
139+
return super.findElementsByPartialLinkText(using);
84140
}
85141

86-
public MobileElement findElementByName(String using){
87-
return (MobileElement) super.findElementByName(using);
142+
public List<RequiredElementType> findElementsByTagName(String using) {
143+
return super.findElementsByTagName(using);
88144
}
89145

90-
public MobileElement findElementByTagName(String using){
91-
return (MobileElement) super.findElementByTagName(using);
146+
public List<RequiredElementType> findElementsByName(String using) {
147+
return super.findElementsByName(using);
92148
}
93149

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

98-
public MobileElement findElementByLinkText(String using){
99-
return (MobileElement) super.findElementByLinkText(using);
154+
public List<RequiredElementType> findElementsByCssSelector(String using) {
155+
return super.findElementsByCssSelector(using);
100156
}
101157

102-
public MobileElement findElementByPartialLinkText(String using){
103-
return (MobileElement) super.findElementByPartialLinkText(using);
158+
public List<RequiredElementType> findElementsByXPath(String using) {
159+
return super.findElementsByXPath(using);
104160
}
105161

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);
108165
}
109166

110167
/**
@@ -210,15 +267,9 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) {
210267
super.setErrorHandler(errorHandler);
211268
}
212269

213-
@Override
214-
public Response execute(String driverCommand, Map<String, ?> parameters) {
215-
216-
return super.execute(driverCommand, parameters);
217-
}
218-
219270
@Override
220271
protected Response execute(String command) {
221-
return execute(command, ImmutableMap.<String, Object> of());
272+
return super.execute(command, ImmutableMap.<String, Object>of());
222273
}
223274

224275
@Override
@@ -335,7 +386,7 @@ public TouchAction performTouchAction(TouchAction touchAction) {
335386
* @see PerformsTouchActions#performMultiTouchAction(MultiTouchAction)
336387
*/
337388
@Override
338-
@SuppressWarnings({ "rawtypes", "unchecked" })
389+
@SuppressWarnings({ "rawtypes"})
339390
public void performMultiTouchAction(MultiTouchAction multiAction) {
340391
ImmutableMap<String, ImmutableList> parameters = multiAction
341392
.getParameters();
@@ -562,7 +613,6 @@ public WebDriver context(String name) {
562613
return AppiumDriver.this;
563614
}
564615

565-
@SuppressWarnings("unchecked")
566616
@Override
567617
public Set<String> getContextHandles() {
568618
Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);
@@ -607,16 +657,6 @@ public ScreenOrientation getOrientation() {
607657
}
608658
}
609659

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-
620660
@Override
621661
public Location location() {
622662
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)