From e9b3e7a3f4387ed4b869c5ff54effb7e7b3438e9 Mon Sep 17 00:00:00 2001 From: Diego Molina Date: Wed, 17 Feb 2021 20:01:52 +0100 Subject: [PATCH] [grid] Adding back a couple of WebDriver tests for the Grid UI --- .../openqa/selenium/grid/web/GridUiRoute.java | 2 +- .../grid/gridui/HubConsolePageTest.java | 108 ------------------ ...solePageTest.java => OverallGridTest.java} | 63 ++++++---- .../grid-ui/src/components/NavBar/NavBar.tsx | 9 +- .../grid-ui/src/components/Node/Node.tsx | 5 +- .../grid-ui/src/components/TopBar/TopBar.tsx | 2 +- 6 files changed, 56 insertions(+), 133 deletions(-) delete mode 100644 java/server/test/org/openqa/selenium/grid/gridui/HubConsolePageTest.java rename java/server/test/org/openqa/selenium/grid/gridui/{ConsolePageTest.java => OverallGridTest.java} (59%) diff --git a/java/server/src/org/openqa/selenium/grid/web/GridUiRoute.java b/java/server/src/org/openqa/selenium/grid/web/GridUiRoute.java index 7fcdfc7a0cb8c..76381e451617a 100644 --- a/java/server/src/org/openqa/selenium/grid/web/GridUiRoute.java +++ b/java/server/src/org/openqa/selenium/grid/web/GridUiRoute.java @@ -48,7 +48,7 @@ public GridUiRoute() { routes = Route.combine( get("/").to(() -> req -> uiRedirect), get("/grid/console").to(() -> req -> uiRedirect), - Route.prefix("/ui/").to(Route.matching(req -> true).to(() -> uiHandler))); + Route.prefix("/ui").to(Route.matching(req -> true).to(() -> uiHandler))); } else { LOG.warning("It was not possible to load the Grid UI."); Json json = new Json(); diff --git a/java/server/test/org/openqa/selenium/grid/gridui/HubConsolePageTest.java b/java/server/test/org/openqa/selenium/grid/gridui/HubConsolePageTest.java deleted file mode 100644 index 20252817283f5..0000000000000 --- a/java/server/test/org/openqa/selenium/grid/gridui/HubConsolePageTest.java +++ /dev/null @@ -1,108 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you 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.openqa.selenium.grid.gridui; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.grid.commands.Hub; -import org.openqa.selenium.grid.config.Config; -import org.openqa.selenium.grid.config.MemoizedConfig; -import org.openqa.selenium.grid.config.TomlConfig; -import org.openqa.selenium.grid.server.Server; -import org.openqa.selenium.net.PortProber; -import org.openqa.selenium.remote.http.HttpClient; -import org.openqa.selenium.remote.http.HttpRequest; -import org.openqa.selenium.remote.http.HttpResponse; -import org.openqa.selenium.support.ui.FluentWait; -import org.openqa.selenium.support.ui.Wait; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.openqa.selenium.testing.drivers.WebDriverBuilder; - -import java.io.StringReader; -import java.time.Duration; - -import static org.openqa.selenium.remote.http.HttpMethod.GET; -import static org.openqa.selenium.testing.Safely.safelyCall; - -public class HubConsolePageTest { - - private Server hub; - private WebDriver driver; - private Wait wait; - - private static Server createHub(int publish, int subscribe) { - String[] rawConfig = new String[] { - "[events]", - "bind = true", - "publish = \"tcp://localhost:" + publish + "\"", - "subscribe = \"tcp://localhost:" + subscribe + "\"", - "", - "[server]", - "port = " + PortProber.findFreePort(), - "registration-secret = \"cheddar\"" - }; - - Config hubConfig = new MemoizedConfig(new TomlConfig(new StringReader(String.join("\n", rawConfig)))); - - Server hubServer = new Hub().asServer(hubConfig).start(); - - waitUntilReady(hubServer, Boolean.FALSE); - - return hubServer; - } - - private static void waitUntilReady(Server server, Boolean state) { - HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl()); - - new FluentWait<>(client) - .withTimeout(Duration.ofSeconds(5)) - .until(c -> { - HttpResponse response = c.execute(new HttpRequest(GET, "/readyz")); - return response.isSuccessful(); - }); - } - - @Before - public void setFields() { - int publish = PortProber.findFreePort(); - int subscribe = PortProber.findFreePort(); - - hub = createHub(publish, subscribe); - - driver = new WebDriverBuilder().get(); - - wait = new WebDriverWait(driver, Duration.ofSeconds(5)); - } - - @After - public void stopServers() { - safelyCall(() -> driver.quit()); - safelyCall(() -> hub.stop()); - } - - @Test - public void shouldReportNoCapacityWhenNoNodesAreRegistered() { -// driver.get(whereIs(hub, "/ui/index.html#/")); -// -// WebElement element = wait.until(visibilityOfElementLocated(By.id("ring-system"))); -// -// assertEquals("0% free", element.getText()); - } -} diff --git a/java/server/test/org/openqa/selenium/grid/gridui/ConsolePageTest.java b/java/server/test/org/openqa/selenium/grid/gridui/OverallGridTest.java similarity index 59% rename from java/server/test/org/openqa/selenium/grid/gridui/ConsolePageTest.java rename to java/server/test/org/openqa/selenium/grid/gridui/OverallGridTest.java index c00507d41c911..48ea9b2b8c805 100644 --- a/java/server/test/org/openqa/selenium/grid/gridui/ConsolePageTest.java +++ b/java/server/test/org/openqa/selenium/grid/gridui/OverallGridTest.java @@ -21,7 +21,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import org.openqa.selenium.grid.commands.Standalone; import org.openqa.selenium.grid.config.Config; import org.openqa.selenium.grid.config.MapConfig; @@ -29,26 +31,35 @@ import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.web.Values; import org.openqa.selenium.net.PortProber; +import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.http.HttpClient; import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; import org.openqa.selenium.support.ui.FluentWait; import org.openqa.selenium.support.ui.Wait; import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.testing.drivers.Browser; import org.openqa.selenium.testing.drivers.WebDriverBuilder; import java.time.Duration; import java.util.Collections; +import java.util.List; import java.util.Map; +import static junit.framework.TestCase.assertEquals; +import static org.openqa.selenium.grid.gridui.Urls.whereIs; import static org.openqa.selenium.json.Json.MAP_TYPE; import static org.openqa.selenium.remote.http.HttpMethod.GET; +import static org.openqa.selenium.support.ui.ExpectedConditions.textToBe; +import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElementsLocatedBy; +import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated; import static org.openqa.selenium.testing.Safely.safelyCall; -public class ConsolePageTest { +public class OverallGridTest { private Server server; private WebDriver driver; + private WebDriver remoteWebDriver; private Wait wait; @Before @@ -57,32 +68,42 @@ public void setup() { driver = new WebDriverBuilder().get(); - wait = new WebDriverWait(driver, Duration.ofSeconds(5)); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); } @After public void tearDown() { safelyCall(() -> driver.quit()); + safelyCall(() -> remoteWebDriver.quit()); safelyCall(() -> server.stop()); } @Test - public void shouldReportAllNodesFreeWhenGridIsStartedWithoutLoad() { -// driver.get(whereIs(server, "/ui/index.html#/console")); -// -// WebElement ring = wait.until(visibilityOfElementLocated(By.id("ring-system"))); -// -// assertEquals("100% free", ring.getText()); + public void shouldReportConcurrencyZeroPercentWhenGridIsStartedWithoutLoad() { + driver.get(whereIs(server, "/ui/index.html#/sessions")); + + WebElement concurrency = wait + .until(visibilityOfElementLocated(By.cssSelector("div[data-testid='concurrency-usage']"))); + + assertEquals("0%", concurrency.getText()); } @Test - public void shouldDoSomethingExciting() { -// driver.get(whereIs(server, "/ui/index.html#/console")); -// -// WebElement element = wait.until(visibilityOfElementLocated(By.xpath("//a[contains(@href,'node')]"))); -// element.click(); -// -// wait.until(visibilityOf(driver.findElement(By.id("node-info")))); + public void shouldShowOneNodeRegistered() { + driver.get(whereIs(server, "/ui/index.html#")); + + List nodeInfoIcons = wait + .until(visibilityOfAllElementsLocatedBy(By.cssSelector("button[data-testid*='node-info-']"))); + + assertEquals(1, nodeInfoIcons.size()); + } + + @Test + public void shouldIncrementSessionCountWhenSessionStarts() { + remoteWebDriver = new RemoteWebDriver(server.getUrl(), Browser.detect().getCapabilities()); + driver.get(whereIs(server, "/ui/index.html#/sessions")); + + wait.until(textToBe(By.cssSelector("div[data-testid='session-count']"), "1")); } private Server createStandalone() { @@ -104,12 +125,12 @@ private void waitUntilReady(Server server) { HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl()); new FluentWait<>(client) - .withTimeout(Duration.ofSeconds(5)) - .until(c -> { - HttpResponse response = c.execute(new HttpRequest(GET, "/status")); - Map status = Values.get(response, MAP_TYPE); - return status != null && Boolean.TRUE.equals(status.get("ready")); - }); + .withTimeout(Duration.ofSeconds(5)) + .until(c -> { + HttpResponse response = c.execute(new HttpRequest(GET, "/status")); + Map status = Values.get(response, MAP_TYPE); + return status != null && Boolean.TRUE.equals(status.get("ready")); + }); } } diff --git a/javascript/grid-ui/src/components/NavBar/NavBar.tsx b/javascript/grid-ui/src/components/NavBar/NavBar.tsx index 4cbe6c6673187..a423aaa3373d5 100644 --- a/javascript/grid-ui/src/components/NavBar/NavBar.tsx +++ b/javascript/grid-ui/src/components/NavBar/NavBar.tsx @@ -149,6 +149,7 @@ export default function NavBar(props) { justifyContent="center" mt={2} mb={2} + data-testid={"concurrency-usage"} > @@ -156,7 +157,13 @@ export default function NavBar(props) { align="center" variant="h4" > - {sessionCount} / {maxSession} + + {sessionCount} + + {' / '} + + {maxSession} + )} diff --git a/javascript/grid-ui/src/components/Node/Node.tsx b/javascript/grid-ui/src/components/Node/Node.tsx index 484e52c30c686..48a2be23d8a53 100644 --- a/javascript/grid-ui/src/components/Node/Node.tsx +++ b/javascript/grid-ui/src/components/Node/Node.tsx @@ -140,7 +140,10 @@ export default function Node(props) { className={classes.osLogo} alt="OS Logo" /> - + diff --git a/javascript/grid-ui/src/components/TopBar/TopBar.tsx b/javascript/grid-ui/src/components/TopBar/TopBar.tsx index e2a0c44ca60cd..ff7a1f7b931e3 100644 --- a/javascript/grid-ui/src/components/TopBar/TopBar.tsx +++ b/javascript/grid-ui/src/components/TopBar/TopBar.tsx @@ -115,7 +115,7 @@ export default function TopBar() {