Performing Scrolling and Swiping in Appium using PointerInput in Java

Scrolling and swiping are important gestures in mobile app testing using Appium. These gestures allow you to interact with your app and test its functionality. The PointerInput class in Java provides a powerful way to perform these gestures using Appium. In this post, we'll show you how to use PointerInput to perform scrolling and swiping in Appium with Java.

What is PointerInput?

PointerInput is a class in the Java client library for Appium that provides a way to perform gestures like tap, swipe, and scroll. It's a low-level API that allows you to create custom gestures using pointer events. With PointerInput, you can create complex gestures that are not possible with the standard Appium API.

How to Perform Scrolling and Swiping using PointerInput

To perform scrolling or swiping in Appium using PointerInput, you need to follow these steps:

  1. Create a new PointerInput instance.
  2. Create a new sequence for the gesture.
  3. Add actions to the sequence for the starting point, move, and release.
  4. Use the Appium driver to perform the sequence on the device.

Here's an example of how to perform scrolling and swiping using PointerInput in Appium with Java:

 
// create a new PointerInput instance
PointerInput pointerInput = new PointerInput(PointerInput.Kind.TOUCH, "finger1");
// create a new sequence
Sequence sequence = new Sequence(pointerInput, 0);
// create a move action for the starting point
PointerMoveAction moveAction1 = pointerInput.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), x1, y1);
// create a press action for the starting point
PointerDownAction downAction = pointerInput.createPointerDown(PointerInput.MouseButton.LEFT.asArg());
// add the move and press actions to the sequence
sequence.addAction(moveAction1);
sequence.addAction(downAction);

// create a move action for the ending point
PointerMoveAction moveAction2 = pointerInput.createPointerMove(Duration.ofMillis(1000), PointerInput.Origin.viewport(), x2, y2);
// create a release action for the ending point
PointerUpAction upAction = pointerInput.createPointerUp(PointerInput.MouseButton.LEFT.asArg());
// add the move and release actions to the sequence
sequence.addAction(moveAction2);
sequence.addAction(upAction);

// perform the sequence action
driver.perform(Arrays.asList(sequence));

In this example, we create a new PointerInput instance and use it to create a sequence that contains a press, move, and release action for performing scrolling or swiping. We then use the perform method of the Appium driver to execute the sequence on the device.

Conclusion

In this post, we showed you how to perform scrolling and swiping in Appium using PointerInput in Java. By using PointerInput, you can create complex gestures that are not possible with the standard Appium API. With this knowledge, you can improve your mobile app testing and ensure that your app functions as expected. 



Kindly Share This Post »»

Responses

0 Respones to "Appium scrolling and swiping with PointerInput in Java"

Post a Comment

 
HOME | Freshers | Exp | Java | SQL | Walkins | OffCampus | BankJobs
=*= PRIVACY POLICY And DISCLAIMER =*=
Some of the stuff contained this site are found on internetThis site is not responsible for publishing all available Information as well accuracy, please check posted Information with its original sources, e.g. News Papers/ Websites etc.We collect all the Information form the Internet.
Software My Zimbio
Copyright © 2013 Career+ Blog +Google | Disclaimer | Privacy Policy | Contact