buttons

 

Appium Gestures-(Part-3)-Perform ‘FlingGesture’ based on element & direction — down

Please go through the below video for complete details:

package demo;

public class FlingDownDemo {

private AndroidDriver driver;


@BeforeTest
public void setup() throws MalformedURLException {
UiAutomator2Options cap=new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setDeviceName("Pixel8Pro");


driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(100));

}

@Test
public void test() throws InterruptedException {
driver.activateApp("com.android.vending");
Thread.sleep(3000);

driver.pressKey(new KeyEvent(AndroidKey.APP_SWITCH));
Thread.sleep(3000);

WebElement element=driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().className(\"android.view.View\").instance(1)"));

//perform fling gesture based on element & direction is down
System.out.println("perform fling gesture based on element & direction is down");

int speedvalue=(int)(7500*2.625);

boolean canFlingMore=(boolean)((JavascriptExecutor)driver).executeScript("mobile: flingGesture",ImmutableMap.of(
"elementId",((RemoteWebElement)element).getId(),
"direction","down",
"speed",speedvalue));

}


@AfterTest
public void teardown() {

if(driver!=null) {
driver.quit();
}

}

}

For Android: Have total 9 W3C Mobile Gestures Commands

mobile: clickGesture

mobile: doubleClickGesture

mobile: longClickGesture

mobile: pinchCloseGesture

mobile: pinchOpenGesture

mobile: swipeGesture

mobile: scrollGesture

mobile: dragGesture

mobile: flingGesture

Complete Details on “flingGesture” Command:

mobile: flingGesture : performs fling gesture on the given element/area.

Supported arguments:

elementId: The id of the element to be flinged. If the element id is missing then fling bounding area must be provided. If both the element id and the fling bounding area are provided then this area is effectively ignored.

left: The left coordinate of the fling bounding area

top: The top coordinate of the fling bounding area

width: The width of the fling bounding area

height: The height of the fling bounding area

direction: Direction of the fling. Mandatory value. Acceptable values are: up, down, left and right (case insensitive)

speed: The speed at which to perform this gesture in pixels per second. The value must be greater than the minimum fling velocity for the given view (50 by default). The default value is 7500 * displayDensity

Returned value:

The returned value is a boolean one and equals to true if the object can still scroll in the given direction

Example : // Java

boolean canFlingMore = (Boolean) ((JavascriptExecutor) driver).executeScript(“mobile: flingGesture”, ImmutableMap.of(

“elementId”, ((RemoteWebElement) element).getId(),

“direction”, “down”,

“speed”, 500

));

Sample Code:

//perform fling gesture based on element & direction is down

WebElement element=driver.findElement(AppiumBy.androidUIAutomator(“new UiSelector().className(\”android.view.View\”).instance(1)”));

System.out.println(“perform fling gesture based on element & direction is down”);

int speedvalue=(int)(7500*2.625);

boolean canFlingMore=(boolean)((JavascriptExecutor)driver).executeScript(“mobile: flingGesture”,ImmutableMap.of(

“elementId”,((RemoteWebElement)element).getId(),

“direction”,”down”,

“speed”,speedvalue));

GitHub Link:


No comments:

Post a Comment