Skip to content
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

Set up Blazor end-to-end tests #705

Closed
1 of 3 tasks
m-akinc opened this issue Aug 26, 2022 · 4 comments
Closed
1 of 3 tasks

Set up Blazor end-to-end tests #705

m-akinc opened this issue Aug 26, 2022 · 4 comments

Comments

@m-akinc
Copy link
Contributor

m-akinc commented Aug 26, 2022

🧹 Tech Debt

We should have infrastructure (presumably Playwright) for running e2e tests in order to fill testing gaps that are difficult to test via unit tests and Chromatic. This came up in the context of writing unit tests for the Nimble dialog's Blazor integration. The Blazor implementation of the dialog calls js using the JSRuntime, but BUnit tests don't support that. This made it impossible to test that part of the Blazor implementation.

Tasks

@m-akinc m-akinc added tech debt triage New issue that needs to be reviewed labels Aug 26, 2022
@m-akinc m-akinc removed the triage New issue that needs to be reviewed label Aug 30, 2022
@rajsite
Copy link
Member

rajsite commented Aug 30, 2022

@m-akinc can we make a separate issue to track the testing we need for the dialog when this issue to set-up infrastructure is addressed?

@jattasNI
Copy link
Contributor

@atmgrifter00 can you update this tech debt item with any info/links/lessons learned from when you investigated it in your CI week?

@atmgrifter00
Copy link
Contributor

atmgrifter00 commented Mar 13, 2023

I got as far as creating a branch that has the Playwright infrastructure set up for Blazor, with a dummy test. However, at the moment, the PlaywrightFixture test fixture class isn't being called to properly set up the local run with the right Chromium version to run. Some investigation is needed to figure out what is missing. My guess is that there is only a little more work needed to get to where we can write a component e2e test in Blazor.

@msmithNI msmithNI assigned msmithNI and unassigned atmgrifter00 May 15, 2023
msmithNI added a commit that referenced this issue May 19, 2023
# Pull Request

## 🤨 Rationale

#705 (partially addresses - that issue covers both hover/focus testing
and Blazor e2e tests currently)

This PR adds a new test project for Nimble Blazor end-to-end /
acceptance tests. These use Playwright to start up a Chromium browser
instance, connect to a local Blazor Server app with pages using Nimble
Blazor components, and interact with them.

## 👩‍💻 Implementation

Add new project `NimbleBlazor.Tests.Acceptance` to `NimbleBlazor.sln`
(depends on `NimbleBlazor`) (xUnit-based)
- Fixture class `BlazorServerWebHostFixture` spins up a local web server
to host a Blazor Server app.
- This app uses the `all-components-bundle` JS like the other Nimble
Blazor example apps
  - Razor components for the tests are defined in the Pages\ subfolder
- Fixture class `PlaywrightFixture` handles spinning up a Chromium
browser instance to run tests targeting the local Blazor server (uses
Microsoft.Playwright NuGet package)
- Release builds run Chromium headless. Debug builds currently run
headed w/ slow-mo mode to make debugging easier.
- `Tests\AcceptanceTestsBase` (base class for test classes) has logic to
load a new page with Playwright, navigate to the right URL, etc

This PR includes 3 tests: 
- nimble-dialog opening & closing (`DialogTests.cs,
Dialog_CanOpenAndCloseAsync()`, uses `DialogOpenAndClose.razor`)
- nimble-drawer opening & closing (`DrawerTests.cs,
Dialog_CanOpenAndCloseAsync()`, uses `DrawerOpenAndClose.razor`)
- nimble-table binding to data (`TableTests.cs,
Table_RendersBoundDataAsync()`, uses `TableBindToData.razor`).

For future new tests, we should probably aim to exercise the rest of the
code in `NimbleBlazor.lib.module.js`. Dialog/Drawer/Table were chosen to
start with since they each call custom JS methods in that file (that
only had manual test coverage).

Currently each test loads distinct pages / Razor components. Once we
have more tests, it may make sense for some of them to load the same
Razor components if they're testing the same control.

Writing Playwright test code to test Nimble controls is fairly
straightforward, but there's a few quirks. Reading the [SLE E2E Getting
Started with Playwright
Tests](https://dev.azure.com/ni/DevCentral/_git/Skyline?path=/End2EndTests/Getting%20Started%20with%20Playwright%20Tests.md&_a=preview)
doc is a good starting point.

## 🧪 Testing

- Ran new tests locally (in Visual Studio and with `npm run test`)
- Ensured new tests are running as part of the existing `npm run test`
command for Nimble Blazor for the GitHub Actions / CI build.
- i.e. see npm run test output from build log
[here](https://github.com/ni/nimble/actions/runs/4986254518/jobs/8926790926?pr=1248)
```
Test run for /home/runner/work/nimble/nimble/packages/nimble-blazor/Tests/NimbleBlazor.Tests.Acceptance/bin/Release/net6.0/NimbleBlazor.Tests.Acceptance.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.5.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     3, Skipped:     0, Total:     3, Duration: 1 s - NimbleBlazor.Tests.Acceptance.dll (net6.0)
```

## ✅ Checklist

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
@msmithNI msmithNI removed their assignment May 19, 2023
@jattasNI jattasNI changed the title Set up end-to-end tests Set up Blazor end-to-end tests Mar 4, 2024
@jattasNI
Copy link
Contributor

jattasNI commented Mar 4, 2024

Renamed from "Set up end-to-end tests" to focus specifically on Blazor, which is now done (other than the follow up items tracked in separate issues). That's complete so I'll close the issue.

We've talked about adding similar Playwright infrastructure for nimble-components but don't have a specific prioritized use case in mind yet so we'll leave that untracked for now.

@jattasNI jattasNI closed this as completed Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

5 participants