Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions flow-tests/test-devloop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<hub>`. 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.
6 changes: 6 additions & 0 deletions flow-tests/test-devloop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<!-- Flow only lets dev tools connect from localhost. The browser ITs on
bender.vaadin.com run on the Selenium hub, another machine, and the
dev tools are what bring an applied change into the open page, so
every fixture lets them connect from anywhere. Test applications in
dev mode only. -->
<vaadin.devmode.hostsAllowed>*</vaadin.devmode.hostsAllowed>
<!-- The ITs the maven-compile execution below runs: the ones that put the
compile leg through its paths - an apply, an edit in a sibling module,
a deleted source. -Pdevloop-maven-compile runs every IT instead. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<!-- The daemon owns this process and decides when a change goes
live, so nothing else may push to the browser on its own. -->
<vaadin.frontend.hotdeploy>false</vaadin.frontend.hotdeploy>
<vaadin.devmode.hostsAllowed>${vaadin.devmode.hostsAllowed}</vaadin.devmode.hostsAllowed>
</systemProperties>
</container>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@
<!-- The daemon owns this process and decides when a change goes
live, so nothing else may push to the browser on its own. -->
<server-arg>-Dvaadin.frontend.hotdeploy=false</server-arg>
<server-arg>-Dvaadin.devmode.hostsAllowed=${vaadin.devmode.hostsAllowed}</server-arg>
<!-- JBoss listens only on 127.0.0.1 by default. A browser on the
Selenium hub opens the application at this machine's address. -->
<server-arg>-Djboss.bind.address=0.0.0.0</server-arg>
</server-args>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<!-- The daemon owns this process and decides when a change goes
live, so nothing else may push to the browser on its own. -->
<vaadin.frontend.hotdeploy>false</vaadin.frontend.hotdeploy>
<vaadin.devmode.hostsAllowed>${vaadin.devmode.hostsAllowed}</vaadin.devmode.hostsAllowed>
</systemProperties>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
which it does not take away. -->
<jvmOptions>
<param>-Dvaadin.frontend.hotdeploy=false</param>
<param>-Dvaadin.devmode.hostsAllowed=${vaadin.devmode.hostsAllowed}</param>
</jvmOptions>
<!-- Deployed from apps/ as named in server.xml, so the view is at
http://localhost:8894/devloop/ -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@
<option>
<value>-Dvaadin.frontend.hotdeploy=false</value>
</option>
<option>
<value>-Dvaadin.devmode.hostsAllowed=${vaadin.devmode.hostsAllowed}</value>
</option>
</javaCommandLineOptions>
<!-- At the root context, so the view is at http://localhost:8896/ -->
<contextRoot>/</contextRoot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@
<option>
<value>-Dvaadin.frontend.hotdeploy=false</value>
</option>
<option>
<value>-Dvaadin.devmode.hostsAllowed=${vaadin.devmode.hostsAllowed}</value>
</option>
</javaCommandLineOptions>
</configuration>
<!-- No executions: the daemon owns the application process. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> readPomProperty(String name) {
Path pom = APP.resolve("pom.xml");
String tag = Pattern.quote(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<systemProperties>. The dev loop's own flags cannot carry it:
tomee-plugin.args is the channel it takes for its agents. -->
<vaadin.frontend.hotdeploy>false</vaadin.frontend.hotdeploy>
<vaadin.devmode.hostsAllowed>${vaadin.devmode.hostsAllowed}</vaadin.devmode.hostsAllowed>
</systemVariables>
</configuration>
<!-- No executions: the daemon owns the application process, and for
Expand Down
Loading