Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Add JSpecify annotations for WebDriver and 3 other interfaces #14371

Merged
merged 2 commits into from
Aug 14, 2024
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
9 changes: 6 additions & 3 deletions java/src/org/openqa/selenium/JavascriptExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.internal.Require;

/**
Expand All @@ -30,6 +32,7 @@
* request or when trying to access another frame. Most times when troubleshooting failure it's best
* to view the browser's console after executing the WebDriver request.
*/
@NullMarked
public interface JavascriptExecutor {
/**
* Executes JavaScript in the context of the currently selected frame or window. The script
Expand Down Expand Up @@ -63,7 +66,7 @@ public interface JavascriptExecutor {
* @param args The arguments to the script. May be empty
* @return One of Boolean, Long, Double, String, List, Map or WebElement. Or null.
*/
Object executeScript(String script, Object... args);
@Nullable Object executeScript(String script, @Nullable Object... args);

/**
* Execute an asynchronous piece of JavaScript in the context of the currently selected frame or
Expand Down Expand Up @@ -139,7 +142,7 @@ public interface JavascriptExecutor {
* @return One of Boolean, Long, String, List, Map, WebElement, or null.
* @see WebDriver.Timeouts#scriptTimeout(java.time.Duration)
*/
Object executeAsyncScript(String script, Object... args);
@Nullable Object executeAsyncScript(String script, @Nullable Object... args);

/**
* Commonly used scripts may be "pinned" to the WebDriver session, allowing them to be called
Expand Down Expand Up @@ -186,7 +189,7 @@ default Set<ScriptKey> getPinnedScripts() {
*
* @see #executeScript(String, Object...)
*/
default Object executeScript(ScriptKey key, Object... args) {
default @Nullable Object executeScript(ScriptKey key, @Nullable Object... args) {
Require.stateCondition(
key instanceof UnpinnedScriptKey, "Script key should have been generated by this driver");

Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/OutputType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Base64;
import org.jspecify.annotations.NullMarked;

/**
* Defines the output type for a screenshot.
*
* @see TakesScreenshot
* @param <T> Type for the screenshot output.
*/
@NullMarked
public interface OutputType<T> {
/** Obtain the screenshot as base64 data. */
OutputType<String> BASE64 =
Expand Down
3 changes: 3 additions & 0 deletions java/src/org/openqa/selenium/TakesScreenshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// under the License.
package org.openqa.selenium;

import org.jspecify.annotations.NullMarked;

/**
* Indicates a driver or an HTML element that can capture a screenshot and store it in different
* ways.
Expand All @@ -29,6 +31,7 @@
*
* @see OutputType
*/
@NullMarked
public interface TakesScreenshot {
/**
* Capture the screenshot and store it in the specified location.
Expand Down
11 changes: 7 additions & 4 deletions java/src/org/openqa/selenium/WebDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.logging.Logs;

Expand All @@ -46,6 +48,7 @@
* <p>Most implementations of this interface follow <a href="https://w3c.github.io/webdriver/">W3C
* WebDriver specification</a>
*/
@NullMarked
public interface WebDriver extends SearchContext {
// Navigation

Expand Down Expand Up @@ -74,7 +77,7 @@ public interface WebDriver extends SearchContext {
*
* @return The URL of the page currently loaded in the browser
*/
String getCurrentUrl();
@Nullable String getCurrentUrl();

// General properties

Expand All @@ -87,7 +90,7 @@ public interface WebDriver extends SearchContext {
* @return The title of the current page, with leading and trailing whitespace stripped, or null
* if one is not already set
*/
String getTitle();
@Nullable String getTitle();

/**
* Find all elements within the current page using the given mechanism. This method is affected by
Expand Down Expand Up @@ -142,7 +145,7 @@ public interface WebDriver extends SearchContext {
*
* @return The source of the current page
*/
String getPageSource();
@Nullable String getPageSource();

/**
* Close the current window, quitting the browser if it's the last window currently open.
Expand Down Expand Up @@ -261,7 +264,7 @@ interface Options {
* @param name the name of the cookie
* @return the cookie, or null if no cookie with the given name is present
*/
Cookie getCookieNamed(String name);
@Nullable Cookie getCookieNamed(String name);

/**
* @return the interface for managing driver timeouts.
Expand Down
Loading