|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.grid.gridui; |
19 | 19 |
|
20 | | -import java.util.Objects; |
| 20 | +import com.google.common.collect.ImmutableMap; |
| 21 | + |
21 | 22 | import org.junit.jupiter.api.AfterEach; |
22 | 23 | import org.junit.jupiter.api.BeforeEach; |
23 | 24 | import org.junit.jupiter.api.Test; |
24 | 25 | import org.openqa.selenium.By; |
25 | 26 | import org.openqa.selenium.WebDriver; |
26 | 27 | import org.openqa.selenium.WebElement; |
| 28 | +import org.openqa.selenium.grid.commands.Standalone; |
| 29 | +import org.openqa.selenium.grid.config.Config; |
| 30 | +import org.openqa.selenium.grid.config.MapConfig; |
| 31 | +import org.openqa.selenium.grid.config.MemoizedConfig; |
27 | 32 | import org.openqa.selenium.grid.server.Server; |
| 33 | +import org.openqa.selenium.grid.web.Values; |
| 34 | +import org.openqa.selenium.net.PortProber; |
28 | 35 | import org.openqa.selenium.remote.RemoteWebDriver; |
| 36 | +import org.openqa.selenium.remote.http.HttpClient; |
| 37 | +import org.openqa.selenium.remote.http.HttpRequest; |
| 38 | +import org.openqa.selenium.remote.http.HttpResponse; |
| 39 | +import org.openqa.selenium.support.ui.FluentWait; |
29 | 40 | import org.openqa.selenium.support.ui.Wait; |
30 | 41 | import org.openqa.selenium.support.ui.WebDriverWait; |
31 | 42 | import org.openqa.selenium.testing.drivers.Browser; |
32 | 43 | import org.openqa.selenium.testing.drivers.WebDriverBuilder; |
33 | 44 |
|
34 | 45 | import java.time.Duration; |
| 46 | +import java.util.Collections; |
35 | 47 | import java.util.List; |
| 48 | +import java.util.Map; |
36 | 49 |
|
37 | 50 | import static org.junit.jupiter.api.Assertions.assertEquals; |
38 | 51 | import static org.openqa.selenium.grid.gridui.Urls.whereIs; |
| 52 | +import static org.openqa.selenium.json.Json.MAP_TYPE; |
| 53 | +import static org.openqa.selenium.remote.http.HttpMethod.GET; |
39 | 54 | import static org.openqa.selenium.support.ui.ExpectedConditions.textToBe; |
40 | 55 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElementsLocatedBy; |
41 | 56 | import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated; |
42 | 57 | import static org.openqa.selenium.testing.Safely.safelyCall; |
43 | 58 |
|
44 | | -class OverallGridTest extends AbstractGridTest { |
| 59 | +class OverallGridTest { |
45 | 60 |
|
46 | 61 | private Server<?> server; |
47 | 62 | private WebDriver driver; |
@@ -86,9 +101,39 @@ void shouldShowOneNodeRegistered() { |
86 | 101 |
|
87 | 102 | @Test |
88 | 103 | void shouldIncrementSessionCountWhenSessionStarts() { |
89 | | - remoteWebDriver = new RemoteWebDriver(server.getUrl(), Objects.requireNonNull(Browser.detect()).getCapabilities()); |
| 104 | + remoteWebDriver = new RemoteWebDriver(server.getUrl(), Browser.detect().getCapabilities()); |
90 | 105 | driver.get(whereIs(server, "/ui/index.html#/sessions")); |
91 | 106 |
|
92 | 107 | wait.until(textToBe(By.cssSelector("div[data-testid='session-count']"), "1")); |
93 | 108 | } |
| 109 | + |
| 110 | + private Server<?> createStandalone() { |
| 111 | + int port = PortProber.findFreePort(); |
| 112 | + |
| 113 | + Config config = new MemoizedConfig( |
| 114 | + new MapConfig(ImmutableMap.of( |
| 115 | + "server", Collections.singletonMap("port", port), |
| 116 | + "node", ImmutableMap.of("detect-drivers", true, "selenium-manager", true) |
| 117 | + ))); |
| 118 | + |
| 119 | + Server<?> server = new Standalone().asServer(config).start(); |
| 120 | + |
| 121 | + waitUntilReady(server); |
| 122 | + |
| 123 | + return server; |
| 124 | + } |
| 125 | + |
| 126 | + private void waitUntilReady(Server<?> server) { |
| 127 | + try (HttpClient client = HttpClient.Factory.createDefault().createClient(server.getUrl())) { |
| 128 | + new FluentWait<>(client) |
| 129 | + .withTimeout(Duration.ofSeconds(5)) |
| 130 | + .until( |
| 131 | + c -> { |
| 132 | + HttpResponse response = c.execute(new HttpRequest(GET, "/status")); |
| 133 | + Map<String, Object> status = Values.get(response, MAP_TYPE); |
| 134 | + return status != null && Boolean.TRUE.equals(status.get("ready")); |
| 135 | + }); |
| 136 | + } |
| 137 | + } |
| 138 | + |
94 | 139 | } |
0 commit comments