Java Code Examples for org.openqa.selenium.interactions.Sequence#addAction()
The following examples show how to use
org.openqa.selenium.interactions.Sequence#addAction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Edition029_W3C_Actions.java From appiumpro with Apache License 2.0 | 6 votes |
private void drawCircle (AppiumDriver driver, Point origin, double radius, int steps) { Point firstPoint = getPointOnCircle(0, steps, origin, radius); PointerInput finger = new PointerInput(Kind.TOUCH, "finger"); Sequence circle = new Sequence(finger, 0); circle.addAction(finger.createPointerMove(NO_TIME, VIEW, firstPoint.x, firstPoint.y)); circle.addAction(finger.createPointerDown(MouseButton.LEFT.asArg())); for (int i = 1; i < steps + 1; i++) { Point point = getPointOnCircle(i, steps, origin, radius); circle.addAction(finger.createPointerMove(STEP_DURATION, VIEW, point.x, point.y)); } circle.addAction(finger.createPointerUp(MouseButton.LEFT.asArg())); driver.perform(Arrays.asList(circle)); }
Example 2
Source File: Edition046_W3C_Keys.java From appiumpro with Apache License 2.0 | 6 votes |
@Test public void testLowLevelKeys() { wait.until(ExpectedConditions.presenceOfElementLocated(loginScreen)).click(); WebElement usernameField = driver.findElement(username); usernameField.click(); KeyInput keyboard = new KeyInput("keyboard"); Sequence sendKeys = new Sequence(keyboard, 0); sendKeys.addAction(keyboard.createKeyDown(Keys.SHIFT.getCodePoint())); sendKeys.addAction(keyboard.createKeyDown("f".codePointAt(0))); sendKeys.addAction(keyboard.createKeyUp("f".codePointAt(0))); sendKeys.addAction(keyboard.createKeyUp(Keys.SHIFT.getCodePoint())); sendKeys.addAction(keyboard.createKeyDown("o".codePointAt(0))); sendKeys.addAction(keyboard.createKeyUp("o".codePointAt(0))); sendKeys.addAction(keyboard.createKeyDown("o".codePointAt(0))); sendKeys.addAction(keyboard.createKeyUp("o".codePointAt(0))); driver.perform(Arrays.asList(sendKeys)); Assert.assertEquals("Foo", usernameField.getText()); }
Example 3
Source File: Edition067_Zoom_Touch_Gestures.java From appiumpro with Apache License 2.0 | 5 votes |
private Sequence zoomSinglefinger(String fingerName, Point locus, int startRadius, int endRadius, double angle, Duration duration) { PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, fingerName); Sequence fingerPath = new Sequence(finger, 0); double midpointRadius = startRadius + (endRadius > startRadius ? 1 : -1) * 20; // find coordinates for starting point of action (converting from polar coordinates to cartesian) int fingerStartx = (int)Math.floor(locus.x + startRadius * Math.cos(angle)); int fingerStarty = (int)Math.floor(locus.y - startRadius * Math.sin(angle)); // find coordinates for first point that pingers move quickly to int fingerMidx = (int)Math.floor(locus.x + (midpointRadius * Math.cos(angle))); int fingerMidy = (int)Math.floor(locus.y - (midpointRadius * Math.sin(angle))); // find coordinates for ending point of action (converting from polar coordinates to cartesian) int fingerEndx = (int)Math.floor(locus.x + endRadius * Math.cos(angle)); int fingerEndy = (int)Math.floor(locus.y - endRadius * Math.sin(angle)); // move finger into start position fingerPath.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), fingerStartx, fingerStarty)); // finger comes down into contact with screen fingerPath.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); // finger moves a small amount very quickly fingerPath.addAction(finger.createPointerMove(Duration.ofMillis(1), PointerInput.Origin.viewport(), fingerMidx, fingerMidy)); // pause for a little bit fingerPath.addAction(new Pause(finger, Duration.ofMillis(100))); // finger moves to end position fingerPath.addAction(finger.createPointerMove(duration, PointerInput.Origin.viewport(), fingerEndx, fingerEndy)); // finger lets up, off the screen fingerPath.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); return fingerPath; }
Example 4
Source File: Edition090_Image_Element_Optimization.java From appiumpro with Apache License 2.0 | 5 votes |
private void shootBird(AndroidDriver driver, WebElement birdEl, int xOffset, int yOffset) { Rectangle rect = birdEl.getRect(); Point start = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2); Point end = start.moveBy(xOffset, yOffset); Duration dragDuration = Duration.ofMillis(750); PointerInput finger = new PointerInput(Kind.TOUCH, "finger"); Sequence shoot = new Sequence(finger, 0); shoot.addAction(finger.createPointerMove(Duration.ofMillis(0), Origin.viewport(), start.x, start.y)); shoot.addAction(finger.createPointerDown(MouseButton.LEFT.asArg())); shoot.addAction(finger.createPointerMove(dragDuration, Origin.viewport(), end.x, end.y)); shoot.addAction(finger.createPointerUp(MouseButton.LEFT.asArg())); driver.perform(Arrays.asList(shoot)); }