Skip to content

Commit 0dc816c

Browse files
#160 Enum SwipeElementDirection is redesigned.
I have to redesign coordinate calculation and add the new swipe-method to MobileElement.
1 parent 7d3dc11 commit 0dc816c

File tree

3 files changed

+80
-58
lines changed

3 files changed

+80
-58
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.appium.java_client;
2+
3+
import org.openqa.selenium.WebDriverException;
4+
5+
public class IllegalCoordinatesException extends WebDriverException {
6+
private static final long serialVersionUID = 1L;
7+
8+
public IllegalCoordinatesException(String message) {
9+
super(message);
10+
}
11+
12+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public void zoom() {
7070

7171
@Override
7272
public void swipe(SwipeElementDirection direction, int duration) {
73-
direction.swipe((AppiumDriver) parent, this, duration);
73+
direction.swipe((AppiumDriver) parent, this, 0, 0, 0, 0, duration);
7474
}
7575
}
Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,67 @@
1-
package io.appium.java_client;
2-
3-
import org.openqa.selenium.Dimension;
4-
import org.openqa.selenium.Point;
5-
6-
public enum SwipeElementDirection {
7-
/**
8-
* Up from the center of the lower
9-
*/
10-
UP{
11-
@Override
12-
void swipe(AppiumDriver driver, MobileElement element, int duration){
13-
Point p = element.getCenter();
14-
Point location = element.getLocation();
15-
Dimension size = element.getSize();
16-
driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration);
17-
}
18-
},
19-
/**
20-
* Down from the center of the upper
21-
*/
22-
DOWN{
23-
@Override
24-
void swipe(AppiumDriver driver, MobileElement element, int duration){
25-
Point p = element.getCenter();
26-
Point location = element.getLocation();
27-
Dimension size = element.getSize();
28-
driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration);
29-
}
30-
},
31-
/**
32-
* To the left from the center of the rightmost
33-
*/
34-
LEFT{
35-
@Override
36-
void swipe(AppiumDriver driver, MobileElement element, int duration){
37-
Point p = element.getCenter();
38-
Point location = element.getLocation();
39-
Dimension size = element.getSize();
40-
driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration);
41-
}
42-
},
43-
/**
44-
* To the right from the center of the leftmost
45-
*/
46-
RIGHT{
47-
@Override
48-
void swipe(AppiumDriver driver, MobileElement element, int duration){
49-
Point p = element.getCenter();
50-
Point location = element.getLocation();
51-
Dimension size = element.getSize();
52-
driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration);
53-
}
54-
};
55-
56-
void swipe(AppiumDriver driver, MobileElement element, int duration){}
57-
}
1+
package io.appium.java_client;
2+
3+
import org.openqa.selenium.Dimension;
4+
import org.openqa.selenium.Point;
5+
6+
public enum SwipeElementDirection {
7+
/**
8+
* Up from the center of the lower
9+
*/
10+
UP{
11+
@Override
12+
void swipe(AppiumDriver driver, MobileElement element,
13+
int xOffsetStart, int xOffsetEnd, int yOffsetStart,
14+
int yOffsetEnd, int duration) throws IllegalCoordinatesException {
15+
Point p = element.getCenter();
16+
Point location = element.getLocation();
17+
Dimension size = element.getSize();
18+
driver.swipe(p.getX(), location.getY() + size.getHeight(), p.getX(), location.getY(), duration);
19+
}
20+
},
21+
/**
22+
* Down from the center of the upper
23+
*/
24+
DOWN{
25+
@Override
26+
void swipe(AppiumDriver driver, MobileElement element,
27+
int xOffsetStart, int xOffsetEnd, int yOffsetStart,
28+
int yOffsetEnd, int duration) throws IllegalCoordinatesException {
29+
Point p = element.getCenter();
30+
Point location = element.getLocation();
31+
Dimension size = element.getSize();
32+
driver.swipe(p.getX(), location.getY(), p.getX(), location.getY() + size.getHeight(), duration);
33+
}
34+
},
35+
/**
36+
* To the left from the center of the rightmost
37+
*/
38+
LEFT{
39+
@Override
40+
void swipe(AppiumDriver driver, MobileElement element,
41+
int xOffsetStart, int xOffsetEnd, int yOffsetStart,
42+
int yOffsetEnd, int duration) throws IllegalCoordinatesException {
43+
Point p = element.getCenter();
44+
Point location = element.getLocation();
45+
Dimension size = element.getSize();
46+
driver.swipe(location.getX() + size.getWidth(), p.getY(), location.getX(), p.getY(), duration);
47+
}
48+
},
49+
/**
50+
* To the right from the center of the leftmost
51+
*/
52+
RIGHT{
53+
@Override
54+
void swipe(AppiumDriver driver, MobileElement element,
55+
int xOffsetStart, int xOffsetEnd, int yOffsetStart,
56+
int yOffsetEnd, int duration) throws IllegalCoordinatesException {
57+
Point p = element.getCenter();
58+
Point location = element.getLocation();
59+
Dimension size = element.getSize();
60+
driver.swipe(location.getX(), p.getY(), location.getX()+ size.getWidth(), p.getY(), duration);
61+
}
62+
};
63+
64+
abstract void swipe(AppiumDriver driver, MobileElement element,
65+
int xOffsetStart, int xOffsetEnd, int yOffsetStart,
66+
int yOffsetEnd, int duration) throws IllegalCoordinatesException;
67+
}

0 commit comments

Comments
 (0)