selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[dotnet] ability to create tests using mocked driver

Open Indomitable opened this issue 7 months ago • 4 comments

User description

I noticed that all tests require real browser driver, but I think it can be useful to have ability to write tests which doesn't need it. We can use WireMock to mock driver responses and write more detailed tests.

It contains a test that tests my changes in PR: #14242

Unfortunately my knowledge with bazel is quite limited in order to add integration for bazel test but for this dotnet test should be sufficient.

Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines. Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • [x] I have read the contributing document.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

PR Type

Enhancement, Tests


Description

  • Added a new MockWebDriver class to facilitate testing without a real browser driver.
  • Implemented tests for MockWebDriver constructor using WireMock to mock server responses.
  • Included the new test project WebDriver.Mock.Tests in the solution file.
  • Created project file for WebDriver.Mock.Tests with necessary package references.

Changes walkthrough 📝

Relevant files
Enhancement
GlobalUsings.cs
Add global using directive for NUnit framework                     

dotnet/test/mocked/GlobalUsings.cs

  • Added global using directive for NUnit framework.
+1/-0     
MockWebDriver.cs
Implement MockWebDriver class for testing                               

dotnet/test/mocked/MockWebDriver.cs

  • Created MockWebDriver class inheriting from OpenQA.Selenium.WebDriver.
  • Implemented constructor to initialize with mocked server.
  • +12/-0   
    Tests
    WebDriverConstructorTests.cs
    Add tests for MockWebDriver constructor                                   

    dotnet/test/mocked/WebDriverConstructorTests.cs

  • Added tests for MockWebDriver constructor.
  • Included tests for session creation and error handling.
  • +91/-0   
    Configuration changes
    WebDriver.NET.sln
    Include MockWebDriver tests project in solution                   

    dotnet/WebDriver.NET.sln

    • Added WebDriver.Mock.Tests project to solution file.
    +6/-0     
    WebDriver.Mock.Tests.csproj
    Create project file for MockWebDriver tests                           

    dotnet/test/mocked/WebDriver.Mock.Tests.csproj

  • Created project file for WebDriver.Mock.Tests.
  • Added necessary package references for testing.
  • +28/-0   

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Indomitable avatar Jul 10 '24 20:07 Indomitable