-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[grid + cdp]: add a smoke test for grid cdp propagation
This is being used to guide development, and so isn't complete yet.
- Loading branch information
Showing
6 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
java/server/test/org/openqa/selenium/grid/SmokeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// 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; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.openqa.selenium.grid.commands.MessageBusCommand; | ||
import org.openqa.selenium.grid.config.MapConfig; | ||
import org.openqa.selenium.grid.distributor.httpd.DistributorServer; | ||
import org.openqa.selenium.grid.node.httpd.NodeServer; | ||
import org.openqa.selenium.grid.router.httpd.RouterServer; | ||
import org.openqa.selenium.grid.server.BaseServerOptions; | ||
import org.openqa.selenium.grid.server.Server; | ||
import org.openqa.selenium.grid.sessionmap.httpd.SessionMapServer; | ||
import org.openqa.selenium.grid.web.Values; | ||
import org.openqa.selenium.net.PortProber; | ||
import org.openqa.selenium.netty.server.NettyServer; | ||
import org.openqa.selenium.remote.http.Contents; | ||
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.testing.drivers.Browser; | ||
|
||
import java.io.UncheckedIOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import static java.time.Duration.ofSeconds; | ||
import static org.assertj.core.api.Assertions.fail; | ||
import static org.assertj.core.api.Assumptions.assumeThat; | ||
import static org.openqa.selenium.json.Json.MAP_TYPE; | ||
import static org.openqa.selenium.remote.http.HttpMethod.GET; | ||
|
||
@Ignore | ||
public class SmokeTest { | ||
|
||
@Test | ||
public void ensureBasicFunctionality() throws MalformedURLException { | ||
Browser browser = Objects.requireNonNull(Browser.detect()); | ||
|
||
assumeThat(browser.supportsCdp()).isTrue(); | ||
|
||
int messagePublishPort = PortProber.findFreePort(); | ||
int messageSubscribePort = PortProber.findFreePort(); | ||
String[] eventBusFlags = new String[]{"--publish-events", "tcp://*:" + messagePublishPort, "--subscribe-events", "tcp://*:" + messageSubscribePort}; | ||
|
||
int messageBusPort = PortProber.findFreePort(); | ||
new MessageBusCommand().configure( | ||
System.out, | ||
System.err, | ||
mergeArgs(eventBusFlags, "--port", "" + messageBusPort)).run(); | ||
waitUntilUp(messageBusPort); | ||
|
||
int sessionsPort = PortProber.findFreePort(); | ||
new SessionMapServer().configure( | ||
System.out, | ||
System.err, | ||
mergeArgs(eventBusFlags, "--bind-bus", "false", "--port", "" + sessionsPort)).run(); | ||
waitUntilUp(sessionsPort); | ||
|
||
int distributorPort = PortProber.findFreePort(); | ||
new DistributorServer().configure( | ||
System.out, | ||
System.err, | ||
mergeArgs(eventBusFlags, "--bind-bus", "false", "--port", "" + distributorPort, "-s", "http://localhost:" + sessionsPort)).run(); | ||
waitUntilUp(distributorPort); | ||
|
||
int routerPort = PortProber.findFreePort(); | ||
new RouterServer().configure( | ||
System.out, | ||
System.err, | ||
"--port", "" + routerPort, "-s", "http://localhost:" + sessionsPort, "-d", "http://localhost:" + distributorPort).run(); | ||
waitUntilUp(routerPort); | ||
|
||
int nodePort = PortProber.findFreePort(); | ||
new NodeServer().configure( | ||
System.out, | ||
System.err, | ||
mergeArgs(eventBusFlags, "--port", "" + nodePort, "-I", getBrowserShortName(), "--public-url", "http://localhost:" + routerPort)).run(); | ||
waitUntilUp(nodePort); | ||
|
||
HttpClient client = HttpClient.Factory.createDefault().createClient(new URL("http://localhost:" + routerPort)); | ||
new FluentWait<>(client).withTimeout(ofSeconds(10)).until(c -> { | ||
HttpResponse res = c.execute(new HttpRequest(GET, "/status")); | ||
if (!res.isSuccessful()) { | ||
return false; | ||
} | ||
Map<String, Object> value = Values.get(res, MAP_TYPE); | ||
if (value == null) { | ||
return false; | ||
} | ||
return Boolean.TRUE.equals(value.get("ready")); | ||
}); | ||
|
||
Server<?> server = new NettyServer( | ||
new BaseServerOptions(new MapConfig(ImmutableMap.of())), | ||
req -> new HttpResponse().setContent(Contents.utf8String("I like cheese"))) | ||
.start(); | ||
|
||
fail("Oh noes!"); | ||
} | ||
|
||
private String[] mergeArgs(String[] baseFlags, String... allTheArgs) { | ||
int length = baseFlags.length + allTheArgs.length; | ||
|
||
String[] args = new String[length]; | ||
|
||
System.arraycopy(baseFlags, 0, args, 0, baseFlags.length); | ||
System.arraycopy(allTheArgs, 0, args, baseFlags.length, allTheArgs.length); | ||
|
||
return args; | ||
} | ||
|
||
private void waitUntilUp(int port) { | ||
try { | ||
HttpClient.Factory clientFactory = HttpClient.Factory.createDefault(); | ||
HttpClient client = clientFactory.createClient(new URL("http://localhost:" + port)); | ||
|
||
new FluentWait<>(client) | ||
.ignoring(UncheckedIOException.class) | ||
.withTimeout(ofSeconds(15)) | ||
.until(http -> http.execute(new HttpRequest(GET, "/status")).isSuccessful()); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private String getBrowserShortName() { | ||
switch (System.getProperty("selenium.browser")) { | ||
case "chrome": | ||
case "edge": | ||
case "ie": | ||
return System.getProperty("selenium.browser"); | ||
|
||
case "ff": | ||
return "firefox"; | ||
|
||
case "safari": | ||
return "Safari Technology Preview"; | ||
|
||
default: | ||
throw new RuntimeException("Unknown browser: " + System.getProperty("selenium.browser")); | ||
} | ||
} | ||
} |