Skip to content

[dotnet] [test] Update tests to target .NET 10#17353

Merged
nvborisenko merged 3 commits into
SeleniumHQ:trunkfrom
nvborisenko:dotnet-test-10
Apr 15, 2026
Merged

[dotnet] [test] Update tests to target .NET 10#17353
nvborisenko merged 3 commits into
SeleniumHQ:trunkfrom
nvborisenko:dotnet-test-10

Conversation

@nvborisenko
Copy link
Copy Markdown
Member

.NET 10 for tests projects.

💥 What does this PR do?

This pull request updates the .NET test projects and Bazel build definitions to target .NET 10.0 instead of .NET 8.0, and improves the globbing patterns to exclude build output directories from test sources. Additionally, conditional compilation symbols and platform checks are updated to match the new target framework. These changes ensure the test suite is aligned with the latest .NET version and avoids including unnecessary files in test builds.

Target framework updates:

  • All test project files (.csproj) are updated to use net10.0 as the target framework instead of net8.0. [1] [2] [3] [4]
  • Bazel build definitions for test suites and libraries (BUILD.bazel files) are updated to use net10.0 in the target_frameworks attribute. [1] [2] [3] [4]

Build system improvements:

  • The glob patterns in Bazel build files for test sources now explicitly exclude bin/** and obj/** directories to prevent build artifacts from being included as source files. [1] [2] [3] [4]

Conditional compilation and platform checks:

  • Conditional compilation symbols in test code are updated from NET8_0 to NET10_0 to match the new target framework. This affects platform checks in IgnoreTargetAttribute.cs and conditional logic in TakesScreenshotTests.cs. [1] [2] [3]

🔧 Implementation Notes

Also added bin/obj as exclusion for bazel.

🔄 Types of changes

  • Cleanup (formatting, renaming)

Copilot AI review requested due to automatic review settings April 15, 2026 20:47
@selenium-ci selenium-ci added C-dotnet .NET Bindings B-build Includes scripting, bazel and CI integrations B-support Issue or PR related to support classes labels Apr 15, 2026
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

✨ Enhancement 🧪 Tests

Grey Divider

Walkthroughs

Description
• Update .NET test projects from net8.0 to net10.0 target framework
• Improve Bazel glob patterns to exclude build output directories
• Update conditional compilation symbols from NET8_0 to NET10_0

Grey Divider

File Changes

1. dotnet/test/webdriver/Infrastructure/IgnoreTargetAttribute.cs ✨ Enhancement +2/-2

Update platform check conditional compilation to NET10_0

dotnet/test/webdriver/Infrastructure/IgnoreTargetAttribute.cs


2. dotnet/test/webdriver/TakesScreenshotTests.cs ✨ Enhancement +2/-2

Update screenshot test conditional compilation symbols

dotnet/test/webdriver/TakesScreenshotTests.cs


3. dotnet/test/remote/BUILD.bazel ⚙️ Configuration changes +5/-2

Update target framework and exclude build directories

dotnet/test/remote/BUILD.bazel


View more (7)
4. dotnet/test/remote/Selenium.WebDriver.Remote.Tests.csproj ⚙️ Configuration changes +1/-1

Update target framework to net10.0

dotnet/test/remote/Selenium.WebDriver.Remote.Tests.csproj


5. dotnet/test/support/BUILD.bazel ⚙️ Configuration changes +5/-2

Update target framework and exclude build directories

dotnet/test/support/BUILD.bazel


6. dotnet/test/support/Selenium.WebDriver.Support.Tests.csproj ⚙️ Configuration changes +1/-1

Update target framework to net10.0

dotnet/test/support/Selenium.WebDriver.Support.Tests.csproj


7. dotnet/test/testing.webserver/BUILD.bazel ⚙️ Configuration changes +5/-2

Update target framework and exclude build directories

dotnet/test/testing.webserver/BUILD.bazel


8. dotnet/test/testing.webserver/Selenium.Testing.WebServer.csproj ⚙️ Configuration changes +1/-1

Update target framework to net10.0

dotnet/test/testing.webserver/Selenium.Testing.WebServer.csproj


9. dotnet/test/webdriver/BUILD.bazel ⚙️ Configuration changes +5/-2

Update target framework and exclude build directories

dotnet/test/webdriver/BUILD.bazel


10. dotnet/test/webdriver/Selenium.WebDriver.Tests.csproj ⚙️ Configuration changes +1/-1

Update target framework to net10.0

dotnet/test/webdriver/Selenium.WebDriver.Tests.csproj


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented Apr 15, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. NET10 screenshot tests fail🐞
Description
In TakesScreenshotTests, tests only skip color comparisons under NET8_0, but the color
extraction code paths are now inside #if !NET10_0, so on net10.0 they return empty/black values
and the tests’ color assertions fail.
Code

dotnet/test/webdriver/TakesScreenshotTests.cs[346]

+#if !NET10_0
Evidence
The WebDriver test project now targets net10.0, so NET10_0 is defined. However, the test methods
still only Assert.Ignore under NET8_0 and proceed to assert on extracted pixel colors, while
ScanActualColors/GetPixelColor compile out the image/pixel processing when NET10_0 is defined,
leaving defaults (empty set / Color.Black).

dotnet/test/webdriver/Selenium.WebDriver.Tests.csproj[3-7]
dotnet/test/webdriver/TakesScreenshotTests.cs[81-110]
dotnet/test/webdriver/TakesScreenshotTests.cs[112-137]
dotnet/test/webdriver/TakesScreenshotTests.cs[342-386]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`dotnet/test/webdriver/TakesScreenshotTests.cs` now compiles the screenshot color-extraction logic only when **not** targeting NET10 (`#if !NET10_0`), but the tests themselves are only skipped for `NET8_0`. Since the test project targets `net10.0`, these tests will run but `ScanActualColors()`/`GetPixelColor()` will return defaults (empty set / black), causing the color assertions to fail.

### Issue Context
- The test project targets `net10.0`, so `NET10_0` will be defined at compile time.
- Multiple tests still use `#if NET8_0` to skip, which will not trigger on `net10.0`.

### Fix Focus Areas
- dotnet/test/webdriver/TakesScreenshotTests.cs[81-110]
- dotnet/test/webdriver/TakesScreenshotTests.cs[112-137]
- dotnet/test/webdriver/TakesScreenshotTests.cs[342-386]

### What to change
Choose one consistent strategy:
1) **If NET10 cannot do color processing**: update all `#if NET8_0` skip blocks in the relevant tests to `#if NET10_0` (or `#if NET8_0 || NET10_0` if both should skip), so the tests don’t run when color extraction is compiled out.

2) **If NET10 should support color processing**: remove/adjust the `#if !NET10_0` guards so `ScanActualColors()` and `GetPixelColor()` actually extract pixels under NET10, and ensure any required dependencies/APIs are available for the target runtime.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@selenium-ci
Copy link
Copy Markdown
Member

Thank you, @nvborisenko for this code suggestion.

The support packages contain example code that many users find helpful, but they do not necessarily represent
the best practices for using Selenium, and the Selenium team is not currently merging changes to them.

After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium
to work, we will likely close the PR.

We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks.
If you have any questions, please contact us

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the .NET test projects and Bazel test targets to run against the net10.0 target framework, and tightens Bazel globbing to avoid picking up build output directories as test sources.

Changes:

  • Bump .NET test project TFMs from net8.0 to net10.0.
  • Update Bazel target_frameworks for .NET test rules to net10.0.
  • Exclude bin/** and obj/** from Bazel glob() test source collection.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
dotnet/test/webdriver/TakesScreenshotTests.cs Updates conditional compilation symbols to NET10_0 for screenshot color/pixel helpers.
dotnet/test/webdriver/Selenium.WebDriver.Tests.csproj Switches WebDriver test project target framework to net10.0.
dotnet/test/webdriver/Infrastructure/IgnoreTargetAttribute.cs Updates current TFM detection to NET10_0 / net10.
dotnet/test/webdriver/BUILD.bazel Moves test suite to net10.0 and excludes bin//obj/ from sources.
dotnet/test/testing.webserver/Selenium.Testing.WebServer.csproj Switches web server test project target framework to net10.0.
dotnet/test/testing.webserver/BUILD.bazel Moves library to net10.0 and excludes bin//obj/ from sources.
dotnet/test/support/Selenium.WebDriver.Support.Tests.csproj Switches support tests target framework to net10.0.
dotnet/test/support/BUILD.bazel Moves test suite to net10.0 and excludes bin//obj/ from sources.
dotnet/test/remote/Selenium.WebDriver.Remote.Tests.csproj Switches remote tests target framework to net10.0.
dotnet/test/remote/BUILD.bazel Moves test suite to net10.0 and excludes bin//obj/ from sources.
Comments suppressed due to low confidence (2)

dotnet/test/webdriver/TakesScreenshotTests.cs:373

  • ScanActualColors is now entirely excluded when compiling for net10 (#if !NET10_0). Since the test projects now target net10.0, this method will always return an empty set, and the screenshot color comparison assertions in this file become invalid (likely failing or becoming meaningless). Either update the framework guards so these tests are ignored on net10 as well (similar to existing NET6_0/NET8_0 skips), or provide a net10-compatible implementation for extracting pixel colors (e.g., via a supported cross-platform image API).
#if !NET10_0
        try
        {
            Image image = Image.FromStream(new MemoryStream(screenshot.AsByteArray));
            Bitmap bitmap = new Bitmap(image);
            int height = bitmap.Height;
            int width = bitmap.Width;
            Assert.That(width, Is.GreaterThan(0));
            Assert.That(height, Is.GreaterThan(0));

            for (int i = 0; i < width; i = i + stepX)
            {
                for (int j = 0; j < height; j = j + stepY)
                {
                    string hex = FormatColorToHex(bitmap.GetPixel(i, j).ToArgb());
                    colors.Add(hex);
                }
            }
        }
        catch (Exception e)
        {
            Assert.Fail("Unable to get actual colors from screenshot: " + e.Message);
        }

        Assert.That(colors.Count, Is.GreaterThan(0));
#endif

        return colors;

dotnet/test/webdriver/TakesScreenshotTests.cs:386

  • GetPixelColor is also excluded for net10 (#if !NET10_0), so on net10 it will always return Color.Black. If any tests rely on this helper to validate screenshot pixels, they will produce incorrect results under the new target framework. Consider skipping the relevant tests on net10 (as is done for earlier TFMs) or reworking the implementation to use a net10-compatible image decoding approach.
        Color pixelColor = Color.Black;

#if !NET10_0
        Image image = Image.FromStream(new MemoryStream(screenshot.AsByteArray));
        Bitmap bitmap = new Bitmap(image);
        pixelColor = bitmap.GetPixel(1, 1);
#endif
        return pixelColor;
    }

Comment thread dotnet/test/webdriver/TakesScreenshotTests.cs
@nvborisenko
Copy link
Copy Markdown
Member Author

nvborisenko commented Apr 15, 2026

I love bazel, they again forgot to support preprocessor directives?

Edit: My bad - not updated everything.

Copilot AI review requested due to automatic review settings April 15, 2026 21:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the .NET test suite build configuration to run on .NET 10, aligning both MSBuild test projects and Bazel targets with the new target framework while preventing build output directories from being treated as sources.

Changes:

  • Retarget .NET test projects (.csproj) from net8.0 to net10.0.
  • Update Bazel target_frameworks for test suites/libraries to net10.0 and exclude bin/** + obj/** from glob() sources.
  • Adjust conditional compilation/platform identification in tests to match the new TFM (NET10_0, "net10").

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
dotnet/test/webdriver/TakesScreenshotTests.cs Updates conditional compilation symbols to NET10_0 for framework-specific skips and code paths.
dotnet/test/webdriver/Selenium.WebDriver.Tests.csproj Retargets the main WebDriver test project to net10.0.
dotnet/test/webdriver/Infrastructure/IgnoreTargetAttribute.cs Updates TFM-to-string mapping to report "net10" under NET10_0.
dotnet/test/webdriver/BUILD.bazel Retargets Bazel test suite to net10.0 and excludes bin/ + obj/ from source globs.
dotnet/test/testing.webserver/Selenium.Testing.WebServer.csproj Retargets the test web server project to net10.0.
dotnet/test/testing.webserver/BUILD.bazel Retargets Bazel library to net10.0 and excludes bin/ + obj/ from source globs.
dotnet/test/support/Selenium.WebDriver.Support.Tests.csproj Retargets the support test project to net10.0.
dotnet/test/support/BUILD.bazel Retargets Bazel support test suite to net10.0 and excludes bin/ + obj/ from source globs.
dotnet/test/remote/Selenium.WebDriver.Remote.Tests.csproj Retargets the remote test project to net10.0.
dotnet/test/remote/BUILD.bazel Retargets Bazel remote test suite to net10.0 and excludes bin/ + obj/ from source globs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations B-support Issue or PR related to support classes C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants