From 4d256d3d0668ed3e445c991180c63bb26126cdd5 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 3 Jun 2021 17:00:33 -0500 Subject: [PATCH 1/6] First draft at running in webdriver, seems to work locally --- .github/workflows/build.yaml | 21 +++- gwt-core-gwt2-tests/pom.xml | 28 +++++ .../gwtproject/junit/RunStyleWebDriver.java | 112 ++++++++++++++++++ 3 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b5abb92..48e6cac 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,12 +21,31 @@ on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + container: + options: --network-alias testHost + env: + SELENIUM_HUB: hub + TEST_HOST: testHost + + services: + hub: + image: selenium/hub:3.141.59-gold + firefox: + image: selenium/node-firefox:3.141.59-gold + env: + HUB_HOST: hub + HUB_PORT: 4444 + chrome: + image: selenium/node-chrome:3.141.59-gold + env: + HUB_HOST: hub + HUB_PORT: 4444 steps: - uses: actions/checkout@v2 # TODO: cache dependencies (taking into accounts: Maven plugins, snapshots, etc.) - name: Build with Maven - run: JAVA_HOME=$JAVA_HOME_8_X64 mvn -V -B -ntp -U -e verify + run: JAVA_HOME=$JAVA_HOME_8_X64 mvn -V -B -ntp -U -e verify -Pgithub-ci-selenium diff --git a/gwt-core-gwt2-tests/pom.xml b/gwt-core-gwt2-tests/pom.xml index 1e92433..4a00918 100644 --- a/gwt-core-gwt2-tests/pom.xml +++ b/gwt-core-gwt2-tests/pom.xml @@ -76,6 +76,11 @@ gwt-core test + + org.seleniumhq.selenium + selenium-remote-driver + 3.141.59 + @@ -100,4 +105,27 @@ + + + + github-ci-selenium + + + + net.ltgt.gwt.maven + gwt-maven-plugin + + + testHost + + + -runStyle + org.gwtproject.junit.RunStyleWebDriver:http://localhost:4444?firefox,chrome + + + + + + + diff --git a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java new file mode 100644 index 0000000..f644d9e --- /dev/null +++ b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java @@ -0,0 +1,112 @@ +package org.gwtproject.junit; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; +import com.google.gwt.junit.JUnitShell; +import com.google.gwt.junit.RunStyle; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.net.*; +import java.util.ArrayList; +import java.util.List; + +public class RunStyleWebDriver extends RunStyle { + + private List browsers = new ArrayList<>(); + private Thread keepalive; + + public RunStyleWebDriver(JUnitShell shell) { + super(shell); + } + + @Override + public int initialize(String args) { + if (args == null || args.length() == 0) { + getLogger().log(TreeLogger.ERROR, "WebDriver runstyle requires a parameter of the form protocol://hostname:port?browser1[,browser2]"); + return -1; + } + String[] parts = args.split("\\?"); + URL remoteAddress = null; + try { + remoteAddress = new URL(parts[0] + "/wd/hub"); + } catch (MalformedURLException e) { + getLogger().log(TreeLogger.ERROR, e.getMessage(), e); + return -1; + } + + // build each driver based on parts[1].split(",") + String[] browserNames = parts[1].split(","); + + for (String browserName : browserNames) { + DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY); + + try { + RemoteWebDriver wd = new RemoteWebDriver(remoteAddress, capabilities); + browsers.add(wd); + } catch (Exception exception) { + getLogger().log(TreeLogger.ERROR, "Failed to find desired browser", exception); + return -1; + } + } + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + if (keepalive != null) { + keepalive.interrupt(); + } + for (RemoteWebDriver browser : browsers) { + try { + browser.quit(); + } catch (Exception ignored) { + // ignore, we're shutting down, continue shutting down others + } + } + })); + return browsers.size(); + } + + @Override + public void launchModule(String moduleName) throws UnableToCompleteException { + // since WebDriver.get is blocking, start a keepalive thread first + keepalive = new Thread(() -> { + while (true) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + break; + } + for (RemoteWebDriver browser : browsers) { + browser.getTitle();// as in RunStyleSelenium, simple way to poll the browser + } + } + }); + keepalive.setDaemon(true); + keepalive.start(); + for (RemoteWebDriver browser : browsers) { + browser.get(shell.getModuleUrl(moduleName)); + } + } + + /** + * Work-around until GWT's JUnitShell handles IPv6 addresses correctly. + * https://groups.google.com/d/msg/google-web-toolkit/jLGhwUrKVRY/eQaDO6EUqdYJ + */ + public String getLocalHostName() { + String host = System.getProperty("webdriver.test.host"); + if (host != null) { + return host; + } + InetAddress a; + try { + a = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + throw new RuntimeException("Unable to determine my ip address", e); + } + if (a instanceof Inet6Address) { + return "[" + a.getHostAddress() + "]"; + } else { + return a.getHostAddress(); + } + } +} From c9bed433752bef99b1c7d7baff2bbd124a790ef6 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 3 Jun 2021 17:17:31 -0500 Subject: [PATCH 2/6] Clean up wiring so it works in github actions, makes sense locally --- .github/workflows/build.yaml | 11 +- gwt-core-gwt2-tests/pom.xml | 32 ++- .../gwtproject/junit/RunStyleWebDriver.java | 190 ++++++++++-------- 3 files changed, 133 insertions(+), 100 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 48e6cac..5df6724 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,16 +21,11 @@ on: [push, pull_request] jobs: build: runs-on: ubuntu-latest - container: - options: --network-alias testHost - - env: - SELENIUM_HUB: hub - TEST_HOST: testHost - services: hub: image: selenium/hub:3.141.59-gold + ports: + - 4444:4444 firefox: image: selenium/node-firefox:3.141.59-gold env: @@ -47,5 +42,5 @@ jobs: # TODO: cache dependencies (taking into accounts: Maven plugins, snapshots, etc.) - name: Build with Maven - run: JAVA_HOME=$JAVA_HOME_8_X64 mvn -V -B -ntp -U -e verify -Pgithub-ci-selenium + run: JAVA_HOME=$JAVA_HOME_8_X64 mvn -V -B -ntp -U -e verify -Pwebdriver-tests -Dwebdriver.test.host=$(hostname) diff --git a/gwt-core-gwt2-tests/pom.xml b/gwt-core-gwt2-tests/pom.xml index 4a00918..d316b59 100644 --- a/gwt-core-gwt2-tests/pom.xml +++ b/gwt-core-gwt2-tests/pom.xml @@ -76,11 +76,6 @@ gwt-core test - - org.seleniumhq.selenium - selenium-remote-driver - 3.141.59 - @@ -107,8 +102,29 @@ + - github-ci-selenium + webdriver-tests + + localhost + localhost + 4444 + firefox,chrome + 3.141.59 + + + + org.seleniumhq.selenium + selenium-remote-driver + ${webdriver.version} + + @@ -116,11 +132,11 @@ gwt-maven-plugin - testHost + ${webdriver.test.host} -runStyle - org.gwtproject.junit.RunStyleWebDriver:http://localhost:4444?firefox,chrome + org.gwtproject.junit.RunStyleWebDriver:http://${webdriver.hub.host}:${webdriver.hub.port}?${webdriver.browsers} diff --git a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java index f644d9e..4e272ac 100644 --- a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java +++ b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java @@ -1,112 +1,134 @@ +/* + * Copyright © 2019 The GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.gwtproject.junit; import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.junit.JUnitShell; import com.google.gwt.junit.RunStyle; -import org.openqa.selenium.Platform; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - import java.net.*; import java.util.ArrayList; import java.util.List; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; public class RunStyleWebDriver extends RunStyle { - private List browsers = new ArrayList<>(); - private Thread keepalive; - - public RunStyleWebDriver(JUnitShell shell) { - super(shell); - } + private List browsers = new ArrayList<>(); + private Thread keepalive; - @Override - public int initialize(String args) { - if (args == null || args.length() == 0) { - getLogger().log(TreeLogger.ERROR, "WebDriver runstyle requires a parameter of the form protocol://hostname:port?browser1[,browser2]"); - return -1; - } - String[] parts = args.split("\\?"); - URL remoteAddress = null; - try { - remoteAddress = new URL(parts[0] + "/wd/hub"); - } catch (MalformedURLException e) { - getLogger().log(TreeLogger.ERROR, e.getMessage(), e); - return -1; - } + public RunStyleWebDriver(JUnitShell shell) { + super(shell); + } - // build each driver based on parts[1].split(",") - String[] browserNames = parts[1].split(","); + @Override + public int initialize(String args) { + if (args == null || args.length() == 0) { + getLogger() + .log( + TreeLogger.ERROR, + "WebDriver runstyle requires a parameter of the form protocol://hostname:port?browser1[,browser2]"); + return -1; + } + String[] parts = args.split("\\?"); + URL remoteAddress = null; + try { + remoteAddress = new URL(parts[0] + "/wd/hub"); + } catch (MalformedURLException e) { + getLogger().log(TreeLogger.ERROR, e.getMessage(), e); + return -1; + } - for (String browserName : browserNames) { - DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY); + // build each driver based on parts[1].split(",") + String[] browserNames = parts[1].split(","); - try { - RemoteWebDriver wd = new RemoteWebDriver(remoteAddress, capabilities); - browsers.add(wd); - } catch (Exception exception) { - getLogger().log(TreeLogger.ERROR, "Failed to find desired browser", exception); - return -1; - } - } + for (String browserName : browserNames) { + DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY); - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - if (keepalive != null) { - keepalive.interrupt(); - } - for (RemoteWebDriver browser : browsers) { - try { - browser.quit(); - } catch (Exception ignored) { - // ignore, we're shutting down, continue shutting down others - } - } - })); - return browsers.size(); + try { + RemoteWebDriver wd = new RemoteWebDriver(remoteAddress, capabilities); + browsers.add(wd); + } catch (Exception exception) { + getLogger().log(TreeLogger.ERROR, "Failed to find desired browser", exception); + return -1; + } } - @Override - public void launchModule(String moduleName) throws UnableToCompleteException { - // since WebDriver.get is blocking, start a keepalive thread first - keepalive = new Thread(() -> { - while (true) { + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + if (keepalive != null) { + keepalive.interrupt(); + } + for (RemoteWebDriver browser : browsers) { + try { + browser.quit(); + } catch (Exception ignored) { + // ignore, we're shutting down, continue shutting down others + } + } + })); + return browsers.size(); + } + + @Override + public void launchModule(String moduleName) throws UnableToCompleteException { + // since WebDriver.get is blocking, start a keepalive thread first + keepalive = + new Thread( + () -> { + while (true) { try { - Thread.sleep(1000); + Thread.sleep(1000); } catch (InterruptedException e) { - break; + break; } for (RemoteWebDriver browser : browsers) { - browser.getTitle();// as in RunStyleSelenium, simple way to poll the browser + browser.getTitle(); // as in RunStyleSelenium, simple way to poll the browser } - } - }); - keepalive.setDaemon(true); - keepalive.start(); - for (RemoteWebDriver browser : browsers) { - browser.get(shell.getModuleUrl(moduleName)); - } + } + }); + keepalive.setDaemon(true); + keepalive.start(); + for (RemoteWebDriver browser : browsers) { + browser.get(shell.getModuleUrl(moduleName)); } + } - /** - * Work-around until GWT's JUnitShell handles IPv6 addresses correctly. - * https://groups.google.com/d/msg/google-web-toolkit/jLGhwUrKVRY/eQaDO6EUqdYJ - */ - public String getLocalHostName() { - String host = System.getProperty("webdriver.test.host"); - if (host != null) { - return host; - } - InetAddress a; - try { - a = InetAddress.getLocalHost(); - } catch (UnknownHostException e) { - throw new RuntimeException("Unable to determine my ip address", e); - } - if (a instanceof Inet6Address) { - return "[" + a.getHostAddress() + "]"; - } else { - return a.getHostAddress(); - } + /** + * Work-around until GWT's JUnitShell handles IPv6 addresses correctly. + * https://groups.google.com/d/msg/google-web-toolkit/jLGhwUrKVRY/eQaDO6EUqdYJ + */ + public String getLocalHostName() { + String host = System.getProperty("webdriver.test.host"); + if (host != null) { + return host; + } + InetAddress a; + try { + a = InetAddress.getLocalHost(); + } catch (UnknownHostException e) { + throw new RuntimeException("Unable to determine my ip address", e); + } + if (a instanceof Inet6Address) { + return "[" + a.getHostAddress() + "]"; + } else { + return a.getHostAddress(); } + } } From db89fd7a00737f5a7ec6c8fde176414aa88a93e8 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 8 Jul 2021 10:56:14 -0500 Subject: [PATCH 3/6] Code review feedback --- gwt-core-gwt2-tests/pom.xml | 2 +- ...a => RunStyleAbstractRemoteWebDriver.java} | 71 +++++++++++++----- .../junit/RunStyleRemoteWebDriver.java | 74 +++++++++++++++++++ .../RunStyleRemoteWebDriverWithConfig.java | 52 +++++++++++++ 4 files changed, 180 insertions(+), 19 deletions(-) rename gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/{RunStyleWebDriver.java => RunStyleAbstractRemoteWebDriver.java} (65%) create mode 100644 gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java create mode 100644 gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriverWithConfig.java diff --git a/gwt-core-gwt2-tests/pom.xml b/gwt-core-gwt2-tests/pom.xml index d316b59..8cb4da0 100644 --- a/gwt-core-gwt2-tests/pom.xml +++ b/gwt-core-gwt2-tests/pom.xml @@ -136,7 +136,7 @@ -runStyle - org.gwtproject.junit.RunStyleWebDriver:http://${webdriver.hub.host}:${webdriver.hub.port}?${webdriver.browsers} + org.gwtproject.junit.RunStyleRemoteWebDriver:http://${webdriver.hub.host}:${webdriver.hub.port}?${webdriver.browsers} diff --git a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleAbstractRemoteWebDriver.java similarity index 65% rename from gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java rename to gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleAbstractRemoteWebDriver.java index 4e272ac..1a8ebce 100644 --- a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleWebDriver.java +++ b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleAbstractRemoteWebDriver.java @@ -19,45 +19,80 @@ import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.junit.JUnitShell; import com.google.gwt.junit.RunStyle; -import java.net.*; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; -import org.openqa.selenium.Platform; +import java.util.Map; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; -public class RunStyleWebDriver extends RunStyle { +public abstract class RunStyleAbstractRemoteWebDriver extends RunStyle { + + public static class RemoteWebDriverConfiguration { + private String remoteWebDriverUrl; + private List> browserCapabilities; + + public String getRemoteWebDriverUrl() { + return remoteWebDriverUrl; + } + + public void setRemoteWebDriverUrl(String remoteWebDriverUrl) { + this.remoteWebDriverUrl = remoteWebDriverUrl; + } + + public List> getBrowserCapabilities() { + return browserCapabilities; + } + + public void setBrowserCapabilities(List> browserCapabilities) { + this.browserCapabilities = browserCapabilities; + } + } + + public class ConfigurationException extends Exception {} private List browsers = new ArrayList<>(); private Thread keepalive; - public RunStyleWebDriver(JUnitShell shell) { + public RunStyleAbstractRemoteWebDriver(JUnitShell shell) { super(shell); } + /** + * Validates the arguments for the specific subclass, and creates a configuration that describes + * how to run the tests. + * + * @param args the command line argument string passed from JUnitShell + * @return the configuration to use when running these tests + */ + protected abstract RemoteWebDriverConfiguration readConfiguration(String args) + throws ConfigurationException; + @Override - public int initialize(String args) { - if (args == null || args.length() == 0) { - getLogger() - .log( - TreeLogger.ERROR, - "WebDriver runstyle requires a parameter of the form protocol://hostname:port?browser1[,browser2]"); + public final int initialize(String args) { + final RemoteWebDriverConfiguration config; + try { + config = readConfiguration(args); + } catch (ConfigurationException failed) { + // log should already have details about what went wrong, we will just return the failure + // value return -1; } - String[] parts = args.split("\\?"); - URL remoteAddress = null; + + final URL remoteAddress; try { - remoteAddress = new URL(parts[0] + "/wd/hub"); + remoteAddress = new URL(config.getRemoteWebDriverUrl()); } catch (MalformedURLException e) { getLogger().log(TreeLogger.ERROR, e.getMessage(), e); return -1; } - // build each driver based on parts[1].split(",") - String[] browserNames = parts[1].split(","); - - for (String browserName : browserNames) { - DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY); + for (Map capabilityMap : config.getBrowserCapabilities()) { + DesiredCapabilities capabilities = new DesiredCapabilities(capabilityMap); try { RemoteWebDriver wd = new RemoteWebDriver(remoteAddress, capabilities); diff --git a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java new file mode 100644 index 0000000..99249f4 --- /dev/null +++ b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java @@ -0,0 +1,74 @@ +/* + * Copyright © 2019 The GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.gwtproject.junit; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.junit.JUnitShell; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import org.openqa.selenium.Platform; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class RunStyleRemoteWebDriver extends RunStyleAbstractRemoteWebDriver { + + public RunStyleRemoteWebDriver(JUnitShell shell) { + super(shell); + } + + @Override + protected RemoteWebDriverConfiguration readConfiguration(String args) + throws ConfigurationException { + RemoteWebDriverConfiguration config = new RemoteWebDriverConfiguration(); + if (args == null || args.length() == 0) { + getLogger() + .log( + TreeLogger.ERROR, + "RemoteWebDriver runstyle requires a parameter of the form protocol://hostname:port?browser1[,browser2]"); + throw new ConfigurationException(); + } + + String[] parts = args.split("\\?"); + String url = parts[0]; + URL remoteAddress = null; + try { + remoteAddress = new URL(url); + if (remoteAddress.getPath().equals("") + || (remoteAddress.getPath().equals("/") && !url.endsWith("/"))) { + getLogger() + .log( + TreeLogger.INFO, + "No path specified in webdriver remote url, using default of /wd/hub"); + config.setRemoteWebDriverUrl(url + "/wd/hub"); + } else { + config.setRemoteWebDriverUrl(url); + } + } catch (MalformedURLException e) { + getLogger().log(TreeLogger.ERROR, e.getMessage(), e); + throw new ConfigurationException(); + } + + // build each driver based on parts[1].split(",") + String[] browserNames = parts[1].split(","); + config.setBrowserCapabilities(new ArrayList<>()); + for (String browserName : browserNames) { + DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY); + config.getBrowserCapabilities().add(capabilities.asMap()); + } + + return config; + } +} diff --git a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriverWithConfig.java b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriverWithConfig.java new file mode 100644 index 0000000..ededc00 --- /dev/null +++ b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriverWithConfig.java @@ -0,0 +1,52 @@ +/* + * Copyright © 2019 The GWT Project Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.gwtproject.junit; + +import com.google.gson.Gson; +import com.google.gson.JsonIOException; +import com.google.gson.JsonSyntaxException; +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.junit.JUnitShell; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; + +public class RunStyleRemoteWebDriverWithConfig extends RunStyleAbstractRemoteWebDriver { + public RunStyleRemoteWebDriverWithConfig(JUnitShell shell) { + super(shell); + } + + @Override + protected RemoteWebDriverConfiguration readConfiguration(String args) + throws ConfigurationException { + File jsonConfigFile = new File(args); + + try { + RemoteWebDriverConfiguration config = + new Gson().fromJson(new FileReader(jsonConfigFile), RemoteWebDriverConfiguration.class); + return config; + } catch (FileNotFoundException e) { + getLogger().log(TreeLogger.Type.ERROR, "Configuration file not found: " + args, e); + throw new ConfigurationException(); + } catch (JsonIOException e) { + getLogger().log(TreeLogger.Type.ERROR, "Error reading config file: " + args, e); + throw new ConfigurationException(); + } catch (JsonSyntaxException e) { + getLogger().log(TreeLogger.Type.ERROR, "Error parsing config file: " + args, e); + throw new ConfigurationException(); + } + } +} From bafa0d4eb6a764b7bb72490b0ea06951fad74f80 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 28 Dec 2023 10:11:18 -0600 Subject: [PATCH 4/6] Update to latest selenium --- gwt-core-gwt2-tests/pom.xml | 15 +++++++-------- .../gwtproject/junit/RunStyleRemoteWebDriver.java | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gwt-core-gwt2-tests/pom.xml b/gwt-core-gwt2-tests/pom.xml index 8cb4da0..d3f6821 100644 --- a/gwt-core-gwt2-tests/pom.xml +++ b/gwt-core-gwt2-tests/pom.xml @@ -76,6 +76,13 @@ gwt-core test + + + org.seleniumhq.selenium + selenium-remote-driver + 4.16.1 + test + @@ -116,15 +123,7 @@ localhost 4444 firefox,chrome - 3.141.59 - - - org.seleniumhq.selenium - selenium-remote-driver - ${webdriver.version} - - diff --git a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java index 99249f4..f4f9969 100644 --- a/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java +++ b/gwt-core-gwt2-tests/src/test/java/org/gwtproject/junit/RunStyleRemoteWebDriver.java @@ -20,7 +20,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import org.openqa.selenium.Platform; import org.openqa.selenium.remote.DesiredCapabilities; public class RunStyleRemoteWebDriver extends RunStyleAbstractRemoteWebDriver { @@ -65,7 +64,8 @@ protected RemoteWebDriverConfiguration readConfiguration(String args) String[] browserNames = parts[1].split(","); config.setBrowserCapabilities(new ArrayList<>()); for (String browserName : browserNames) { - DesiredCapabilities capabilities = new DesiredCapabilities(browserName, "", Platform.ANY); + DesiredCapabilities capabilities = new DesiredCapabilities(); + capabilities.setBrowserName(browserName); config.getBrowserCapabilities().add(capabilities.asMap()); } From fa5176ed062e369be0714cdf1e43d2d4fe1cf8c5 Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 28 Dec 2023 10:14:23 -0600 Subject: [PATCH 5/6] Attempt to update gha to match --- .github/workflows/build.yaml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5df6724..2376760 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,19 +23,23 @@ jobs: runs-on: ubuntu-latest services: hub: - image: selenium/hub:3.141.59-gold + image: selenium/hub:4.16.1-20231219 ports: - - 4444:4444 + - "4442:4442" + - "4443:4443" + - "4444:4444" firefox: - image: selenium/node-firefox:3.141.59-gold + image: selenium/node-firefox:4.16.1-20231219 env: - HUB_HOST: hub - HUB_PORT: 4444 + SE_EVENT_BUS_HOST: hub + SE_EVENT_BUS_PUBLISH_PORT: 4442 + SE_EVENT_BUS_SUBSCRIBE_PORT: 4443 chrome: - image: selenium/node-chrome:3.141.59-gold + image: selenium/node-chrome:4.16.1-20231219 env: - HUB_HOST: hub - HUB_PORT: 4444 + SE_EVENT_BUS_HOST: hub + SE_EVENT_BUS_PUBLISH_PORT: 4442 + SE_EVENT_BUS_SUBSCRIBE_PORT: 4443 steps: - uses: actions/checkout@v2 From 8c3b484749af91495c6fb28d9b6322b5b684622a Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 28 Dec 2023 10:18:11 -0600 Subject: [PATCH 6/6] Update to Java 11 to support selenium, enable caching too --- .github/workflows/build.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2376760..6af49f6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -41,10 +41,15 @@ jobs: SE_EVENT_BUS_PUBLISH_PORT: 4442 SE_EVENT_BUS_SUBSCRIBE_PORT: 4443 steps: - - uses: actions/checkout@v2 - - # TODO: cache dependencies (taking into accounts: Maven plugins, snapshots, etc.) - - - name: Build with Maven - run: JAVA_HOME=$JAVA_HOME_8_X64 mvn -V -B -ntp -U -e verify -Pwebdriver-tests -Dwebdriver.test.host=$(hostname) + - name: Checkout + uses: actions/checkout@v4 + - name: Setup JDK 11 + id: setup-java-11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + cache: 'maven' + - name: Build and test with Maven + run: mvn -V -B -ntp -U -e verify -Pwebdriver-tests -Dwebdriver.test.host=$(hostname)