MIU Automated Testing: Playwright
Requirement
Latest version of PowerShell need to install
Built by Microsoft, Playwright is a Node.js library that, with a single API, automates Chromium, Firefox, and WebKit. These APIs can be used by developers writing JavaScript code to create new browser pages, navigate to URLs and then interact with elements on a page.
Add Microsft.playwrite and Microsoft.Playwright.Nunit to the test project
[TestMethod]
public async Task PlaywriteTest()
{
// await Page.GotoAsync("https://playwright.dev ");
await Expect(Page).ToHaveURLAsync(new Regex("Playwrite"));
var getstarted = Page.GetByRole(AriaRole.Link, new() { Name = "Get started" });
await Expect(getstarted).ToHaveAttributeAsync("href", "/doc/intro");
await getstarted.ClickAsync();
await Expect(Page).ToHaveURLAsync(new Regex(".*intro"));
}
YAMl file need to add into the project example is
trigger: none
resources:
- repo: self
# schedules:
# - cron: "0 * * * *"
# displayName: MID Automate Test
# branches:
# include:
# - sharmap/DevsecOps_from_dev
# always: true
# batch: true
# Define variable `APPLICATIONINSIGHTS_CONNECTION_STRING` in Azure DevOps Pipeline Library or Azure Key Vault that is linked to a Library
variables:
- group: MIUKeyVaultSecretsVariableGroup
pool:
name: Marine Self-Hosted DotNetCore 3.1
jobs:
- job: RunMIDWebSiteTests
displayName: Run Automated MIDWebSite playwrite Tests....
timeoutInMinutes: 10
variables:
- group: 'MIUKeyVaultSecretsVariableGroup'
steps:
- checkout: self
submodules: true
# - task: CmdLine@2
# inputs:
# script: 'npm ci'
- task: NuGetCommand@2
displayName: Install Dependencies
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: 'f44d1ef3-b012-4d30-b1d3-0cbfc6ab7352'
- script: npm i npx playwright install --with -deps
- task: CmdLine@2
displayName: Install Dependencies
inputs:
# Install Playwright dependencies onto the agent.
# We are only installing Chromium in this example to minimize install time.
script: |
cd E2E_Tests
dotnet build
powershell bin/Debug/net8.0/playwright.ps1 install chromium
- task: DotNetCoreCLI@2
displayName: Run Mid Test
inputs:
command: 'test'
projects: '**/MID.Website.Playwright.Tests.csproj'
arguments: '--configuration $(buildConfiguration)'
testRunTitle: 'MIU test for MID Playwrite'
after test run ,it will show fail/pass like below
Test coverage will show you error for the fail test