-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[dotnet] ability to create tests using mocked driver #14249
[dotnet] ability to create tests using mocked driver #14249
Conversation
Currently tests are using real browser drivers, but we can use a library like wiremock to mock the driver responses and create tests that don't need a real driver
68a3add
to
6efcb92
Compare
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨
|
Real browser or mocked browser?!.. This is conceptual question to the @SeleniumHQ/selenium-committers group. From my point of view, if we have an ability to test our code on real browser, let's use it. I can image some edge cases when we want to change the behavior of the browser, and it becomes tricky with real browsers. But from another hand introducing faked browser will introduce much more maintenance effort. |
I have no problem with real browsers. My problem is actually that in most of the cases they will work correctly and this way we only test positive path. But what if an endpoint returns a malformed response, a status code which was not expected. By mocking the the responses we can easily test the non happy path, check that driver doesn't throw unhandled exceprions, but a one with good message to the client. |
At least in the java tests the http responses are mocked and injected, to simulate these failures.
Or more high level a decoded json object with a invalid response: selenium/java/test/org/openqa/selenium/remote/W3CHandshakeResponseTest.java Lines 72 to 74 in d4ba7a5
So there is no mock for the driver it self, but we are able to write such tests. |
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 thisdotnet 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
Checklist
PR Type
Enhancement, Tests
Description
MockWebDriver
class to facilitate testing without a real browser driver.MockWebDriver
constructor using WireMock to mock server responses.WebDriver.Mock.Tests
in the solution file.WebDriver.Mock.Tests
with necessary package references.Changes walkthrough 📝
GlobalUsings.cs
Add global using directive for NUnit framework
dotnet/test/mocked/GlobalUsings.cs
MockWebDriver.cs
Implement MockWebDriver class for testing
dotnet/test/mocked/MockWebDriver.cs
MockWebDriver
class inheriting fromOpenQA.Selenium.WebDriver
.WebDriverConstructorTests.cs
Add tests for MockWebDriver constructor
dotnet/test/mocked/WebDriverConstructorTests.cs
MockWebDriver
constructor.WebDriver.NET.sln
Include MockWebDriver tests project in solution
dotnet/WebDriver.NET.sln
WebDriver.Mock.Tests
project to solution file.WebDriver.Mock.Tests.csproj
Create project file for MockWebDriver tests
dotnet/test/mocked/WebDriver.Mock.Tests.csproj
WebDriver.Mock.Tests
.