Skip to content

Commit

Permalink
[grid] Adding back a couple of WebDriver tests for the Grid UI
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Feb 17, 2021
1 parent 68b17ed commit e9b3e7a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,45 @@
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;
import org.openqa.selenium.grid.config.MemoizedConfig;
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<WebDriver> wait;

@Before
Expand All @@ -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<WebElement> 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() {
Expand All @@ -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<String, Object> 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<String, Object> status = Values.get(response, MAP_TYPE);
return status != null && Boolean.TRUE.equals(status.get("ready"));
});
}

}
9 changes: 8 additions & 1 deletion javascript/grid-ui/src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,21 @@ export default function NavBar(props) {
justifyContent="center"
mt={2}
mb={2}
data-testid={"concurrency-usage"}
>
<CircularProgressWithLabel value={currentLoad}/>
</Box>
<Typography
align="center"
variant="h4"
>
{sessionCount} / {maxSession}
<Box display='inline' data-testid={"session-count"}>
{sessionCount}
</Box>
{' / '}
<Box display='inline' data-testid={"max-session"}>
{maxSession}
</Box>
</Typography>
</Box>
)}
Expand Down
5 changes: 4 additions & 1 deletion javascript/grid-ui/src/components/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export default function Node(props) {
className={classes.osLogo}
alt="OS Logo"
/>
<IconButton className={classes.buttonMargin} onClick={handleDialogOpen}>
<IconButton
className={classes.buttonMargin}
onClick={handleDialogOpen}
data-testid={`node-info-${nodeInfo.id}`}>
<InfoIcon/>
</IconButton>
<Dialog onClose={handleDialogClose} aria-labelledby="node-info-dialog" open={open}>
Expand Down
2 changes: 1 addition & 1 deletion javascript/grid-ui/src/components/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default function TopBar() {
<IconButton
edge="start"
color="inherit"
aria-label="close drawer"
aria-label="help"
href={"#help"}
className={clsx(classes.menuButton, !connectionError && classes.menuButtonHidden)}
>
Expand Down

0 comments on commit e9b3e7a

Please sign in to comment.