Skip to content

Commit 7bc291d

Browse files
committed
Merge pull request appium#130 from TikhomirovSergey/master
appium#129 fix
2 parents 10eba88 + 4977cb8 commit 7bc291d

File tree

5 files changed

+455
-289
lines changed

5 files changed

+455
-289
lines changed
Lines changed: 84 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,84 @@
1-
/*
2-
+Copyright 2014 Appium contributors
3-
+Copyright 2014 Software Freedom Conservancy
4-
+
5-
+Licensed under the Apache License, Version 2.0 (the "License");
6-
+you may not use this file except in compliance with the License.
7-
+You may obtain a copy of the License at
8-
+
9-
+ http://www.apache.org/licenses/LICENSE-2.0
10-
+
11-
+Unless required by applicable law or agreed to in writing, software
12-
+distributed under the License is distributed on an "AS IS" BASIS,
13-
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
+See the License for the specific language governing permissions and
15-
+limitations under the License.
16-
+ */
17-
18-
package io.appium.java_client;
19-
20-
import com.google.common.collect.ImmutableMap;
21-
import org.openqa.selenium.By;
22-
import org.openqa.selenium.Dimension;
23-
import org.openqa.selenium.Point;
24-
import org.openqa.selenium.WebElement;
25-
import org.openqa.selenium.remote.FileDetector;
26-
import org.openqa.selenium.remote.RemoteWebElement;
27-
28-
import java.util.List;
29-
30-
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId {
31-
32-
protected FileDetector fileDetector;
33-
34-
public List<WebElement> findElements(By by) {
35-
return by.findElements(this);
36-
}
37-
38-
public WebElement findElement(By by) {
39-
return by.findElement(this);
40-
}
41-
42-
public WebElement findElementByAccessibilityId(String using) {
43-
return findElement("accessibility id", using);
44-
}
45-
46-
public List<WebElement> findElementsByAccessibilityId(String using) {
47-
return findElements("accessibility id", using);
48-
}
49-
50-
public void setValue(String value) {
51-
ImmutableMap.Builder builder = ImmutableMap.builder();
52-
builder.put("id", id).put("value", value);
53-
execute(MobileCommand.SET_VALUE, builder.build());
54-
}
55-
56-
public Point getCenter() {
57-
Point upperLeft = this.getLocation();
58-
Dimension dimensions = this.getSize();
59-
return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2);
60-
}
61-
}
1+
/*
2+
+Copyright 2014 Appium contributors
3+
+Copyright 2014 Software Freedom Conservancy
4+
+
5+
+Licensed under the Apache License, Version 2.0 (the "License");
6+
+you may not use this file except in compliance with the License.
7+
+You may obtain a copy of the License at
8+
+
9+
+ http://www.apache.org/licenses/LICENSE-2.0
10+
+
11+
+Unless required by applicable law or agreed to in writing, software
12+
+distributed under the License is distributed on an "AS IS" BASIS,
13+
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
+See the License for the specific language governing permissions and
15+
+limitations under the License.
16+
+ */
17+
18+
package io.appium.java_client;
19+
20+
import com.google.common.collect.ImmutableMap;
21+
22+
import org.openqa.selenium.By;
23+
import org.openqa.selenium.Dimension;
24+
import org.openqa.selenium.Point;
25+
import org.openqa.selenium.WebElement;
26+
import org.openqa.selenium.remote.FileDetector;
27+
import org.openqa.selenium.remote.RemoteWebDriver;
28+
import org.openqa.selenium.remote.RemoteWebElement;
29+
30+
import java.util.List;
31+
32+
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement {
33+
34+
protected FileDetector fileDetector;
35+
36+
public List<WebElement> findElements(By by) {
37+
return by.findElements(this);
38+
}
39+
40+
public WebElement findElement(By by) {
41+
return by.findElement(this);
42+
}
43+
44+
public WebElement findElementByAccessibilityId(String using) {
45+
return findElement("accessibility id", using);
46+
}
47+
48+
public List<WebElement> findElementsByAccessibilityId(String using) {
49+
return findElements("accessibility id", using);
50+
}
51+
52+
public void setValue(String value) {
53+
ImmutableMap.Builder builder = ImmutableMap.builder();
54+
builder.put("id", id).put("value", value);
55+
execute(MobileCommand.SET_VALUE, builder.build());
56+
}
57+
58+
public Point getCenter() {
59+
Point upperLeft = this.getLocation();
60+
Dimension dimensions = this.getSize();
61+
return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2);
62+
}
63+
64+
@Override
65+
public void pinch() {
66+
((AppiumDriver) parent).pinch(this);
67+
}
68+
69+
@Override
70+
public void tap(int fingers, int duration) {
71+
((AppiumDriver) parent).tap(fingers, this, duration);
72+
}
73+
74+
@Override
75+
public void zoom() {
76+
((AppiumDriver) parent).zoom(this);
77+
}
78+
79+
80+
@Override
81+
public void swipe(SwipeElementDirection direction, int duration) {
82+
direction.swipe((AppiumDriver) parent, this, duration);
83+
}
84+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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, 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+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.appium.java_client;
2+
3+
import org.openqa.selenium.WebElement;
4+
5+
/**
6+
* It supposed that mobile elements could be tappable, swipeable, zoomable and so on.
7+
* This interface extends {@link WebElement} and describes this behavior.
8+
*/
9+
public interface TouchableElement extends WebElement {
10+
11+
/**
12+
* Convenience method for pinching the given element.
13+
* "pinching" refers to the action of two appendages pressing the screen and sliding towards each other.
14+
* NOTE:
15+
* This convenience method places the initial touches around the element, if this would happen to place one of them
16+
* off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api
17+
* instead of this method.
18+
*
19+
*/
20+
public void pinch();
21+
22+
/**
23+
* Convenience method for tapping the center of the given element
24+
*
25+
* @param fingers
26+
* number of fingers/appendages to tap with
27+
* @param duration
28+
* how long between pressing down, and lifting fingers/appendages
29+
*/
30+
public void tap(int fingers, int duration);
31+
32+
/**
33+
* Convenience method for "zooming in" on the given element.
34+
* "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other.
35+
* NOTE:
36+
* This convenience method slides touches away from the element, if this would happen to place one of them
37+
* off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api
38+
* instead of this method.
39+
*/
40+
public void zoom();
41+
42+
/**
43+
* Convenience method for swiping on the given element to the given direction
44+
*
45+
* @param direction UP, DOWN, LEFT, RIGHT
46+
*
47+
* @param duration amount of time in milliseconds for the entire swipe action to
48+
* take
49+
*/
50+
public void swipe(SwipeElementDirection direction, int duration);
51+
52+
}

0 commit comments

Comments
 (0)