Pages

Appium- Actions

Mouse Actions: 

Mouse Move To:

Move the mouse by an offset of the specificed element

If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. If the element is not visible, it will be scrolled into view.

Actions action = new Actions(driver);
action.moveTo(element, 10, 10);
action.perform();

Click Action:

Click any mouse button at the current mouse coordinates

Actions action = new Actions(driver);
action.moveTo(element);
action.click();
action.perform();

Double Click Action:

Double-clicks at the current mouse coordinates (set by moveto).

Actions action = new Actions(driver);
action.moveTo(element);
action.doubleClick();
action.perform();

Button Down Action:

Click and hold the left mouse button at the current mouse coordinates.

Note that the next mouse-related command that should follow is buttonup . Any other mouse command (such as click or another call to buttondown) will yield undefined behavior


Actions action = new Actions(driver);
action.moveTo(element);
action.clickAndHold();
action.perform();

Button Up Action

Releases the mouse button previously held

Must be called once for every buttondown command issued. See the note in click and buttondown about implications of out-of-order commands.

Actions action = new Actions(driver);
action.moveTo(element);
action.clickAndHold();
action.moveTo(element, 10, 10);
action.release();
action.perform();

Touch Action

Tap

Single tap on the touch enabled device

TouchActions action = new TouchActions(driver);
action.singleTap(element);
action.perform();

Double Action

Double tap on the touch screen using finger motion events

TouchActions action = new TouchActions(driver);
action.doubleTap(element);
action.perform();

Move To:

Finger move on the screen

As of Appium 1.8.0 all move actions take coordinates that are absolute.

TouchActions action = new TouchActions(driver);
action.down(10, 10);
action.moveTo(50, 50);
action.perform();

Touch Down:

Finger down on the screen

TouchActions action = new TouchActions(driver);
action.down(10, 10);
action.move(50, 50);
action.perform();

Touch Up:

Finger up on the screen

TouchActions action = new TouchActions(driver);
action.down(10, 10);
action.up(20, 20);
action.perform();

Long Press

Long press on the touch screen using finger motion events

TouchActions action = new TouchActions(driver);
action.longPress(element);
action.perform();

Scroll:

Scroll on the touch screen using finger based motion events

TouchActions action = new TouchActions(driver);
action.scroll(element, 10, 100);
action.perform();

OR//scroll for the option
 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"webview\"));");
		
		

Flick

Flick on the touch screen using finger motion events

TouchActions action = new TouchActions(driver);
action.flick(element, 1, 10, 10);
action.perform();

Perform Multi Touch Action

Perform a multi touch action sequence

TouchActions actionOne = new TouchAction();
actionOne.press(10, 10);
actionOne.moveTo(10, 100);
actionOne.release();
TouchActions actionTwo = new TouchAction();
actionTwo.press(20, 20);
actionTwo.moveTo(20, 200);
actionTwo.release();
MultiTouchAction action = new MultiTouchAction();
action.add(actionOne);
action.add(actionTwo);
action.perform();

Touch Action 

Perform a touch action sequence

TouchAction action = new TouchAction(driver);
action.press(10, 10);
action.moveTo(10, 100);
action.release();
action.perform();

Perform a chain or multiple chains of keyboard and pointer (touch, mouse, stylus) actions

  • input source: Represents an input device (pointer or key) that a series of actions are dispatched to. The input source has a unique ID.
  • action: An action that is dispatched to an input source. For a keyboard source, this can be 'keyDown' or 'keyUp'. For a pointer event this can be 'pointerMove', 'pointerDown', or 'pointerUp'. 'pause' events can also be sent to the device.

The Actions API takes a list of input sources and executes each 'tick'. A 'tick' is a slice of an action chain, so if you have two input sources, the first 'tick' is the 0-indexed action, the second 'tick' is the 1-indexed action, etc.... All of the actions per tick are executed concurrently.


WebElement source = (MobileElement) driver.findElementsByAccessibilityId("SomeAccessibilityID");
WebElement target = (MobileElement) driver.findElementsByAccessibilityId("SomeOtherAccessibilityID");

Point source = dragMe.getCenter();
Point target = driver.findElementByAccessibilityId("dropzone").getCenter();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence dragNDrop = new Sequence(finger, 1);
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(0),
                    PointerInput.Origin.viewport(), source.x, source.y));
dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
dragNDrop.addAction(finger.createPointerMove(Duration.ofMillis(700),
                    PointerInput.Origin.viewport(),target.x, target.y));
dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(dragNDrop));






No comments:

Post a Comment

Note: Only a member of this blog may post a comment.