I have a class called Utils were I defined some useful methods, and I have a construction which is passing me the driver( sorry still at the beginning of appium and java and I might get it wrong).
Here is my code:
package resources;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static io.appium.java_client.touch.offset.PointOption.point;
import static java.time.Duration.ofSeconds;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
public class Utils {
public static AndroidDriver<AndroidElement> driver;
public Utils(AndroidDriver<AndroidElement> driver) {
Utils.driver = driver;
}
public void swipe(int x_start, int y_start, int x_stop, int y_stop, int duration) {
new TouchAction(driver).press(point(x_start, y_start)) .waitAction(waitOptions(ofSeconds(duration)))
.moveTo(point(x_stop, y_stop)) .release() .perform();
}
The driver is initiating in my TestBase class.