Skip to content

Commit

Permalink
Upgrade selenium to 4.6.0 and release 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperchen committed Nov 8, 2022
1 parent 4af7ebc commit 180ad33
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 27 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version=1.0.4
version=1.0.5

# dependencies
junitVersion=5.8.1
seleniumVersion=4.2.2
seleniumVersion=4.6.0
dockerJunitVersion=1.8.0
webdrivermanagerVersion=5.3.0
hamcrestVersion=2.2
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/zkoss/test/webdriver/BaseTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import java.net.URL;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;

/**
Expand All @@ -31,7 +28,7 @@
* @see <a href="https://crbug.com/1010288">Chrome is not supporting --lang parameter with language that contains a '-' while using headless mode</a>
* @author rudyhuang
*/
public class DockerChromeRemoteWebDriver extends RemoteWebDriver implements HasTouchScreen {
public class DockerChromeRemoteWebDriver extends RemoteWebDriver {
public DockerChromeRemoteWebDriver(URL remoteAddress, Capabilities capabilities) {
super(remoteAddress, capabilities);
}
Expand All @@ -47,9 +44,4 @@ private static URL toURL(String url) {
throw new UncheckedIOException(e);
}
}

@Override
public TouchScreen getTouch() {
return new RemoteTouchScreen(getExecuteMethod());
}
}
61 changes: 52 additions & 9 deletions src/main/java/org/zkoss/test/webdriver/TouchWebDriverTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@
*/
package org.zkoss.test.webdriver;

import static java.time.Duration.ofMillis;
import static org.openqa.selenium.interactions.PointerInput.MouseButton.LEFT;
import static org.openqa.selenium.interactions.PointerInput.Origin.viewport;

import java.util.Collections;

import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.touch.TouchActions;
import org.openqa.selenium.interactions.Pause;
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
import org.openqa.selenium.remote.RemoteWebDriver;

/**
* A base class to test using a Touch Simulator to run a remote Docker WebDriver.
Expand All @@ -25,15 +34,49 @@ public abstract class TouchWebDriverTestCase extends DockerWebDriverTestCase {
@Override
protected final ChromeOptions getWebDriverOptions() {
return super.getWebDriverOptions()
.setExperimentalOption("mobileEmulation", Collections.singletonMap("deviceName", "iPad"))
.setExperimentalOption("w3c", false); // Temporary workaround for TouchAction
.setExperimentalOption("mobileEmulation", Collections.singletonMap("deviceName", "iPad"));
}

private final static PointerInput FINGER = new PointerInput(
PointerInput.Kind.TOUCH, "finger");

public void swipe(Point start, Point end) {
swipe(start, end, 0);
}
public void swipe(Point start, Point end, int duration) {
Sequence swipe = new Sequence(FINGER, 1)
.addAction(FINGER.createPointerMove(ofMillis(0), viewport(), start.getX(), start.getY()))
.addAction(FINGER.createPointerDown(LEFT.asArg()))
.addAction(FINGER.createPointerMove(ofMillis(duration), viewport(), end.getX(), end.getY()))
.addAction(FINGER.createPointerUp(LEFT.asArg()));
((RemoteWebDriver) driver).perform(Collections.singleton(swipe));
}

public void swipe(WebElement start, WebElement end) {
swipe(start, end);
}
public void swipe(WebElement start, WebElement end, int duration) {
swipe(start.getLocation(), end.getLocation(), duration);
}
public void tap(Point point) {
tap(point, 0);
}

public void tap(Point point, int duration) {
Sequence tap = new Sequence(FINGER, 1)
.addAction(FINGER.createPointerMove(ofMillis(0), viewport(), point.getX(), point.getY()))
.addAction(FINGER.createPointerDown(LEFT.asArg()))
.addAction(new Pause(FINGER, ofMillis(duration)))
.addAction(FINGER.createPointerUp(LEFT.asArg()));
((RemoteWebDriver) driver).perform(Collections.singleton(tap));
}

/**
* Returns the touch actions for simulating touch events.
* @return
*/
protected TouchActions getTouchActions() {
return new TouchActions(driver);
public void tap(WebElement start, int duration) {
tap(start.getLocation(), duration);
}

public void tap(WebElement start) {
tap(start.getLocation(), 0);
}

}
2 changes: 1 addition & 1 deletion src/main/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version: "3"
services:
chrome:
image: selenium/node-chrome:4.1.4-20220427
image: selenium/node-chrome:4.6.0-20221104
shm_size: 2gb
depends_on:
- hub
Expand Down

0 comments on commit 180ad33

Please sign in to comment.