Skip to content

Commit

Permalink
Merge branch 'trunk' into renovate/firefox_standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Dec 23, 2024
2 parents ddab1d9 + cc5ca35 commit e8134d0
Show file tree
Hide file tree
Showing 33 changed files with 115 additions and 73 deletions.
26 changes: 12 additions & 14 deletions dotnet/src/webdriver/SessionId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@
// under the License.
// </copyright>

using System;

#nullable enable

namespace OpenQA.Selenium
{
/// <summary>
/// Provides a mechanism for maintaining a session for a test
/// </summary>
public class SessionId
{
private string sessionOpaqueKey;
private readonly string sessionOpaqueKey;

/// <summary>
/// Initializes a new instance of the <see cref="SessionId"/> class
/// </summary>
/// <param name="opaqueKey">Key for the session in use</param>
/// <exception cref="ArgumentNullException">If <paramref name="opaqueKey"/> is <see langword="null"/>.</exception>
public SessionId(string opaqueKey)
{
this.sessionOpaqueKey = opaqueKey;
this.sessionOpaqueKey = opaqueKey ?? throw new ArgumentNullException(nameof(opaqueKey));
}

/// <summary>
Expand All @@ -54,20 +59,13 @@ public override int GetHashCode()
}

/// <summary>
/// Compares two Sessions
/// Indicates whether the current session ID value is the same as <paramref name="obj"/>.
/// </summary>
/// <param name="obj">Session to compare</param>
/// <returns>True if they are equal or False if they are not</returns>
public override bool Equals(object obj)
/// <param name="obj">The session to compare to.</param>
/// <returns><see langword="true"/> if the values are equal; otherwise, <see langword="false"/>.</returns>
public override bool Equals(object? obj)
{
bool objectsAreEqual = false;
SessionId other = obj as SessionId;
if (other != null)
{
objectsAreEqual = this.sessionOpaqueKey.Equals(other.sessionOpaqueKey);
}

return objectsAreEqual;
return obj is SessionId otherSession && this.sessionOpaqueKey.Equals(otherSession.sessionOpaqueKey);
}
}
}
19 changes: 10 additions & 9 deletions dotnet/src/webdriver/WebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading.Tasks;

Expand All @@ -44,7 +45,7 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
private IFileDetector fileDetector = new DefaultFileDetector();
private NetworkManager network;
private WebElementFactory elementFactory;
private SessionId sessionId;

private List<string> registeredCommands = new List<string>();

/// <summary>
Expand Down Expand Up @@ -191,10 +192,7 @@ public bool IsActionExecutor
/// <summary>
/// Gets the <see cref="SessionId"/> for the current session of this driver.
/// </summary>
public SessionId SessionId
{
get { return this.sessionId; }
}
public SessionId SessionId { get; private set; }

/// <summary>
/// Gets or sets the <see cref="IFileDetector"/> responsible for detecting
Expand Down Expand Up @@ -612,7 +610,7 @@ protected virtual Response Execute(string driverCommandToExecute,
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
{
Command commandToExecute = new Command(this.sessionId, driverCommandToExecute, parameters);
Command commandToExecute = new Command(SessionId, driverCommandToExecute, parameters);

Response commandResponse;

Expand Down Expand Up @@ -641,6 +639,7 @@ protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecut
/// Starts a session with the driver
/// </summary>
/// <param name="capabilities">Capabilities of the browser</param>
[MemberNotNull(nameof(SessionId))]
protected void StartSession(ICapabilities capabilities)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
Expand Down Expand Up @@ -679,7 +678,9 @@ protected void StartSession(ICapabilities capabilities)

ReturnedCapabilities returnedCapabilities = new ReturnedCapabilities(rawCapabilities);
this.capabilities = returnedCapabilities;
this.sessionId = new SessionId(response.SessionId);

string sessionId = response.SessionId ?? throw new WebDriverException($"The remote end did not respond with ID of a session when it was required. {response.Value}");
this.SessionId = new SessionId(sessionId);
}

/// <summary>
Expand Down Expand Up @@ -723,7 +724,7 @@ protected virtual void Dispose(bool disposing)
{
try
{
if (this.sessionId is not null)
if (this.SessionId is not null)
{
this.Execute(DriverCommand.Quit, null);
}
Expand All @@ -739,7 +740,7 @@ protected virtual void Dispose(bool disposing)
}
finally
{
this.sessionId = null;
this.SessionId = null;
}
this.executor.Dispose();
}
Expand Down
6 changes: 3 additions & 3 deletions dotnet/test/common/DevTools/DevToolsProfilerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ private void ValidateProfile(CurrentCdpVersion.Profiler.Profile profiler)
{
Assert.That(profiler, Is.Not.Null);
Assert.That(profiler.Nodes, Is.Not.Null);
Assert.That(profiler.StartTime, Is.Not.Null);
Assert.That(profiler.EndTime, Is.Not.Null);
Assert.That(profiler.StartTime, Is.Not.Zero);
Assert.That(profiler.EndTime, Is.Not.Zero);
Assert.That(profiler.TimeDeltas, Is.Not.Null);
foreach (var delta in profiler.TimeDeltas)
{
Assert.That(delta, Is.Not.Null);
Assert.That(delta, Is.Not.Zero);
}

foreach (var node in profiler.Nodes)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/DevTools/DevToolsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Setup()
devTools = driver as IDevTools;
if (devTools == null)
{
Assert.Ignore("{0} does not support Chrome DevTools Protocol", EnvironmentManager.Instance.Browser);
Assert.Ignore($"{EnvironmentManager.Instance.Browser} does not support Chrome DevTools Protocol");
return;
}

Expand Down
6 changes: 4 additions & 2 deletions java/src/org/openqa/selenium/Architecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.openqa.selenium;

import java.util.Locale;

/**
* Represents the known architectures used in WebDriver. It attempts to smooth over some of Java's
* rough edges when dealing with microprocessor architectures by, for instance, allowing you to
Expand Down Expand Up @@ -98,7 +100,7 @@ public int getDataModel() {

@Override
public String toString() {
return name().toLowerCase();
return name().toLowerCase(Locale.ENGLISH);
}

/**
Expand All @@ -121,7 +123,7 @@ public static Architecture getCurrent() {
*/
public static Architecture extractFromSysProperty(String arch) {
if (arch != null) {
arch = arch.toLowerCase();
arch = arch.toLowerCase(Locale.ENGLISH);
}

// Some architectures are basically the same even though they have different names. ia32, x86,
Expand Down
5 changes: 3 additions & 2 deletions java/src/org/openqa/selenium/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium;

import java.util.Arrays;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -414,7 +415,7 @@ public static Platform extractFromSysProperty(String osName) {
* @return the most likely platform based on given operating system name and version
*/
public static Platform extractFromSysProperty(String osName, String osVersion) {
osName = osName.toLowerCase();
osName = osName.toLowerCase(Locale.ENGLISH);
// os.name for android is linux
if ("dalvik".equalsIgnoreCase(System.getProperty("java.vm.name"))) {
return Platform.ANDROID;
Expand All @@ -434,7 +435,7 @@ public static Platform extractFromSysProperty(String osName, String osVersion) {
if ("".equals(matcher)) {
continue;
}
matcher = matcher.toLowerCase();
matcher = matcher.toLowerCase(Locale.ENGLISH);
if (os.isExactMatch(osName, matcher)) {
return os;
}
Expand Down
6 changes: 4 additions & 2 deletions java/src/org/openqa/selenium/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -93,7 +94,8 @@ public Proxy() {
public Proxy(Map<String, ?> raw) {
Map<String, Consumer<Object>> setters = new HashMap<>();
setters.put(
PROXY_TYPE, value -> setProxyType(ProxyType.valueOf(((String) value).toUpperCase())));
PROXY_TYPE,
value -> setProxyType(ProxyType.valueOf(((String) value).toUpperCase(Locale.ENGLISH))));
setters.put(FTP_PROXY, value -> setFtpProxy((String) value));
setters.put(HTTP_PROXY, value -> setHttpProxy((String) value));
setters.put(
Expand Down Expand Up @@ -448,7 +450,7 @@ public String toString() {
case DIRECT:
case MANUAL:
case SYSTEM:
builder.append(getProxyType().toString().toLowerCase());
builder.append(getProxyType().toString().toLowerCase(Locale.ENGLISH));
break;

case PAC:
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/chrome/ChromeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
Expand Down Expand Up @@ -300,7 +301,7 @@ protected List<String> createArgs() {
}

if (logLevel != null) {
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase()));
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase(Locale.ENGLISH)));
}
if (allowedListIps != null) {
args.add(String.format("--allowed-ips=%s", allowedListIps));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openqa.selenium.chromium;

import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;

Expand Down Expand Up @@ -46,7 +47,7 @@ public enum ChromiumDriverLogLevel {

@Override
public String toString() {
return super.toString().toLowerCase();
return super.toString().toLowerCase(Locale.ENGLISH);
}

public static ChromiumDriverLogLevel fromString(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.openqa.selenium.remote.http.Contents.utf8String;

import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void close() {
protected HttpMethod convertFromCdpHttpMethod(String method) {
Require.nonNull("HTTP Method", method);
try {
return HttpMethod.valueOf(method.toUpperCase());
return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
// Spam in a reasonable value
return HttpMethod.GET;
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/devtools/idealized/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -300,7 +301,7 @@ protected Optional<Credentials> getAuthCredentials(URI uri) {
protected HttpMethod convertFromCdpHttpMethod(String method) {
Require.nonNull("HTTP Method", method);
try {
return HttpMethod.valueOf(method.toUpperCase());
return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
// Spam in a reasonable value
return HttpMethod.GET;
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/edge/EdgeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
Expand Down Expand Up @@ -294,7 +295,7 @@ protected List<String> createArgs() {
}

if (logLevel != null) {
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase()));
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase(Locale.ENGLISH)));
}
if (Boolean.TRUE.equals(silent)) {
args.add("--silent");
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/firefox/FirefoxBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -72,7 +73,7 @@ public String toString() {
* @return the Channel enum value matching the parameter
*/
public static Channel fromString(String name) {
final String lcName = name.toLowerCase();
final String lcName = name.toLowerCase(Locale.ENGLISH);
return stream(Channel.values())
.filter(ch -> ch.name.equals(lcName))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.firefox;

import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;

Expand Down Expand Up @@ -47,7 +48,7 @@ public enum FirefoxDriverLogLevel {

@Override
public String toString() {
return super.toString().toLowerCase();
return super.toString().toLowerCase(Locale.ENGLISH);
}

public static FirefoxDriverLogLevel fromString(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -194,7 +195,7 @@ public int hashCode() {
}

public String getType(Type type) {
String className = deriveClass(type).getSimpleName().toLowerCase();
String className = deriveClass(type).getSimpleName().toLowerCase(Locale.ENGLISH);

return isCollection(type) ? "list of " + className + "s" : className;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.annotations.VisibleForTesting;
import java.util.Comparator;
import java.util.Locale;
import java.util.Set;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.grid.config.Config;
Expand Down Expand Up @@ -67,7 +68,7 @@ public Set<SlotId> selectSlot(
@VisibleForTesting
long getNumberOfSupportedBrowsers(NodeStatus nodeStatus) {
return nodeStatus.getSlots().stream()
.map(slot -> slot.getStereotype().getBrowserName().toLowerCase())
.map(slot -> slot.getStereotype().getBrowserName().toLowerCase(Locale.ENGLISH))
.distinct()
.count();
}
Expand Down
Loading

0 comments on commit e8134d0

Please sign in to comment.