Last active
June 21, 2023 14:45
-
-
Save SarahElson/584eec685f19775260bc4a574da92e2f to your computer and use it in GitHub Desktop.
Automated App Testing Using Appium With TestNG [Tutorial]
This file contains hidden or 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
package com.lambdatest.appium.sample.utils; | |
import static io.appium.java_client.touch.WaitOptions.waitOptions; | |
import static io.appium.java_client.touch.offset.PointOption.point; | |
import static java.time.Duration.ofMillis; | |
import io.appium.java_client.AppiumDriver; | |
import io.appium.java_client.MobileElement; | |
import io.appium.java_client.TouchAction; | |
import io.appium.java_client.touch.offset.PointOption; | |
import org.openqa.selenium.Dimension; | |
// 1. | |
@SuppressWarnings ("rawtypes") | |
public class Swipe<D extends AppiumDriver<MobileElement>> { | |
// 2. | |
private final D driver; | |
public Swipe (final D driver) { | |
this.driver = driver; | |
} | |
// 3. | |
public void down () { | |
final Dimension screenDimension = this.driver.manage () | |
.window () | |
.getSize (); | |
final PointOption startPoint = point (screenDimension.getWidth () / 2, 10); | |
final PointOption endPoint = point (screenDimension.getWidth () / 2, screenDimension.getHeight () / 2); | |
perform (startPoint, endPoint); | |
} | |
// 4. | |
public void up () { | |
final Dimension screenDimension = this.driver.manage () | |
.window () | |
.getSize (); | |
final PointOption startPoint = point (screenDimension.getWidth () / 2, screenDimension.getHeight () - 10); | |
final PointOption endPoint = point (screenDimension.getWidth () / 2, 10); | |
perform (startPoint, endPoint); | |
} | |
// 5. | |
private void perform (final PointOption startPoint, final PointOption endPoint) { | |
final TouchAction action = new TouchAction (this.driver); | |
action.press (startPoint) | |
.waitAction (waitOptions (ofMillis (200))) | |
.moveTo (endPoint) | |
.release () | |
.perform (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment