Skip to content

Commit 2fc8e1d

Browse files
Merge pull request #536 from TikhomirovSergey/master
Partial reversion of changes related to TouchActions/MultitouchActions
2 parents ddbbbdb + fc0fcc2 commit 2fc8e1d

33 files changed

+437
-827
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ You can get it on [WIKI](https://github.com/appium/java-client/wiki)
9999
- `io.appium.java_client.ios.ShakesDevice`
100100
- `io.appium.java_client.HasSessionDetails`
101101
_That was done because Windows automation tools have some features that were considered as Android-specific and iOS-specific._
102-
- `io.appium.java_client.CreatesSwipeAction`
103102

104-
The list of methods which were marked _deprecated_ and they are going to be removed
103+
The list of classes and methods which were marked _deprecated_ and they are going to be removed
105104
- `AppiumDriver#swipe(int, int, int, int, int)`
106105
- `AppiumDriver#pinch(WebElement)`
107106
- `AppiumDriver#pinch(int, int)`
@@ -112,11 +111,14 @@ You can get it on [WIKI](https://github.com/appium/java-client/wiki)
112111
- `AppiumDriver#swipe(int, int, int, int, int)`
113112
- `MobileElement#swipe(SwipeElementDirection, int)`
114113
- `MobileElement#swipe(SwipeElementDirection, int, int, int)`
114+
- `MobileElement#zoom()`
115+
- `MobileElement#pinch()`
116+
- `MobileElement#tap(int, int)`
117+
- `io.appium.java_client.SwipeElementDirection` and `io.appium.java_client.TouchebleElement` also were marked deprecated.
115118

116119
redesign of `TouchAction` and `MultiTouchAction`
117-
- constructors were redesigned. There is no strict binding of `AppiumDriver` and `TouchAction` /`MultiTouchAction`. They can pass any instance of a class that implements `PerformsTouchActions`.
118-
- deprecated methods of `AppiumDriver`/`MobileElement` were moved to `TouchAction`/`MultiTouchAction`.
119-
- `io.appium.java_client.android.AndroidTouchAction` and `io.appium.java_client.ios.IOSTouchAction` were added. They create the swiping gesture. Both classes implement the new `io.appium.java_client.CreatesSwipeAction` API.
120+
- constructors were redesigned. There is no strict binding of `AppiumDriver` and `TouchAction` /`MultiTouchAction`. They can consume any instance of a class that implements `PerformsTouchActions`.
121+
- `io.appium.java_client.ios.IOSTouchAction` was added. It extends `io.appium.java_client.TouchAction`.
120122

121123
`JsonToMobileElementConverter` re-design [#532](https://github.com/appium/java-client/pull/532):
122124
- unused `MobileElementToJsonConverter` was removed

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

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.openqa.selenium.By;
3030
import org.openqa.selenium.Capabilities;
3131
import org.openqa.selenium.DeviceRotation;
32+
import org.openqa.selenium.Dimension;
33+
import org.openqa.selenium.Point;
3234
import org.openqa.selenium.ScreenOrientation;
3335
import org.openqa.selenium.WebDriver;
3436
import org.openqa.selenium.WebDriverException;
@@ -43,7 +45,6 @@
4345
import org.openqa.selenium.remote.Response;
4446
import org.openqa.selenium.remote.html5.RemoteLocationContext;
4547
import org.openqa.selenium.remote.http.HttpClient;
46-
import org.openqa.selenium.remote.internal.JsonToWebElementConverter;
4748

4849
import java.net.URL;
4950
import java.util.LinkedHashSet;
@@ -56,7 +57,6 @@
5657
* Instances of the defined type will be returned via findElement* and findElements*
5758
* Warning (!!!). Allowed types:
5859
* {@link org.openqa.selenium.WebElement}
59-
* {@link io.appium.java_client.TouchableElement}
6060
* {@link org.openqa.selenium.remote.RemoteWebElement}
6161
* {@link io.appium.java_client.MobileElement} and its subclasses that designed
6262
* specifically
@@ -191,36 +191,35 @@ public List<T> findElementsByXPath(String using) {
191191

192192
/**
193193
* This method is deprecated and it is going to be removed soon.
194-
* Please use {@link MultiTouchAction#tap(int, WebElement, int)}.
195194
*/
196195
@Deprecated
197196
public void tap(int fingers, WebElement element, int duration) {
198197
MultiTouchAction multiTouch = new MultiTouchAction(this);
199198

200199
for (int i = 0; i < fingers; i++) {
201-
multiTouch.add(createTap(element, duration));
200+
TouchAction tap = new TouchAction(this);
201+
multiTouch.add(tap.press(element).waitAction(duration).release());
202202
}
203203

204204
multiTouch.perform();
205205
}
206206

207207
/**
208208
* This method is deprecated and it is going to be removed soon.
209-
* Please use {@link MultiTouchAction#tap(int, int, int, int)}.
210209
*/
211210
@Deprecated
212211
public void tap(int fingers, int x, int y, int duration) {
213212
MultiTouchAction multiTouch = new MultiTouchAction(this);
214213

215214
for (int i = 0; i < fingers; i++) {
216-
multiTouch.add(createTap(x, y, duration));
215+
TouchAction tap = new TouchAction(this);
216+
multiTouch.add(tap.press(x,y).waitAction(duration).release());
217217
}
218218
multiTouch.perform();
219219
}
220220

221221
/**
222-
* This method is deprecated.
223-
* It was moved to {@link CreatesSwipeAction#swipe(int, int, int, int, int)}.
222+
* This method is deprecated. It is going to be removed
224223
*/
225224
@Deprecated
226225
public void swipe(int startx, int starty, int endx, int endy, int duration) {
@@ -229,19 +228,29 @@ public void swipe(int startx, int starty, int endx, int endy, int duration) {
229228

230229
/**
231230
* This method is deprecated and it is going to be removed soon.
232-
* Please use {@link MultiTouchAction#pinch(WebElement)}.
233231
*/
234232
@Deprecated
235233
public void pinch(WebElement el) {
236234
MultiTouchAction multiTouch = new MultiTouchAction(this);
237235

238-
multiTouch.pinch(el).perform();
236+
Dimension dimensions = el.getSize();
237+
Point upperLeft = el.getLocation();
238+
Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,
239+
upperLeft.getY() + dimensions.getHeight() / 2);
240+
int yOffset = center.getY() - upperLeft.getY();
241+
242+
TouchAction action0 =
243+
new TouchAction(this).press(el, center.getX(), center.getY() - yOffset).moveTo(el)
244+
.release();
245+
TouchAction action1 =
246+
new TouchAction(this).press(el, center.getX(), center.getY() + yOffset).moveTo(el)
247+
.release();
248+
249+
multiTouch.add(action0).add(action1).perform();
239250
}
240251

241252
/**
242253
* This method is deprecated and it is going to be removed soon.
243-
* Please use {@link MultiTouchAction#pinch(int, int, int, int)} or
244-
* {@link MultiTouchAction#pinch(int, int, int)}
245254
*/
246255
@Deprecated
247256
public void pinch(int x, int y) {
@@ -264,19 +273,27 @@ public void pinch(int x, int y) {
264273

265274
/**
266275
* This method is deprecated and it is going to be removed soon.
267-
* Please use {@link MultiTouchAction#zoom(WebElement)}.
268276
*/
269277
@Deprecated
270278
public void zoom(WebElement el) {
271279
MultiTouchAction multiTouch = new MultiTouchAction(this);
272280

273-
multiTouch.zoom(el).perform();
281+
Dimension dimensions = el.getSize();
282+
Point upperLeft = el.getLocation();
283+
Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2,
284+
upperLeft.getY() + dimensions.getHeight() / 2);
285+
int yOffset = center.getY() - upperLeft.getY();
286+
287+
TouchAction action0 = new TouchAction(this).press(center.getX(), center.getY())
288+
.moveTo(el, center.getX(), center.getY() - yOffset).release();
289+
TouchAction action1 = new TouchAction(this).press(center.getX(), center.getY())
290+
.moveTo(el, center.getX(), center.getY() + yOffset).release();
291+
292+
multiTouch.add(action0).add(action1).perform();
274293
}
275294

276295
/**
277296
* This method is deprecated and it is going to be removed soon.
278-
* Please use {@link MultiTouchAction#zoom(int, int, int, int)} or
279-
* {@link MultiTouchAction#zoom(int, int, int)}.
280297
*/
281298
@Deprecated
282299
public void zoom(int x, int y) {
@@ -364,18 +381,6 @@ public void zoom(int x, int y) {
364381
locationContext.setLocation(location);
365382
}
366383

367-
@Deprecated
368-
private TouchAction createTap(WebElement element, int duration) {
369-
TouchAction tap = new TouchAction(this);
370-
return tap.press(element).waitAction(duration).release();
371-
}
372-
373-
@Deprecated
374-
private TouchAction createTap(int x, int y, int duration) {
375-
TouchAction tap = new TouchAction(this);
376-
return tap.press(x, y).waitAction(duration).release();
377-
}
378-
379384
public URL getRemoteAddress() {
380385
return remoteAddress;
381386
}

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

Lines changed: 0 additions & 101 deletions
This file was deleted.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
import org.openqa.selenium.By;
2222
import org.openqa.selenium.WebDriverException;
2323
import org.openqa.selenium.WebElement;
24+
import org.openqa.selenium.internal.FindsByClassName;
25+
import org.openqa.selenium.internal.FindsByCssSelector;
26+
import org.openqa.selenium.internal.FindsById;
27+
import org.openqa.selenium.internal.FindsByLinkText;
28+
import org.openqa.selenium.internal.FindsByName;
29+
import org.openqa.selenium.internal.FindsByTagName;
30+
import org.openqa.selenium.internal.FindsByXPath;
2431
import org.openqa.selenium.remote.RemoteWebElement;
2532
import org.openqa.selenium.remote.Response;
2633

@@ -29,7 +36,10 @@
2936

3037
@SuppressWarnings({"unchecked", "rawtypes"})
3138
abstract class DefaultGenericMobileElement<T extends WebElement> extends RemoteWebElement
32-
implements TouchableElement<T> {
39+
implements FindsByClassName,
40+
FindsByCssSelector, FindsById,
41+
FindsByLinkText, FindsByName, FindsByTagName, FindsByXPath, FindsByFluentSelector<T>, FindsByAccessibilityId<T>,
42+
ExecutesMethod, TouchableElement<T> {
3343

3444
@Override public Response execute(String driverCommand, Map<String, ?> parameters) {
3545
return super.execute(driverCommand, parameters);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static io.appium.java_client.MobileCommand.GET_SESSION;
2020

21+
import com.google.common.collect.ImmutableMap;
22+
2123
import org.openqa.selenium.remote.Response;
2224

2325
import java.util.Map;
@@ -27,9 +29,11 @@ public interface HasSessionDetails extends ExecutesMethod {
2729
* @return a map with values that hold session details.
2830
*
2931
*/
32+
@SuppressWarnings("unchecked")
3033
default Map<String, Object> getSessionDetails() {
3134
Response response = execute(GET_SESSION);
32-
return (Map<String, Object>) response.getValue();
35+
return ImmutableMap.<String, Object>builder()
36+
.putAll(Map.class.cast(response.getValue())).build();
3337
}
3438

3539
default Object getSessionDetail(String detail) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package io.appium.java_client;
1818

19-
@SuppressWarnings("serial")
2019
public class MissingParameterException
2120
extends IllegalArgumentException {
2221

22+
private static final long serialVersionUID = 1L;
23+
2324
public MissingParameterException(String reason) {
2425
super(reason);
2526
}
2627

2728
public MissingParameterException(String reason, Throwable cause) {
2829
super(reason, cause);
2930
}
30-
3131
}

0 commit comments

Comments
 (0)