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

End to end tests with Playwright #161

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Playwright Tests

on:
repository_dispatch:
types: [playwright]
# schedule:
# - cron: '30 6 * * 1-5'

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

- name: Build
run: dotnet build src/UDS.Net.Web.MVC.Services.Test

- name: Install Playwright
run: pwsh src/UDS.Net.Web.MVC.Services.Test/bin/Debug/net8.0/playwright.ps1 install --with-deps

- name: Run tests
run: dotnet test src/UDS.Net.Web.MVC.Services.Test --no-build --verbosity normal
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

.DS_Store
appsettings.Development.json
[Pp]laywright/.auth

# User-specific files
*.rsuser
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The software is implemented with several .NET tools and includes a development c
Thank you for interest in contributing to our project! There are many ways you can help:
* Submit bugs and feature requests [here](Discussions)
* Submit a fix by forking and submitting a PR Request [here](CONTRIBUTING.md)
* This solution includes automated tooling for linting, unit testing, and end-to-end testing. Powershell is required. Read more in our [wiki](https://github.com/UK-SBCoA/uniform-data-set-dotnet/wiki)

## Security
[Security reports](SECURITY.md)
Expand Down
25 changes: 25 additions & 0 deletions src/UDS.Net.Web.MVC.Services.Test/HomepageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace UDS.Net.Web.MVC.Services.Test;

[TestClass]
public class HomepageTests : PageTest
{
[TestMethod]
public async Task HomepageHasNavigationToParticipations()
{
await Page.GotoAsync("/");

//var participation = Page.GetByRole(AriaRole.Link, new() { Name = "Participation" });

//await Expect(participation).ToHaveAttributeAsync("href", "/Participations");

//var createButton = Page.GetByRole(AriaRole.Link, new() { Name = "New participation" });

//await Expect(createButton).ToHaveAttributeAsync("href", "/Participations/Create");

//await participation.ClickAsync();
}
}

27 changes: 27 additions & 0 deletions src/UDS.Net.Web.MVC.Services.Test/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace UDS.Net.Web.MVC.Services.Test
{
public class Startup : PageTest
{
[TestInitialize]
public async Task TestInitialize()
{
await Page.GotoAsync("Identity/Account/Login?ReturnUrl=%2F");

var loginButton = Page.GetByRole(AriaRole.Link, new() { Name = "Login" });

if (loginButton != null)
{

}
else
{
// already authenticated
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Microsoft.Playwright.MSTest" Version="1.43.0" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions src/UDS.Net.Web.MVC.Services.Test/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace UDS.Net.Web.MVC.Services.Test;

[TestClass]
public class ParticipationTests : PageTest
{
[TestMethod]
public async Task ParticipationHasCreateButton()
{
await Page.GotoAsync("https://localhost:4811/Participations");

//var createButton = Page.GetByRole(AriaRole.Link, new() { Name = "New participation" });

//await Expect(createButton).ToHaveAttributeAsync("href", "/Create");

//createButton.ClickAsync();
//await page.GetByLabel("NACC IdParticipation.LegacyId").ClickAsync();
//await page.GetByLabel("NACC IdParticipation.LegacyId").FillAsync("2000");
//await page.GetByRole(AriaRole.Button, new() { Name = "Save" }).ClickAsync();
//await page.GetByLabel("NACC IdParticipation.LegacyId").ClickAsync();
//await page.GetByLabel("NACC IdParticipation.LegacyId").FillAsync("2001");
//await page.GetByRole(AriaRole.Button, new() { Name = "Save" }).ClickAsync();
//await page.GetByLabel("NACC IdParticipation.LegacyId").ClickAsync();
//await page.GetByLabel("NACC IdParticipation.LegacyId").FillAsync("5000");
//await page.GetByRole(AriaRole.Button, new() { Name = "Save" }).ClickAsync();
}
}
3 changes: 3 additions & 0 deletions src/UDS.Net.Web.MVC.Services.Test/appsettings.DEFAULT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"TestUrl": "https://localhost:4811"
}
3 changes: 3 additions & 0 deletions src/UDS.Net.Web.MVC.Services.Test/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"TestUrl": "https://demo-uds.coa.uky.edu"
}
20 changes: 13 additions & 7 deletions src/UDS.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Forms", "UDS.Net.Fo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Services", "UDS.Net.Services\UDS.Net.Services.csproj", "{BD35F74B-9134-46F3-850D-7DF05F7397E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UDS.Net.Forms.Tests", "UDS.Net.Forms.Tests\UDS.Net.Forms.Tests.csproj", "{7A359BF3-B7F2-4962-A948-DAB0A996DA0F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Forms.Tests", "UDS.Net.Forms.Tests\UDS.Net.Forms.Tests.csproj", "{7A359BF3-B7F2-4962-A948-DAB0A996DA0F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Web.MVC.Services", "UDS.Net.Web.MVC.Services\UDS.Net.Web.MVC.Services.csproj", "{10B4A194-D9E4-491B-AF11-FF14F6108F5F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UDS.Net.Services.Test", "UDS.Net.Services.Test\UDS.Net.Services.Test.csproj", "{395296FB-4036-4FC9-A8DC-A50F96D35623}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Services.Test", "UDS.Net.Services.Test\UDS.Net.Services.Test.csproj", "{395296FB-4036-4FC9-A8DC-A50F96D35623}"
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "docker-compose", "docker-compose.dcproj", "{C44B743C-B76C-41C1-BBB2-97AAC6B988BE}"
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "docker-compose", "docker-compose.dcproj", "{EF687CA4-D15B-4E2F-97BA-64AAB218E395}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Web.MVC.Services.Test", "UDS.Net.Web.MVC.Services.Test\UDS.Net.Web.MVC.Services.Test.csproj", "{7879003A-AF57-4662-A66B-6A33FA09325C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -47,10 +49,14 @@ Global
{395296FB-4036-4FC9-A8DC-A50F96D35623}.Debug|Any CPU.Build.0 = Debug|Any CPU
{395296FB-4036-4FC9-A8DC-A50F96D35623}.Release|Any CPU.ActiveCfg = Release|Any CPU
{395296FB-4036-4FC9-A8DC-A50F96D35623}.Release|Any CPU.Build.0 = Release|Any CPU
{C44B743C-B76C-41C1-BBB2-97AAC6B988BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C44B743C-B76C-41C1-BBB2-97AAC6B988BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C44B743C-B76C-41C1-BBB2-97AAC6B988BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C44B743C-B76C-41C1-BBB2-97AAC6B988BE}.Release|Any CPU.Build.0 = Release|Any CPU
{EF687CA4-D15B-4E2F-97BA-64AAB218E395}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF687CA4-D15B-4E2F-97BA-64AAB218E395}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF687CA4-D15B-4E2F-97BA-64AAB218E395}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF687CA4-D15B-4E2F-97BA-64AAB218E395}.Release|Any CPU.Build.0 = Release|Any CPU
{7879003A-AF57-4662-A66B-6A33FA09325C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7879003A-AF57-4662-A66B-6A33FA09325C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7879003A-AF57-4662-A66B-6A33FA09325C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7879003A-AF57-4662-A66B-6A33FA09325C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down