buttons

”Scroll Gestures”-‘UiScrollable’ | How to perform/define “No of Scrolls”by using UiScrollable Class

 

”Scroll Gestures”-‘UiScrollable’ | How to perform/define “No of Scrolls”by using UiScrollable Class

Please go through the below video for complete details:

Summary:

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 is a UiCollection and as such requires a UiSelector to identify the container UI element of the scrollable collection.

Perform a scroll search for a UI element matching the UiSelector selector argument. See scrollDescriptionIntoView(String) and scrollTextIntoView(String).

Parameters

selector UiSelector selector

Returns

  • true if the item was found and now is in view else false

Throws

UiObjectNotFoundException

#getChildByDescription(String, boolean) and #getChildByText(String, boolean) use an arguments that specifies if scrolling is allowed while searching for the UI element. The number of scrolls allowed to perform a search can be modified by this method. The current value can be read by calling getMaxSearchSwipes()

Parameters

swipesis the number of search swipes until abort

Syntax:

"new UiScrollable(new UiSelector().scrollable(true)).setMaxSearchSwipes(2)" +
".scrollIntoView(new UiSelector().text(\"<text>\"))"));

Example:

driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setMaxSearchSwipes(2)" +
".scrollIntoView(new UiSelector().text(\"Tabs\"))"));

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.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.*;
import java.time.Duration;

/**
* Script Details - 6:"Scroll Gestures”-‘UiScrollable’-How to perform/define "No of Scrolls"by using UiScrollable Class
*
* appium-java-client version: 9.3.0
*
* @author 'Ramesh Kodumuru' for AppiumGuide [appiumguide@gmail.com]
*/


public class NoofScrollsDemo {

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() {

driver.activateApp("io.appium.android.apis");

driver.findElement(AppiumBy.accessibilityId("Views")).click();

driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setMaxSearchSwipes(1)" +
".scrollIntoView(new UiSelector().text(\"Tabs\"))"));

driver.pressKey(new KeyEvent(AndroidKey.BACK));

driver.findElement(AppiumBy.accessibilityId("Views")).click();


driver.findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).setMaxSearchSwipes(2)" +
".scrollIntoView(new UiSelector().text(\"Tabs\"))"));
}



@AfterTest
public void teardown() {

if(driver!=null) {
driver.quit();
System.out.println("Test Execution Completed");

}

}

}



GitHub Link:

No comments:

Post a Comment