-
-
Notifications
You must be signed in to change notification settings - Fork 766
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#160 fixed parameter names and comments.
- Loading branch information
1 parent
166a0cb
commit 3a07643
Showing
2 changed files
with
161 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,82 @@ | ||
/* | ||
+Copyright 2014 Appium contributors | ||
+Copyright 2014 Software Freedom Conservancy | ||
+ | ||
+Licensed under the Apache License, Version 2.0 (the "License"); | ||
+you may not use this file except in compliance with the License. | ||
+You may obtain a copy of the License at | ||
+ | ||
+ http://www.apache.org/licenses/LICENSE-2.0 | ||
+ | ||
+Unless required by applicable law or agreed to in writing, software | ||
+distributed under the License is distributed on an "AS IS" BASIS, | ||
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
+See the License for the specific language governing permissions and | ||
+limitations under the License. | ||
+ */ | ||
|
||
package io.appium.java_client; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.Dimension; | ||
import org.openqa.selenium.Point; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.remote.FileDetector; | ||
import org.openqa.selenium.remote.RemoteWebElement; | ||
|
||
import java.util.List; | ||
|
||
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement { | ||
|
||
protected FileDetector fileDetector; | ||
|
||
public List<WebElement> findElements(By by) { | ||
return by.findElements(this); | ||
} | ||
|
||
public WebElement findElement(By by) { | ||
return by.findElement(this); | ||
} | ||
|
||
public WebElement findElementByAccessibilityId(String using) { | ||
return findElement("accessibility id", using); | ||
} | ||
|
||
public List<WebElement> findElementsByAccessibilityId(String using) { | ||
return findElements("accessibility id", using); | ||
} | ||
|
||
public Point getCenter() { | ||
Point upperLeft = this.getLocation(); | ||
Dimension dimensions = this.getSize(); | ||
return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); | ||
} | ||
|
||
@Override | ||
public void pinch() { | ||
((AppiumDriver) parent).pinch(this); | ||
} | ||
|
||
@Override | ||
public void tap(int fingers, int duration) { | ||
((AppiumDriver) parent).tap(fingers, this, duration); | ||
} | ||
|
||
@Override | ||
public void zoom() { | ||
((AppiumDriver) parent).zoom(this); | ||
} | ||
|
||
|
||
@Override | ||
public void swipe(SwipeElementDirection direction, int duration) { | ||
direction.swipe((AppiumDriver) parent, this, 0, 0, duration); | ||
} | ||
|
||
@Override | ||
public void swipe(SwipeElementDirection direction, int offset1, | ||
int offset2, int duration) throws IllegalCoordinatesException { | ||
direction.swipe((AppiumDriver) parent, this, offset1, offset2, duration); | ||
} | ||
} | ||
/* | ||
+Copyright 2014 Appium contributors | ||
+Copyright 2014 Software Freedom Conservancy | ||
+ | ||
+Licensed under the Apache License, Version 2.0 (the "License"); | ||
+you may not use this file except in compliance with the License. | ||
+You may obtain a copy of the License at | ||
+ | ||
+ http://www.apache.org/licenses/LICENSE-2.0 | ||
+ | ||
+Unless required by applicable law or agreed to in writing, software | ||
+distributed under the License is distributed on an "AS IS" BASIS, | ||
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
+See the License for the specific language governing permissions and | ||
+limitations under the License. | ||
+ */ | ||
|
||
package io.appium.java_client; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.Dimension; | ||
import org.openqa.selenium.Point; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.remote.FileDetector; | ||
import org.openqa.selenium.remote.RemoteWebElement; | ||
|
||
import java.util.List; | ||
|
||
public abstract class MobileElement extends RemoteWebElement implements FindsByAccessibilityId, TouchableElement { | ||
|
||
protected FileDetector fileDetector; | ||
|
||
public List<WebElement> findElements(By by) { | ||
return by.findElements(this); | ||
} | ||
|
||
public WebElement findElement(By by) { | ||
return by.findElement(this); | ||
} | ||
|
||
public WebElement findElementByAccessibilityId(String using) { | ||
return findElement("accessibility id", using); | ||
} | ||
|
||
public List<WebElement> findElementsByAccessibilityId(String using) { | ||
return findElements("accessibility id", using); | ||
} | ||
|
||
public Point getCenter() { | ||
Point upperLeft = this.getLocation(); | ||
Dimension dimensions = this.getSize(); | ||
return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); | ||
} | ||
|
||
@Override | ||
public void pinch() { | ||
((AppiumDriver) parent).pinch(this); | ||
} | ||
|
||
@Override | ||
public void tap(int fingers, int duration) { | ||
((AppiumDriver) parent).tap(fingers, this, duration); | ||
} | ||
|
||
@Override | ||
public void zoom() { | ||
((AppiumDriver) parent).zoom(this); | ||
} | ||
|
||
|
||
@Override | ||
public void swipe(SwipeElementDirection direction, int duration) { | ||
direction.swipe((AppiumDriver) parent, this, 0, 0, duration); | ||
} | ||
|
||
@Override | ||
public void swipe(SwipeElementDirection direction, int offsetFromStartBorder, | ||
int offsetFromEndBorder, int duration) throws IllegalCoordinatesException { | ||
direction.swipe((AppiumDriver) parent, this, offsetFromStartBorder, | ||
offsetFromEndBorder, duration); | ||
} | ||
} |
155 changes: 79 additions & 76 deletions
155
src/main/java/io/appium/java_client/TouchableElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,79 @@ | ||
package io.appium.java_client; | ||
|
||
import org.openqa.selenium.WebElement; | ||
|
||
/** | ||
* It supposed that mobile elements could be tappable, swipeable, zoomable and so on. | ||
* This interface extends {@link WebElement} and describes this behavior. | ||
*/ | ||
public interface TouchableElement extends WebElement { | ||
|
||
/** | ||
* Convenience method for pinching the given element. | ||
* "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. | ||
* NOTE: | ||
* This convenience method places the initial touches around the element, if this would happen to place one of them | ||
* off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api | ||
* instead of this method. | ||
* | ||
*/ | ||
public void pinch(); | ||
|
||
/** | ||
* Convenience method for tapping the center of the given element | ||
* | ||
* @param fingers | ||
* number of fingers/appendages to tap with | ||
* @param duration | ||
* how long between pressing down, and lifting fingers/appendages | ||
*/ | ||
public void tap(int fingers, int duration); | ||
|
||
/** | ||
* Convenience method for "zooming in" on the given element. | ||
* "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. | ||
* NOTE: | ||
* This convenience method slides touches away from the element, if this would happen to place one of them | ||
* off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api | ||
* instead of this method. | ||
*/ | ||
public void zoom(); | ||
|
||
/** | ||
* Convenience method for swiping on the given element to the given direction | ||
* | ||
* @param direction UP, DOWN, LEFT, RIGHT | ||
* | ||
* @param duration amount of time in milliseconds for the entire swipe action to | ||
* take | ||
*/ | ||
public void swipe(SwipeElementDirection direction, int duration); | ||
|
||
|
||
/** | ||
* Convenience method for swiping on the given element to the given direction | ||
* | ||
* @param direction direction UP, DOWN, LEFT, RIGHT | ||
* | ||
* @param offset1 is the offset from the border of the element. If direction is UP then | ||
* this is offset from the bottom of the element. If direction is DOWN then | ||
* this is offset from the top of the element. If direction is RIGHT then | ||
* this is offset from the left border of the element. If direction is LEFT then | ||
* this is offset from the right border of the element. | ||
* | ||
* @param offset2 is the offset from the border of the element. If direction is UP then | ||
* this is offset from the top of the element. If direction is DOWN then | ||
* this is offset from the bottom of the element. If direction is RIGHT then | ||
* this is offset from the right border of the element. If direction is LEFT then | ||
* this is offset from the left border of the element. | ||
* | ||
* @param duration amount of time in milliseconds for the entire swipe action to | ||
* take | ||
* @throws IllegalCoordinatesException when resulted coordinates are out of the element borders | ||
* or disagree with the given direction | ||
*/ | ||
public void swipe(SwipeElementDirection direction, int offset1, int offset2, int duration) throws IllegalCoordinatesException; | ||
} | ||
package io.appium.java_client; | ||
|
||
import org.openqa.selenium.WebElement; | ||
|
||
/** | ||
* It supposed that mobile elements could be tappable, swipeable, zoomable and so on. | ||
* This interface extends {@link WebElement} and describes this behavior. | ||
*/ | ||
public interface TouchableElement extends WebElement { | ||
|
||
/** | ||
* Convenience method for pinching the given element. | ||
* "pinching" refers to the action of two appendages pressing the screen and sliding towards each other. | ||
* NOTE: | ||
* This convenience method places the initial touches around the element, if this would happen to place one of them | ||
* off the screen, appium with return an outOfBounds error. In this case, revert to using the MultiTouchAction api | ||
* instead of this method. | ||
* | ||
*/ | ||
public void pinch(); | ||
|
||
/** | ||
* Convenience method for tapping the center of the given element | ||
* | ||
* @param fingers | ||
* number of fingers/appendages to tap with | ||
* @param duration | ||
* how long between pressing down, and lifting fingers/appendages | ||
*/ | ||
public void tap(int fingers, int duration); | ||
|
||
/** | ||
* Convenience method for "zooming in" on the given element. | ||
* "zooming in" refers to the action of two appendages pressing the screen and sliding away from each other. | ||
* NOTE: | ||
* This convenience method slides touches away from the element, if this would happen to place one of them | ||
* off the screen, appium will return an outOfBounds error. In this case, revert to using the MultiTouchAction api | ||
* instead of this method. | ||
*/ | ||
public void zoom(); | ||
|
||
/** | ||
* Convenience method for swiping on the given element to the given direction | ||
* | ||
* @param direction UP, DOWN, LEFT, RIGHT | ||
* | ||
* @param duration amount of time in milliseconds for the entire swipe action to | ||
* take | ||
*/ | ||
public void swipe(SwipeElementDirection direction, int duration); | ||
|
||
|
||
/** | ||
* Convenience method for swiping on the given element to the given direction | ||
* | ||
* @param direction direction UP, DOWN, LEFT, RIGHT | ||
* | ||
* @param offsetFromEndBorder is the offset from the border of the element where the swiping should be started. | ||
* If direction is UP then | ||
* this is offset from the bottom of the element. If direction is DOWN then | ||
* this is offset from the top of the element. If direction is RIGHT then | ||
* this is offset from the left border of the element. If direction is LEFT then | ||
* this is offset from the right border of the element. | ||
* | ||
* @param offsetFromEndBorder is the offset from the border of the element where the swiping should be finished. | ||
* If direction is UP then | ||
* this is offset from the top of the element. If direction is DOWN then | ||
* this is offset from the bottom of the element. If direction is RIGHT then | ||
* this is offset from the right border of the element. If direction is LEFT then | ||
* this is offset from the left border of the element. | ||
* | ||
* @param duration amount of time in milliseconds for the entire swipe action to | ||
* take | ||
* @throws IllegalCoordinatesException when resulted coordinates are out of the element borders | ||
* or disagree with the given direction | ||
*/ | ||
public void swipe(SwipeElementDirection direction, int offsetFromStartBorder, | ||
int offsetFromEndBorder, int duration) throws IllegalCoordinatesException; | ||
} |