diff --git a/flow-tests/test-devloop/README.md b/flow-tests/test-devloop/README.md index d20cf573446..46ae64d61e0 100644 --- a/flow-tests/test-devloop/README.md +++ b/flow-tests/test-devloop/README.md @@ -94,6 +94,13 @@ mvn -o -pl flow-tests/test-devloop/test-devloop-jetty/devloop-app -Pdevloop-mave `-Dit.test=` narrows both executions, so the named ITs run once with each compiler. +The browser ITs use a local headless Chrome. To run them on a Selenium hub, +as the other Flow ITs do in CI, add `-Dtest.use.hub=true` and +`-Dcom.vaadin.testbench.Parameters.hubHostname=`. The browser then opens +the application at this machine's site-local address rather than at +`localhost`, so every fixture listens on all interfaces and passes +`vaadin.devmode.hostsAllowed` to let that browser use the dev tools connection. + Each fixture's README has the rest: what it pins and why, how to drive the loop by hand, and the patch-and-revert rule the ITs follow so that a failed run never leaves the working tree dirty. diff --git a/flow-tests/test-devloop/pom.xml b/flow-tests/test-devloop/pom.xml index c3588ef4f91..ff05386afb3 100644 --- a/flow-tests/test-devloop/pom.xml +++ b/flow-tests/test-devloop/pom.xml @@ -45,6 +45,12 @@ true + + * diff --git a/flow-tests/test-devloop/test-devloop-cargo/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-cargo/devloop-app/pom.xml index 981205dba60..3c22ce73752 100644 --- a/flow-tests/test-devloop/test-devloop-cargo/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-cargo/devloop-app/pom.xml @@ -188,6 +188,7 @@ false + ${vaadin.devmode.hostsAllowed} diff --git a/flow-tests/test-devloop/test-devloop-jbosseap/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-jbosseap/devloop-app/pom.xml index 3bca17928e7..4761bf108cc 100644 --- a/flow-tests/test-devloop/test-devloop-jbosseap/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-jbosseap/devloop-app/pom.xml @@ -222,6 +222,10 @@ -Dvaadin.frontend.hotdeploy=false + -Dvaadin.devmode.hostsAllowed=${vaadin.devmode.hostsAllowed} + + -Djboss.bind.address=0.0.0.0 diff --git a/flow-tests/test-devloop/test-devloop-jetty/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-jetty/devloop-app/pom.xml index e98ac99a645..f35b664229b 100644 --- a/flow-tests/test-devloop/test-devloop-jetty/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-jetty/devloop-app/pom.xml @@ -172,6 +172,7 @@ false + ${vaadin.devmode.hostsAllowed} diff --git a/flow-tests/test-devloop/test-devloop-liberty/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-liberty/devloop-app/pom.xml index 3cf4837c548..82babd07988 100644 --- a/flow-tests/test-devloop/test-devloop-liberty/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-liberty/devloop-app/pom.xml @@ -195,6 +195,7 @@ which it does not take away. --> -Dvaadin.frontend.hotdeploy=false + -Dvaadin.devmode.hostsAllowed=${vaadin.devmode.hostsAllowed} diff --git a/flow-tests/test-devloop/test-devloop-payara-micro/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-payara-micro/devloop-app/pom.xml index 63c5c46f1a1..9a87dd7a61a 100644 --- a/flow-tests/test-devloop/test-devloop-payara-micro/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-payara-micro/devloop-app/pom.xml @@ -185,6 +185,9 @@ + / diff --git a/flow-tests/test-devloop/test-devloop-payara/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-payara/devloop-app/pom.xml index 7cbf6eef1b7..27d0becdf92 100644 --- a/flow-tests/test-devloop/test-devloop-payara/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-payara/devloop-app/pom.xml @@ -212,6 +212,9 @@ + diff --git a/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/main/resources/application.properties b/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/main/resources/application.properties index b2e56f42043..e40f09040e1 100644 --- a/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/main/resources/application.properties +++ b/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/main/resources/application.properties @@ -7,6 +7,11 @@ server.port=8899 # else may push to the browser on its own. vaadin.frontend.hotdeploy=false +# Dev tools from any host, as the other fixtures get from +# vaadin.devmode.hostsAllowed in flow-tests/test-devloop/pom.xml: the browser ITs +# on bender.vaadin.com run on the Selenium hub, another machine. +vaadin.devmode.hostsAllowed=* + # Tomcat caches what it serves from META-INF/resources for 5 seconds and # revalidates on that TTL alone, never on the file's timestamp - so a fetch # right after an apply can be served the pre-edit bytes even though the daemon diff --git a/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopSpringStatisticsIT.java b/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopSpringStatisticsIT.java index 254b98b95eb..dcec04e5619 100644 --- a/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopSpringStatisticsIT.java +++ b/flow-tests/test-devloop/test-devloop-spring/devloop-app/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopSpringStatisticsIT.java @@ -26,8 +26,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.WebDriverWait; import com.vaadin.testbench.BrowserTest; @@ -54,13 +52,7 @@ class DevLoopSpringStatisticsIT extends BrowserTestBase @Override public WebDriver createDriver() { - ChromeOptions options = new ChromeOptions(); - options.addArguments("--headless=new", "--disable-gpu", - "--disable-backgrounding-occluded-windows"); - // Required in CI and containers, which disable the Chrome sandbox and - // have a small /dev/shm. - options.addArguments("--no-sandbox", "--disable-dev-shm-usage"); - return new ChromeDriver(options); + return DevLoopBrowsers.createDriver(); } @BeforeEach @@ -107,8 +99,9 @@ void anApplicationUnderTheLoop_reportsTheLoopAndThenTheApply() { } private void openTheView() { - getDriver() - .get("http://localhost:" + AbstractDevLoopIT.SERVER_PORT + "/"); + getDriver().get( + AbstractDevLoopIT.rootUrl(DevLoopBrowsers.deploymentHostname()) + + "/"); // The first snapshot after navigating is usually empty - Vaadin renders // client-side - so wait for something the view owns. new WebDriverWait(getDriver(), Duration.ofMinutes(2)) diff --git a/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/AbstractDevLoopIT.java b/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/AbstractDevLoopIT.java index f486be5a6c1..0ccf4e26653 100644 --- a/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/AbstractDevLoopIT.java +++ b/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/AbstractDevLoopIT.java @@ -92,8 +92,7 @@ abstract class AbstractDevLoopIT { * Where the application is served, with no trailing slash: the port, and * the context root for a fixture that cannot serve from {@code /}. */ - static final String ROOT_URL = "http://localhost:" + SERVER_PORT - + contextPath(); + static final String ROOT_URL = rootUrl("localhost"); protected VaadinDevCli cli; @@ -199,6 +198,19 @@ private static String contextPath() { return readPomProperty("devloop.context.path").orElse(""); } + /** + * Where the application is served for a client on the given host name, with + * no trailing slash. A browser on the Selenium hub needs this machine's + * address, as {@code localhost} there is the hub itself. + * + * @param hostname + * the host name the client reaches this machine by + * @return the root URL of the application + */ + static String rootUrl(String hostname) { + return "http://" + hostname + ":" + SERVER_PORT + contextPath(); + } + private static Optional readPomProperty(String name) { Path pom = APP.resolve("pom.xml"); String tag = Pattern.quote(name); diff --git a/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowserIT.java b/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowserIT.java index dd3cb12da82..4a4ac5eb5de 100644 --- a/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowserIT.java +++ b/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowserIT.java @@ -24,8 +24,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.WebDriverWait; import com.vaadin.testbench.BrowserTest; @@ -60,13 +58,7 @@ class DevLoopBrowserIT extends BrowserTestBase implements DriverSupplier { @Override public WebDriver createDriver() { - ChromeOptions options = new ChromeOptions(); - options.addArguments("--headless=new", "--disable-gpu", - "--disable-backgrounding-occluded-windows"); - // Required in CI and containers, which disable the Chrome sandbox and - // have a small /dev/shm. - options.addArguments("--no-sandbox", "--disable-dev-shm-usage"); - return new ChromeDriver(options); + return DevLoopBrowsers.createDriver(); } @BeforeEach @@ -75,7 +67,9 @@ void openTheApplication() { patch = new SourcePatch(); cli.run("start").assertExitCode(0); cli.run("apply").assertExitCode(0); - getDriver().get(AbstractDevLoopIT.ROOT_URL + "/"); + getDriver().get( + AbstractDevLoopIT.rootUrl(DevLoopBrowsers.deploymentHostname()) + + "/"); // The first snapshot after navigating is usually empty - Vaadin renders // client-side - so wait for something the view owns. waitFor("#title"); diff --git a/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowsers.java b/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowsers.java new file mode 100644 index 00000000000..b05cd94e5a9 --- /dev/null +++ b/flow-tests/test-devloop/test-devloop-support/src/test/java/com/vaadin/flow/devloop/test/it/DevLoopBrowsers.java @@ -0,0 +1,97 @@ +/* + * Copyright 2000-2026 Vaadin Ltd. + * + * 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 com.vaadin.flow.devloop.test.it; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.RemoteWebDriver; + +import com.vaadin.testbench.IPAddress; +import com.vaadin.testbench.Parameters; + +/** + * The browser the dev loop browser ITs run in. + *

+ * A local headless Chrome by default. With {@code -Dtest.use.hub=true}, as on + * bender.vaadin.com, the browser runs on the Selenium hub named by + * {@code -Dcom.vaadin.testbench.Parameters.hubHostname} instead, the same as + * the JUnit 4 tests, and the application is opened through this machine's site + * local address. + */ +final class DevLoopBrowsers { + + /** + * Whether the browser runs on the Selenium hub, from the + * {@code test.use.hub} system property that the JUnit 4 tests read too. + */ + static final boolean USE_HUB = Boolean.getBoolean("test.use.hub"); + + private DevLoopBrowsers() { + } + + /** + * Creates the Chrome driver: a remote one on the hub when {@link #USE_HUB} + * is set, a local one otherwise. Both get the same headless options as the + * JUnit 4 {@code ChromeBrowserTest}. + * + * @return a configured Chrome {@link WebDriver} + */ + static WebDriver createDriver() { + ChromeOptions options = new ChromeOptions(); + options.addArguments("--headless=new", "--disable-gpu", + "--disable-backgrounding-occluded-windows"); + // Required in CI and containers, which disable the Chrome sandbox and + // have a small /dev/shm. + options.addArguments("--no-sandbox", "--disable-dev-shm-usage"); + if (USE_HUB) { + return new RemoteWebDriver(getHubURL(), options); + } + return new ChromeDriver(options); + } + + /** + * Returns the host name the browser opens the application on: this + * machine's site local address when the browser runs on the hub, as + * {@code localhost} there is the hub itself, and {@code localhost} + * otherwise. + * + * @return the host name of the application for the browser + */ + static String deploymentHostname() { + return USE_HUB ? IPAddress.findSiteLocalAddress() : "localhost"; + } + + private static URL getHubURL() { + // Fall back to localhost, the @RunOnHub default, when no hub host + // name is given, instead of "http://null:4444/wd/hub". + String hostname = Parameters.getHubHostname(); + if (hostname == null || hostname.isBlank()) { + hostname = "localhost"; + } + String hub = "http://" + hostname + ":" + Parameters.getHubPort() + + "/wd/hub"; + try { + return URI.create(hub).toURL(); + } catch (MalformedURLException e) { + throw new IllegalStateException("invalid hub URL " + hub, e); + } + } +} diff --git a/flow-tests/test-devloop/test-devloop-tomee/devloop-app/pom.xml b/flow-tests/test-devloop/test-devloop-tomee/devloop-app/pom.xml index 61565af75cc..0dc9d30239c 100644 --- a/flow-tests/test-devloop/test-devloop-tomee/devloop-app/pom.xml +++ b/flow-tests/test-devloop/test-devloop-tomee/devloop-app/pom.xml @@ -180,6 +180,7 @@ . The dev loop's own flags cannot carry it: tomee-plugin.args is the channel it takes for its agents. --> false + ${vaadin.devmode.hostsAllowed}