Skip to content

Commit

Permalink
[java] Implementing W3C compatible single tap touch action
Browse files Browse the repository at this point in the history
(To debug drivers, as soon as they prove to be working well other touch actions will be implemented)
  • Loading branch information
barancev committed Apr 10, 2019
1 parent 32e343f commit eea2323
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
26 changes: 0 additions & 26 deletions java/client/src/org/openqa/selenium/interactions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,32 +74,6 @@ public Actions(WebDriver driver) {
}
}

/**
* A constructor that should only be used when the keyboard or mouse were extended to provide
* additional functionality (for example, dragging-and-dropping from the desktop).
* @param keyboard the {@link Keyboard} implementation to delegate to.
* @param mouse the {@link Mouse} implementation to delegate to.
* @deprecated Use the new interactions APIs.
*/
@Deprecated
public Actions(Keyboard keyboard, Mouse mouse) {
this.driver = null;
this.jsonKeyboard = keyboard;
this.jsonMouse = mouse;
}

/**
* Only used by the TouchActions class.
* @param keyboard implementation to delegate to.
* @deprecated Use the new interactions API.
*/
@Deprecated
public Actions(Keyboard keyboard) {
this.driver = null;
this.jsonKeyboard = keyboard;
this.jsonMouse = null;
}

/**
* Performs a modifier key press. Does not release the modifier key - subsequent interactions
* may assume it's kept pressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

package org.openqa.selenium.interactions.touch;

import static org.openqa.selenium.interactions.PointerInput.Kind.TOUCH;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.HasInputDevices;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.Keyboard;
import org.openqa.selenium.interactions.Locatable;
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.TouchScreen;

/**
Expand All @@ -32,17 +33,16 @@
*/
public class TouchActions extends Actions {

private final PointerInput touchPointer = new PointerInput(TOUCH, "touch screen");
protected TouchScreen touchScreen;

public TouchActions(WebDriver driver) {
this(((HasInputDevices) driver).getKeyboard(),
((HasTouchScreen) driver).getTouch());
}

@Deprecated
public TouchActions(Keyboard keyboard, TouchScreen touchScreen) {
super(keyboard);
this.touchScreen = touchScreen;
super(driver);
if (driver instanceof HasTouchScreen) {
this.touchScreen = ((HasTouchScreen) driver).getTouch();
} else {
this.touchScreen = null;
}
}

/**
Expand All @@ -52,7 +52,11 @@ public TouchActions(Keyboard keyboard, TouchScreen touchScreen) {
* @return self
*/
public TouchActions singleTap(WebElement onElement) {
action.addAction(new SingleTapAction(touchScreen, (Locatable) onElement));
if (touchScreen != null) {
action.addAction(new SingleTapAction(touchScreen, (Locatable) onElement));
}
tick(touchPointer.createPointerDown(0));
tick(touchPointer.createPointerUp(0));
return this;
}

Expand All @@ -65,7 +69,9 @@ public TouchActions singleTap(WebElement onElement) {
* @return self
*/
public TouchActions down(int x, int y) {
action.addAction(new DownAction(touchScreen, x, y));
if (touchScreen != null) {
action.addAction(new DownAction(touchScreen, x, y));
}
return this;
}

Expand All @@ -78,7 +84,9 @@ public TouchActions down(int x, int y) {
* @return self
*/
public TouchActions up(int x, int y) {
action.addAction(new UpAction(touchScreen, x, y));
if (touchScreen != null) {
action.addAction(new UpAction(touchScreen, x, y));
}
return this;
}

Expand All @@ -90,7 +98,9 @@ public TouchActions up(int x, int y) {
* @return self
*/
public TouchActions move(int x, int y) {
action.addAction(new MoveAction(touchScreen, x, y));
if (touchScreen != null) {
action.addAction(new MoveAction(touchScreen, x, y));
}
return this;
}

Expand All @@ -103,7 +113,9 @@ public TouchActions move(int x, int y) {
* @return self
*/
public TouchActions scroll(WebElement onElement, int xOffset, int yOffset) {
action.addAction(new ScrollAction(touchScreen, (Locatable) onElement, xOffset, yOffset));
if (touchScreen != null) {
action.addAction(new ScrollAction(touchScreen, (Locatable) onElement, xOffset, yOffset));
}
return this;
}

Expand All @@ -115,7 +127,9 @@ public TouchActions scroll(WebElement onElement, int xOffset, int yOffset) {
*/

public TouchActions doubleTap(WebElement onElement) {
action.addAction(new DoubleTapAction(touchScreen, (Locatable) onElement));
if (touchScreen != null) {
action.addAction(new DoubleTapAction(touchScreen, (Locatable) onElement));
}
return this;
}

Expand All @@ -127,7 +141,9 @@ public TouchActions doubleTap(WebElement onElement) {
*/

public TouchActions longPress(WebElement onElement) {
action.addAction(new LongPressAction(touchScreen, (Locatable) onElement));
if (touchScreen != null) {
action.addAction(new LongPressAction(touchScreen, (Locatable) onElement));
}
return this;
}

Expand All @@ -140,7 +156,9 @@ public TouchActions longPress(WebElement onElement) {
*/

public TouchActions scroll(int xOffset, int yOffset) {
action.addAction(new ScrollAction(touchScreen, xOffset, yOffset));
if (touchScreen != null) {
action.addAction(new ScrollAction(touchScreen, xOffset, yOffset));
}
return this;
}

Expand All @@ -153,7 +171,9 @@ public TouchActions scroll(int xOffset, int yOffset) {
*/

public TouchActions flick(int xSpeed, int ySpeed) {
action.addAction(new FlickAction(touchScreen, xSpeed, ySpeed));
if (touchScreen != null) {
action.addAction(new FlickAction(touchScreen, xSpeed, ySpeed));
}
return this;
}

Expand All @@ -168,7 +188,9 @@ public TouchActions flick(int xSpeed, int ySpeed) {
*/

public TouchActions flick(WebElement onElement, int xOffset, int yOffset, int speed) {
action.addAction(new FlickAction(touchScreen, (Locatable) onElement, xOffset, yOffset, speed));
if (touchScreen != null) {
action.addAction(new FlickAction(touchScreen, (Locatable) onElement, xOffset, yOffset, speed));
}
return this;
}
}

0 comments on commit eea2323

Please sign in to comment.