”Scroll Gestures”-‘UiScrollable’ | How to perform “scrollBackward”-(i.e. moves exactly one view)

Please go through the below video for complete details:
Summary:
UiScrollable:
UiScrollable is a UiCollection
and provides support for searching for items in a scrollable user interface (UI) elements. This class can be used with horizontally or vertically scrollable controls.
UiScrollable(UiSelector container)
UiScrollable is a UiCollection
and as such requires a UiSelector
to identify the container UI element of the scrollable collection.
Option-1:
scrollBackward (int steps)
Perform a scroll backward. If this list is set to vertical (see setAsVerticalList()
default) then the swipes will be executed from the top to bottom. If this list is set to horizontal (see setAsHorizontalList()
) then the swipes will be executed from the left to right. Caution is required on devices configured with right to left languages like Arabic and Hebrew.
Parameters
steps use steps to control the speed, so that it may be a scroll, or fling
Returns
- true if scrolled and false if the control can’t scroll anymore
Throws
UiObjectNotFoundException
Option-2:
scrollBackward ()
scrollBackward(int)
Returns
- true if scrolled and false if the control can’t scroll anymore
Throws
UiObjectNotFoundException
Syntax:
"new UiScrollable(new UiSelector().scrollable(true)).scrollBackward(n)"));
Example:
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).scrollBackward(100)"));
Code:
package demo;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.*;
import java.time.Duration;
/**
* Script Details - "Scroll Gestures” -‘UiScrollable’ | How to perform "scrollBackward"-(i.e. moves exactly one view)
*
* appium-java-client version: 9.3.0
*
* @author 'Ramesh Kodumuru' for AppiumGuide [appiumguide@gmail.com]
*/
public class ScrollBackwardDEmo {
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(10));
}
@Test
public void test1() throws InterruptedException {
driver.activateApp("io.appium.android.apis");
driver.findElement(AppiumBy.accessibilityId("Views")).click();
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).scrollToEnd(3)"));
Thread.sleep(3000);
driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).scrollBackward(100)"));
}
@AfterTest
public void teardown() {
if(driver!=null) {
driver.quit();
System.out.println("Test Execution Completed");
}
}
}
GitHub Link:
No comments:
Post a Comment