Skip to content

Commit

Permalink
Merge branch 'trunk' into node-appium
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 committed May 4, 2024
2 parents 1fa2958 + 970557d commit ffa54c7
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .bazelrc.remote
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test:remote --test_env=PATH=/bin:/usr/bin:/usr/local/bin
test:remote --test_env=HOME=/home/dev

# Make sure we sniff credentials properly
build:remote --credential_helper=%workspace%/scripts/credential-helper.sh
build:remote --credential_helper=gypsum.cluster.engflow.com=%workspace%/scripts/credential-helper.sh

# Use pinned browsers when running remotely
build:remote --//common:pin_browsers
Expand Down
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ use_repo(pip, "py_dev_requirements")

register_toolchains("@pythons_hub//:all")

# https://github.com/bazelbuild/rules_jvm_external/pull/1079
archive_override(
module_name = "rules_jvm_external",
integrity = "sha256-yS8Qes1PLbYbe10b1WSgl0Auqn/1Wlxg8O3wSr7a/Sg=",
patch_strip = 1,
patches = ["//java:rules_jvm_external_javadoc.patch"],
strip_prefix = "rules_jvm_external-f572a26116c7ef71d8842dd056c2605782f7be8d",
urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/f572a26116c7ef71d8842dd056c2605782f7be8d.tar.gz"],
)

java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
use_repo(
java_toolchains,
Expand Down
14 changes: 14 additions & 0 deletions common/src/web/select_space.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Multiple Selection test page</title>
</head>
<body>
<select id="selectWithoutMultiple">
<option value="one">one</option>
<option value="two">&nbsp;&nbsp;two</option>
<option value="three">&nbsp;&nbsp;&nbsp;three</option>
<option value="four">&nbsp;&nbsp;&nbsp;&nbsp;four</option>
<option value="five">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;five</option>
</body>
</html>
7 changes: 5 additions & 2 deletions java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,16 @@ public Optional<DevTools> maybeGetDevTools() {
}

private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
if (!biDiUri.isPresent()) {
if (biDiUri.isEmpty()) {
return Optional.empty();
}

URI wsUri =
biDiUri.orElseThrow(
() -> new BiDiException("This version of Chromium driver does not support BiDi"));
() ->
new BiDiException(
"Check if this browser version supports BiDi and if the 'webSocketUrl: true'"
+ " capability is set."));

HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
Expand Down
12 changes: 8 additions & 4 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,16 @@ public DevTools getDevTools() {
}

private Optional<BiDi> createBiDi(Optional<URI> biDiUri) {
if (!biDiUri.isPresent()) {
if (biDiUri.isEmpty()) {
return Optional.empty();
}

URI wsUri =
biDiUri.orElseThrow(
() ->
new BiDiException("This version of Firefox or geckodriver does not support BiDi"));
new BiDiException(
"Check if this browser version supports BiDi and if the 'webSocketUrl: true'"
+ " capability is set."));

HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
ClientConfig wsConfig = ClientConfig.defaultConfig().baseUri(wsUri);
Expand All @@ -380,8 +382,10 @@ public Optional<BiDi> maybeGetBiDi() {

@Override
public BiDi getBiDi() {
if (!biDiUri.isPresent()) {
throw new BiDiException("This version of Firefox or geckodriver does not support Bidi");
if (biDiUri.isEmpty()) {
throw new BiDiException(
"Check if this browser version supports BiDi and if the 'webSocketUrl: true' capability"
+ " is set.");
}

return maybeGetBiDi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -329,10 +330,11 @@ private Capabilities setBrowserBinary(Capabilities options, String browserPath)
.setCapability(vendorOptionsCapability, vendorOptions)
.setCapability("browserVersion", null);
} catch (Exception e) {
LOG.warning(
LOG.log(
Level.WARNING,
String.format(
"Exception while setting the browser binary path. %s: %s",
options, e.getMessage()));
"Exception while setting the browser binary path. Options: %s", options),
e);
}
}
}
Expand Down
20 changes: 17 additions & 3 deletions java/src/org/openqa/selenium/remote/http/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import static org.openqa.selenium.remote.http.HttpMethod.POST;
import static org.openqa.selenium.remote.http.UrlPath.ROUTE_PREFIX_KEY;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -292,7 +292,7 @@ private HttpRequest transform(HttpRequest request) {
// Don't forget to register our prefix
Object rawPrefixes = request.getAttribute(ROUTE_PREFIX_KEY);
if (!(rawPrefixes instanceof List)) {
rawPrefixes = new LinkedList<>();
rawPrefixes = Collections.emptyList();
}
List<String> prefixes =
Stream.concat(((List<?>) rawPrefixes).stream(), Stream.of(prefix))
Expand Down Expand Up @@ -321,7 +321,21 @@ private static class CombinedRoute extends Route {
private CombinedRoute(Stream<Routable> routes) {
// We want later routes to have a greater chance of being called so that we can override
// routes as necessary.
List<Routable> routables = routes.collect(Collectors.toList());
List<Routable> routables =
routes
.flatMap(
route -> {
// flatten a nested CombinedRoute
if (route instanceof CombinedRoute) {
List<Routable> nestedRoutes =
new ArrayList<>(((CombinedRoute) route).allRoutes);
// reverse to have the identical behaviour like not flattened
Collections.reverse(nestedRoutes);
return nestedRoutes.stream();
}
return Stream.of(route);
})
.collect(Collectors.toList());
Collections.reverse(routables);
allRoutes = List.copyOf(routables);
Require.stateCondition(!allRoutes.isEmpty(), "At least one route must be specified.");
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/ExecutingJavascriptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void testShouldBeAbleToExecuteABigChunkOfJavascriptCode() throws IOException {
driver.get(pages.javascriptPage);

Path jqueryFile = InProject.locate("common/src/web/js/jquery-3.5.1.min.js");
String jquery = new String(Files.readAllBytes(jqueryFile), US_ASCII);
String jquery = Files.readString(jqueryFile, US_ASCII);
assertThat(jquery.length())
.describedAs("The javascript code should be at least 50 KB.")
.isGreaterThan(50000);
Expand Down
6 changes: 3 additions & 3 deletions java/test/org/openqa/selenium/ProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void testManualProxy() {
assertThat(proxy.getHttpProxy()).isEqualTo("http.proxy:1234");
assertThat(proxy.getSslProxy()).isEqualTo("ssl.proxy");
assertThat(proxy.getSocksProxy()).isEqualTo("socks.proxy:65555");
assertThat(proxy.getSocksVersion()).isEqualTo(Integer.valueOf(5));
assertThat(proxy.getSocksVersion()).isEqualTo(5);
assertThat(proxy.getSocksUsername()).isEqualTo("test1");
assertThat(proxy.getSocksPassword()).isEqualTo("test2");
assertThat(proxy.getNoProxy()).isEqualTo("localhost,127.0.0.*");
Expand Down Expand Up @@ -184,7 +184,7 @@ void manualProxyFromMap() {
assertThat(proxy.getHttpProxy()).isEqualTo("http.proxy:1234");
assertThat(proxy.getSslProxy()).isEqualTo("ssl.proxy");
assertThat(proxy.getSocksProxy()).isEqualTo("socks.proxy:65555");
assertThat(proxy.getSocksVersion()).isEqualTo(Integer.valueOf(5));
assertThat(proxy.getSocksVersion()).isEqualTo(5);
assertThat(proxy.getSocksUsername()).isEqualTo("test1");
assertThat(proxy.getSocksPassword()).isEqualTo("test2");
assertThat(proxy.getNoProxy()).isEqualTo("localhost,127.0.0.*");
Expand All @@ -209,7 +209,7 @@ void longSocksVersionFromMap() {

Proxy proxy = new Proxy(proxyData);

assertThat(proxy.getSocksVersion()).isEqualTo(Integer.valueOf(5));
assertThat(proxy.getSocksVersion()).isEqualTo(5);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.openqa.selenium.environment.webserver;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -51,7 +49,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {

return new HttpResponse()
.setHeader("Content-Type", "text/html; charset=UTF-8")
.setContent(Contents.utf8String(new String(Files.readAllBytes(target), UTF_8)));
.setContent(Contents.utf8String(Files.readString(target)));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void shouldBeAbleToRegisterALocalNode() throws URISyntaxException {
wait.until(obj -> distributor.getStatus().hasCapacity());

NodeStatus status = getOnlyElement(distributor.getStatus().getNodes());
assertEquals(1, getStereotypes(status).get(CAPS).intValue());
assertEquals(1, getStereotypes(status).get(CAPS));
}

@Test
Expand Down Expand Up @@ -192,7 +192,7 @@ void shouldBeAbleToRegisterACustomNode() throws URISyntaxException {
wait.until(obj -> distributor.getStatus().hasCapacity());

NodeStatus status = getOnlyElement(distributor.getStatus().getNodes());
assertEquals(1, getStereotypes(status).get(CAPS).intValue());
assertEquals(1, getStereotypes(status).get(CAPS));
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ void shouldBeAbleToRegisterNodesByListeningForEvents() throws URISyntaxException
wait.until(obj -> distributor.getStatus().hasCapacity());

NodeStatus status = getOnlyElement(distributor.getStatus().getNodes());
assertEquals(1, getStereotypes(status).get(CAPS).intValue());
assertEquals(1, getStereotypes(status).get(CAPS));
}
}

Expand Down Expand Up @@ -323,7 +323,7 @@ void distributorShouldUpdateStateOfExistingNodeWhenNodePublishesStateChange()
wait.until(obj -> distributor.getStatus().hasCapacity());

NodeStatus nodeStatus = getOnlyElement(distributor.getStatus().getNodes());
assertEquals(1, getStereotypes(nodeStatus).get(CAPS).intValue());
assertEquals(1, getStereotypes(nodeStatus).get(CAPS));

// Craft a status that makes it look like the node is busy, and post it on the bus.
NodeStatus status = node.getStatus();
Expand Down
2 changes: 1 addition & 1 deletion java/test/org/openqa/selenium/json/JsonOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void shouldConvertUnhandledAlertException() {
@Test
void shouldConvertDatesToMillisecondsInUtcTime() {
String jsonStr = convert(new Date(0));
assertThat(valueOf(jsonStr).intValue()).isZero();
assertThat(valueOf(jsonStr)).isZero();
}

@Test
Expand Down
16 changes: 8 additions & 8 deletions java/test/org/openqa/selenium/json/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ void canReadBooleans() {

@Test
void canReadANumber() {
assertThat((Number) new Json().toType("42", Number.class)).isEqualTo(Long.valueOf(42));
assertThat((Integer) new Json().toType("42", Integer.class)).isEqualTo(Integer.valueOf(42));
assertThat((Double) new Json().toType("42", Double.class)).isEqualTo(Double.valueOf(42));
assertThat((Number) new Json().toType("42", Number.class)).isEqualTo(42L);
assertThat((Integer) new Json().toType("42", Integer.class)).isEqualTo(42);
assertThat((Double) new Json().toType("42", Double.class)).isEqualTo(42.0);
}

@Test
Expand Down Expand Up @@ -285,7 +285,7 @@ void canHandleValueBeingAnArray() {

assertThat(response.getSessionId()).isEqualTo("bar");
assertThat(((List<?>) converted.getValue())).hasSize(2);
assertThat(response.getStatus().intValue()).isEqualTo(1512);
assertThat(response.getStatus()).isEqualTo(1512);
}

@Test
Expand Down Expand Up @@ -426,7 +426,7 @@ void decodingResponseWithNumbersInValueObject() {
void shouldRecognizeNumericStatus() {
Response response = new Json().toType("{\"status\":0,\"value\":\"cheese\"}", Response.class);

assertThat(response.getStatus().intValue()).isZero();
assertThat(response.getStatus()).isZero();
assertThat(response.getState()).isEqualTo(new ErrorCodes().toState(0));
String value = (String) response.getValue();
assertThat(value).isEqualTo("cheese");
Expand All @@ -437,7 +437,7 @@ void shouldRecognizeStringStatus() {
Response response =
new Json().toType("{\"status\":\"success\",\"value\":\"cheese\"}", Response.class);

assertThat(response.getStatus().intValue()).isZero();
assertThat(response.getStatus()).isZero();
assertThat(response.getState()).isEqualTo(new ErrorCodes().toState(0));
String value = (String) response.getValue();
assertThat(value).isEqualTo("cheese");
Expand All @@ -450,7 +450,7 @@ void shouldConvertInvalidSelectorError() {
.toType(
"{\"state\":\"invalid selector\",\"message\":\"invalid xpath selector\"}",
Response.class);
assertThat(response.getStatus().intValue()).isEqualTo(32);
assertThat(response.getStatus()).isEqualTo(32);
assertThat(response.getState()).isEqualTo(new ErrorCodes().toState(32));
}

Expand All @@ -459,7 +459,7 @@ void shouldRecognizeStringState() {
Response response =
new Json().toType("{\"state\":\"success\",\"value\":\"cheese\"}", Response.class);
assertThat(response.getState()).isEqualTo("success");
assertThat(response.getStatus().intValue()).isZero();
assertThat(response.getStatus()).isZero();
String value = (String) response.getValue();
assertThat(value).isEqualTo("cheese");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ void canCompareCapabilities() {
}

private String createString(int length) {
StringBuilder outputBuffer = new StringBuilder(length);
for (int i = 0; i < length; i++) {
outputBuffer.append("x");
}
return outputBuffer.toString();
return "x".repeat(Math.max(0, length));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void shouldBeAbleToHandleGatewayTimeoutError() {

Response decoded = new W3CHttpResponseCodec().decode(response);

assertThat(decoded.getStatus().intValue()).isEqualTo(ErrorCodes.UNHANDLED_ERROR);
assertThat(decoded.getStatus()).isEqualTo(ErrorCodes.UNHANDLED_ERROR);
assertThat(decoded.getValue()).isEqualTo(responseString);
}

Expand All @@ -104,7 +104,7 @@ void shouldBeAbleToHandleBadGatewayError() {

Response decoded = new W3CHttpResponseCodec().decode(response);

assertThat(decoded.getStatus().intValue()).isEqualTo(ErrorCodes.UNHANDLED_ERROR);
assertThat(decoded.getStatus()).isEqualTo(ErrorCodes.UNHANDLED_ERROR);
assertThat(decoded.getValue()).isEqualTo(responseString);
}

Expand All @@ -120,7 +120,7 @@ void decodingAnErrorWithoutAStacktraceIsDecodedProperlyForNonCompliantImplementa
Response decoded = new W3CHttpResponseCodec().decode(response);

assertThat(decoded.getState()).isEqualTo("unsupported operation");
assertThat(decoded.getStatus().intValue()).isEqualTo(METHOD_NOT_ALLOWED);
assertThat(decoded.getStatus()).isEqualTo(METHOD_NOT_ALLOWED);

assertThat(decoded.getValue()).isInstanceOf(UnsupportedCommandException.class);
assertThat(((WebDriverException) decoded.getValue()).getMessage()).contains("I like peas");
Expand All @@ -140,7 +140,7 @@ void decodingAnErrorWithoutAStacktraceIsDecodedProperlyForConformingImplementati
Response decoded = new W3CHttpResponseCodec().decode(response);

assertThat(decoded.getState()).isEqualTo("unsupported operation");
assertThat(decoded.getStatus().intValue()).isEqualTo(METHOD_NOT_ALLOWED);
assertThat(decoded.getStatus()).isEqualTo(METHOD_NOT_ALLOWED);

assertThat(decoded.getValue()).isInstanceOf(UnsupportedCommandException.class);
assertThat(((WebDriverException) decoded.getValue()).getMessage()).contains("I like peas");
Expand Down
7 changes: 5 additions & 2 deletions java/test/org/openqa/selenium/remote/http/RouteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ void laterRoutesOverrideEarlierRoutesToFacilitateOverridingRoutes() {
HttpHandler handler =
Route.combine(
Route.get("/hello").to(() -> req -> new HttpResponse().setContent(utf8String("world"))),
Route.get("/hello")
.to(() -> req -> new HttpResponse().setContent(utf8String("buddy"))));
Route.combine(
Route.get("/hello")
.to(() -> req -> new HttpResponse().setContent(utf8String("world"))),
Route.get("/hello")
.to(() -> req -> new HttpResponse().setContent(utf8String("buddy")))));

HttpResponse response = handler.execute(new HttpRequest(GET, "/hello"));
assertThat(string(response)).isEqualTo("buddy");
Expand Down

0 comments on commit ffa54c7

Please sign in to comment.