Skip to content

Commit

Permalink
Merge branch 'trunk' into syber911911-feature-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
syber911911 authored Oct 27, 2024
2 parents db511e2 + 215e20b commit 2819469
Show file tree
Hide file tree
Showing 80 changed files with 6,240 additions and 2,027 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ jobs:
java-version: 17
os: windows
run: |
fsutil 8dot3name set 0
bazel test //dotnet/test/common:ElementFindingTest-firefox //dotnet/test/common:ElementFindingTest-chrome --pin_browsers=true
1 change: 1 addition & 0 deletions .github/workflows/ci-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
# https://github.com/bazelbuild/rules_jvm_external/issues/1046
java-version: 17
run: |
fsutil 8dot3name set 0
bazel test --flaky_test_attempts 3 //java/test/org/openqa/selenium/chrome:ChromeDriverFunctionalTest `
//java/test/org/openqa/selenium/federatedcredentialmanagement:FederatedCredentialManagementTest `
//java/test/org/openqa/selenium/firefox:FirefoxDriverBuilderTest `
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ maven.install(
"com.github.spotbugs:spotbugs:4.8.6",
"com.github.stephenc.jcip:jcip-annotations:1.0-1",
"com.google.code.gson:gson:2.11.0",
"com.google.guava:guava:33.3.0-jre",
"com.google.guava:guava:33.3.1-jre",
"com.google.auto:auto-common:1.2.2",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.service:auto-service-annotations:1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ rules_closure_toolchains()

http_archive(
name = "rules_rust",
integrity = "sha256-JLN47ZcAbx9wEr5Jiib4HduZATGLiDgK7oUi/fvotzU=",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.42.1/rules_rust-v0.42.1.tar.gz"],
integrity = "sha256-Zx3bP+Xrz53TTQUeynNS+68z+lO/Ye7Qt1pMNIKeVIA=",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.52.2/rules_rust-v0.52.2.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
Expand Down
Binary file modified common/extensions/webextensions-selenium-example.crx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
]
}
],
"permissions": [
"storage",
"scripting"
],
"host_permissions": [
"https://*/*",
"http://*/*"
],
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public NetworkManager(IWebDriver driver)
this.session = new Lazy<DevToolsSession>(() =>
{
IDevTools devToolsDriver = driver as IDevTools;
if (session == null)
if (devToolsDriver == null)
{
throw new WebDriverException("Driver must implement IDevTools to use these features");
}
Expand Down
12 changes: 10 additions & 2 deletions dotnet/src/webdriver/PrintOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,27 @@ public bool ShrinkToFit
}

/// <summary>
/// Gets the dimensions for each page in the printed document.
/// Gets or sets the dimensions for each page in the printed document.
/// </summary>
public PageSize PageDimensions
{
get { return pageSize; }
set
{
pageSize = value ?? throw new ArgumentNullException(nameof(value));
}
}

/// <summary>
/// Gets the margins for each page in the doucment.
/// Gets or sets the margins for each page in the doucment.
/// </summary>
public Margins PageMargins
{
get { return margins; }
set
{
margins = value ?? throw new ArgumentNullException(nameof(value));
}
}

/// <summary>
Expand Down
68 changes: 29 additions & 39 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using static OpenQA.Selenium.SeleniumManagerResponse;

#nullable enable

namespace OpenQA.Selenium
{
Expand All @@ -36,27 +39,25 @@ public static class SeleniumManager
{
private static readonly ILogger _logger = Log.GetLogger(typeof(SeleniumManager));

private static readonly string BinaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");

private static readonly JsonSerializerOptions _serializerOptions = new() { PropertyNameCaseInsensitive = true, TypeInfoResolver = SeleniumManagerSerializerContext.Default };

static SeleniumManager()
private static readonly Lazy<string> _lazyBinaryFullPath = new(() =>
{

if (BinaryFullPath == null)
string? binaryFullPath = Environment.GetEnvironmentVariable("SE_MANAGER_PATH");
if (binaryFullPath == null)
{
var currentDirectory = AppContext.BaseDirectory;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
BinaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe");
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "windows", "selenium-manager.exe");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
BinaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager");
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "linux", "selenium-manager");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
BinaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager");
binaryFullPath = Path.Combine(currentDirectory, "selenium-manager", "macos", "selenium-manager");
}
else
{
Expand All @@ -65,11 +66,13 @@ static SeleniumManager()
}
}

if (!File.Exists(BinaryFullPath))
if (!File.Exists(binaryFullPath))
{
throw new WebDriverException($"Unable to locate or obtain Selenium Manager binary at {BinaryFullPath}");
throw new WebDriverException($"Unable to locate or obtain Selenium Manager binary at {binaryFullPath}");
}
}

return binaryFullPath;
});

/// <summary>
/// Determines the location of the browser and driver binaries.
Expand All @@ -88,7 +91,7 @@ public static Dictionary<string, string> BinaryPaths(string arguments)
argsBuilder.Append(" --debug");
}

var smCommandResult = RunCommand(BinaryFullPath, argsBuilder.ToString());
var smCommandResult = RunCommand(_lazyBinaryFullPath.Value, argsBuilder.ToString());
Dictionary<string, string> binaryPaths = new()
{
{ "browser_path", smCommandResult.BrowserPath },
Expand All @@ -112,10 +115,10 @@ public static Dictionary<string, string> BinaryPaths(string arguments)
/// <returns>
/// the standard output of the execution.
/// </returns>
private static SeleniumManagerResponse.ResultResponse RunCommand(string fileName, string arguments)
private static ResultResponse RunCommand(string fileName, string arguments)
{
Process process = new Process();
process.StartInfo.FileName = BinaryFullPath;
process.StartInfo.FileName = _lazyBinaryFullPath.Value;
process.StartInfo.Arguments = arguments;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
Expand Down Expand Up @@ -183,7 +186,7 @@ private static SeleniumManagerResponse.ResultResponse RunCommand(string fileName

try
{
jsonResponse = JsonSerializer.Deserialize<SeleniumManagerResponse>(output, _serializerOptions);
jsonResponse = JsonSerializer.Deserialize<SeleniumManagerResponse>(output, _serializerOptions)!;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -222,32 +225,19 @@ private static SeleniumManagerResponse.ResultResponse RunCommand(string fileName
}
}

internal class SeleniumManagerResponse
internal record SeleniumManagerResponse(IReadOnlyList<LogEntryResponse> Logs, ResultResponse Result)
{
public IReadOnlyList<LogEntryResponse> Logs { get; set; }

public ResultResponse Result { get; set; }

public class LogEntryResponse
{
public string Level { get; set; }

public string Message { get; set; }
}

public class ResultResponse
{
[JsonPropertyName("driver_path")]
public string DriverPath { get; set; }

[JsonPropertyName("browser_path")]
public string BrowserPath { get; set; }
}
public record LogEntryResponse(string Level, string Message);

public record ResultResponse
(
[property: JsonPropertyName("driver_path")]
string DriverPath,
[property: JsonPropertyName("browser_path")]
string BrowserPath
);
}

[JsonSerializable(typeof(SeleniumManagerResponse))]
internal partial class SeleniumManagerSerializerContext : JsonSerializerContext
{

}
internal partial class SeleniumManagerSerializerContext : JsonSerializerContext;
}
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/WebDriver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</Target>

<Target Name="GenerateCdp" BeforeTargets="CoreCompile">
<Exec Command="bazel build //dotnet/src/webdriver/cdp:generate-v85 //dotnet/src/webdriver/cdp:generate-v127 //dotnet/src/webdriver/cdp:generate-v128 //dotnet/src/webdriver/cdp:generate-v129" WorkingDirectory="../../.." />
<Exec Command="bazel build //dotnet/src/webdriver/cdp/..." WorkingDirectory="../../.." />

<ItemGroup>
<Compile Include="..\..\..\bazel-bin\dotnet\src\webdriver\cdp\**\*.cs" LinkBase="DevTools\generated" />
Expand Down
7 changes: 1 addition & 6 deletions dotnet/src/webdriver/cdp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,4 @@ perform the following steps, where `<N>` is the major version of the protocol:
remove the entry for version `<N>` from the `SupportedDevToolsVersions` dictionary initialization.
3. Remove the version string (`v<N>`) from the `SUPPORTED_DEVTOOLS_VERSIONS` list in
[`//dotnet:selenium-dotnet-version.bzl`](https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/selenium-dotnet-version.bzl).
4. In [`//dotnet/src/webdriver:WebDriver.csproj.prebuild.cmd`](https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/WebDriver.csproj.prebuild.cmd),
remove the `if not exist` block for version `<N>`.
5. In [`//dotnet/src/webdriver:WebDriver.csproj.prebuild.sh`](https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/WebDriver.csproj.prebuild.sh),
remove the `if-fi` block for version `<N>`.
6. Commit the changes.

4. Commit the changes.
2 changes: 2 additions & 0 deletions dotnet/test/common/DriverTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public abstract class DriverTestFixture
public string scrollFrameOutOfViewport = EnvironmentManager.Instance.UrlBuilder.WhereIs("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html");
public string scrollFrameInViewport = EnvironmentManager.Instance.UrlBuilder.WhereIs("scrolling_tests/frame_with_nested_scrolling_frame.html");

public string printPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("printPage.html");

protected IWebDriver driver;

public IWebDriver DriverInstance
Expand Down
74 changes: 74 additions & 0 deletions dotnet/test/common/PrintTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using NUnit.Framework;
using System;

namespace OpenQA.Selenium
{
[TestFixture]
public class PrintTest : DriverTestFixture
{
private const string MagicString = "JVBER";
private ISupportsPrint printer;

[SetUp]
public void LocalSetUp()
{
Assert.That(driver, Is.InstanceOf<ISupportsPrint>(), $"Driver does not support {nameof(ISupportsPrint)}.");

printer = driver as ISupportsPrint;

driver.Navigate().GoToUrl(this.printPage);
}

[Test]
public void CanPrintPage()
{
var pdf = printer.Print(new PrintOptions());

Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
}

[Test]
public void CanPrintTwoPages()
{
var options = new PrintOptions();

options.AddPageRangeToPrint("1-2");

var pdf = printer.Print(options);

Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
}

[Test]
public void CanPrintWithMostParams()
{
var options = new PrintOptions()
{
Orientation = PrintOrientation.Landscape,
ScaleFactor = 0.5,
PageDimensions = new PrintOptions.PageSize { Width = 200, Height = 100 },
PageMargins = new PrintOptions.Margins { Top = 1, Bottom = 1, Left = 2, Right = 2 },
OutputBackgroundImages = true,
ShrinkToFit = false
};

options.AddPageRangeToPrint("1-3");

var pdf = printer.Print(options);

Assert.That(pdf.AsBase64EncodedString, Does.Contain(MagicString));
}

[Test]
public void PageSizeCannotBeNull()
{
Assert.That(() => new PrintOptions { PageDimensions = null }, Throws.InstanceOf<ArgumentNullException>());
}

[Test]
public void MarginsCannotBeNull()
{
Assert.That(() => new PrintOptions { PageMargins = null }, Throws.InstanceOf<ArgumentNullException>());
}
}
}
12 changes: 6 additions & 6 deletions java/maven_install.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": -1369959342,
"__RESOLVED_ARTIFACTS_HASH": 2051378450,
"__INPUT_ARTIFACTS_HASH": 1327312787,
"__RESOLVED_ARTIFACTS_HASH": -2038995232,
"conflict_resolution": {
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.11.0",
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.28.0",
"com.google.guava:guava:31.1-jre": "com.google.guava:guava:33.3.0-jre",
"com.google.guava:guava:31.1-jre": "com.google.guava:guava:33.3.1-jre",
"com.google.j2objc:j2objc-annotations:1.3": "com.google.j2objc:j2objc-annotations:3.0.0",
"org.mockito:mockito-core:4.3.1": "org.mockito:mockito-core:5.13.0"
},
Expand Down Expand Up @@ -159,10 +159,10 @@
},
"com.google.guava:guava": {
"shasums": {
"jar": "dfadc3bce3101eff1452aae47d7c833fee443b47bdf9ef13311b6c7cab663ddf",
"sources": "f91f8619f533db55f37d13369c2fee39d5e1d2f72cef7f69f735d5be1a601f14"
"jar": "4bf0e2c5af8e4525c96e8fde17a4f7307f97f8478f11c4c8e35a0e3298ae4e90",
"sources": "b7cbdad958b791f2a036abff7724570bf9836531c460966f8a3d0df8eaa1c21d"
},
"version": "33.3.0-jre"
"version": "33.3.1-jre"
},
"com.google.guava:guava-testlib": {
"shasums": {
Expand Down
26 changes: 26 additions & 0 deletions java/spotbugs-excludes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,30 @@
<Class name="org.openqa.selenium.remote.internal.WebElementToJsonConverter" />
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />
</Match>

<Match>
<Class name="org.openqa.selenium.chrome.AddHasCasting" />
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />
</Match>

<Match>
<Class name="org.openqa.selenium.chrome.AddHasCdp" />
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />
</Match>

<Match>
<Class name="org.openqa.selenium.edge.AddHasCdp" />
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />
</Match>

<Match>
<Class name="org.openqa.selenium.edge.AddHasCasting" />
<Bug pattern="NM_SAME_SIMPLE_NAME_AS_SUPERCLASS" />
</Match>

<Match>
<Class name="~org.openqa.selenium.devtools.v[0-9]+\.v\w+" />
<Bug pattern="NM_CLASS_NAMING_CONVENTION"/>
</Match>

</FindBugsFilter>
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ public ScriptKey pin(String script) {
// Create the actual script we're going to use.
String scriptToUse =
String.format(
"window.seleniumPinnedScript%s = function(){%s}", Math.abs(script.hashCode()), script);
"window.seleniumPinnedScript%s = function(){%s}",
Math.abs((long) script.hashCode()), script);

DevTools devTools = getDevTools();
devTools.createSessionIfThereIsNotOne();
Expand Down
Loading

0 comments on commit 2819469

Please sign in to comment.