Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions java/src/org/openqa/selenium/Capabilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.openqa.selenium;

import static java.util.Objects.requireNonNull;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -70,6 +72,16 @@ default String getBrowserVersion() {
*/
@Nullable Object getCapability(String capabilityName);

@SuppressWarnings("unchecked")
default @Nullable <T> T get(String capabilityName) {
return (T) getCapability(capabilityName);
}

default <T> T required(String capabilityName) {
return requireNonNull(
get(capabilityName), () -> "Capability " + capabilityName + " is not set");
}

/**
* @param capabilityName The capability to check.
* @return Whether the value is not null and not false.
Expand Down
3 changes: 0 additions & 3 deletions java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.google.auto.service.AutoService;
import java.util.Optional;
import java.util.logging.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.SessionNotCreatedException;
Expand All @@ -34,8 +33,6 @@

@AutoService(WebDriverInfo.class)
public class ChromeDriverInfo extends ChromiumDriverInfo {
private static final Logger LOG = Logger.getLogger(ChromeDriverInfo.class.getName());

@Override
public String getDisplayName() {
return "Chrome";
Expand Down
21 changes: 21 additions & 0 deletions java/src/org/openqa/selenium/chrome/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

@NullMarked
package org.openqa.selenium.chrome;

import org.jspecify.annotations.NullMarked;
8 changes: 5 additions & 3 deletions java/src/org/openqa/selenium/chromium/AddHasCasting.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.openqa.selenium.chromium;

import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNullElse;

import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
Expand Down Expand Up @@ -51,10 +54,9 @@ public Class<HasCasting> getDescribedInterface() {
@Override
public HasCasting getImplementation(Capabilities capabilities, ExecuteMethod executeMethod) {
return new HasCasting() {
@SuppressWarnings("unchecked")
@Override
public List<Map<String, String>> getCastSinks() {
return (List<Map<String, String>>) executeMethod.execute(GET_CAST_SINKS, null);
return requireNonNullElse(executeMethod.execute(GET_CAST_SINKS, null), emptyList());
}

@Override
Expand All @@ -80,7 +82,7 @@ public void startTabMirroring(String deviceName) {

@Override
public String getCastIssueMessage() {
return executeMethod.execute(GET_CAST_ISSUE_MESSAGE, null).toString();
return executeMethod.executeRequired(GET_CAST_ISSUE_MESSAGE, null).toString();
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions java/src/org/openqa/selenium/chromium/AddHasCdp.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ public HasCdp getImplementation(Capabilities capabilities, ExecuteMethod execute
Require.nonNull("Command name", commandName);
Require.nonNull("Parameters", parameters);

Map<String, Object> toReturn =
(Map<String, Object>)
executeMethod.execute(EXECUTE_CDP, Map.of("cmd", commandName, "params", parameters));

return Map.copyOf(toReturn);
return executeMethod.executeRequired(
EXECUTE_CDP, Map.of("cmd", commandName, "params", parameters));
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.chromium;

import static java.util.Objects.requireNonNull;
import static org.openqa.selenium.chromium.ChromiumDriver.IS_CHROMIUM_BROWSER;
import static org.openqa.selenium.chromium.ChromiumNetworkConditions.DOWNLOAD_THROUGHPUT;
import static org.openqa.selenium.chromium.ChromiumNetworkConditions.LATENCY;
Expand Down Expand Up @@ -77,9 +76,7 @@ public HasNetworkConditions getImplementation(
@Override
public ChromiumNetworkConditions getNetworkConditions() {
@SuppressWarnings("unchecked")
Map<String, Object> result =
(Map<String, Object>)
requireNonNull(executeMethod.execute(GET_NETWORK_CONDITIONS, null));
Map<String, Object> result = executeMethod.executeRequired(GET_NETWORK_CONDITIONS, null);
return new ChromiumNetworkConditions()
.setOffline((Boolean) result.getOrDefault(OFFLINE, false))
.setLatency(Duration.ofMillis((Long) result.getOrDefault(LATENCY, 0)))
Expand Down
13 changes: 4 additions & 9 deletions java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openqa.selenium.chromium;

import static java.util.Collections.emptyList;
import static org.openqa.selenium.remote.Browser.CHROME;
import static org.openqa.selenium.remote.Browser.EDGE;
import static org.openqa.selenium.remote.Browser.OPERA;
Expand All @@ -32,7 +33,6 @@
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.BuildInfo;
import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -69,7 +69,6 @@
* A {@link WebDriver} implementation that controls a Chromium browser running on the local machine.
* It is used as the base class for Chromium-based browser drivers (Chrome, Edge).
*/
@NullMarked
public class ChromiumDriver extends RemoteWebDriver
implements HasAuthentication,
HasBiDi,
Expand Down Expand Up @@ -250,8 +249,9 @@ public void unpin(ScriptKey key) {
"Page.removeScriptToEvaluateOnNewDocument", Map.of("identifier", key.getIdentifier())));
}

@Nullable
@Override
public Object executeScript(ScriptKey key, Object... args) {
public Object executeScript(ScriptKey key, @Nullable Object... args) {
int hashCode = getScriptId(key);

String scriptToUse =
Expand Down Expand Up @@ -342,7 +342,7 @@ public Optional<BiDi> maybeGetBiDi() {
@Override
public List<Map<String, String>> getCastSinks() {
if (this.casting == null) {
return List.of();
return emptyList();
}

return casting.getCastSinks();
Expand Down Expand Up @@ -415,9 +415,4 @@ public void setNetworkConditions(ChromiumNetworkConditions networkConditions) {
public void deleteNetworkConditions() {
networkConditions.deleteNetworkConditions();
}

@Override
public void quit() {
super.quit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String toString() {
}

@Nullable
public static ChromiumDriverLogLevel fromString(String text) {
public static ChromiumDriverLogLevel fromString(@Nullable String text) {
if (text != null) {
for (ChromiumDriverLogLevel b : ChromiumDriverLogLevel.values()) {
if (text.equalsIgnoreCase(b.toString())) {
Expand Down
Loading
Loading