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

Let the build run on Ubuntu too #5

Merged
merged 11 commits into from
Apr 29, 2024
Merged
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
14 changes: 10 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ windows-latest ]
os: [ ubuntu-latest, windows-latest ]
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.*
- name: Restore
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Playwright
- name: Install Playwright browsers & dependencies
run: pwsh test/OrchardCoreContrib.Testing.UI.Tests/bin/Release/net8.0/playwright.ps1 install --with-deps
- name: Test
run: dotnet test test/OrchardCoreContrib.Testing.UI.Tests -c Release --no-restore --verbosity normal
run: |
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
xvfb-run dotnet test test/OrchardCoreContrib.Testing.UI.Tests -c Release --no-restore --verbosity normal
else
dotnet test test/OrchardCoreContrib.Testing.UI.Tests -c Release --no-restore --verbosity normal
fi
shell: bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace OrchardCoreContrib.Testing.UI.Helpers.Tests;
using OrchardCoreContrib.Testing.UI.Tests;

namespace OrchardCoreContrib.Testing.UI.Helpers.Tests;

public class CssSelectorsTests
{
private static readonly string _binFolderPath = Path.GetDirectoryName(typeof(CssSelectorsTests).Assembly.Location);
private static readonly string _pagesFolderPath = Path.Combine(_binFolderPath, "Pages");

public static readonly IEnumerable<object[]> CombinatorsData =
[
new [] { By.Id("container") },
Expand Down Expand Up @@ -36,24 +35,12 @@ public class CssSelectorsTests
public async Task ShouldFindByCssSelector(string selector)
{
// Arrange
var playwrightPage = await CreatePlaywrightPageAsync();

await playwrightPage.GotoAsync(Path.Combine(_pagesFolderPath, "selectors.html"));

var page = new Page(new PlaywrightPageAccessor(playwrightPage));
var page = await PlaywrightPageHelper.GotoAsync("selectors.html");

// Act
var element = page.FindElement(selector);

// Assert
Assert.True(element.Visible);
}

private static async Task<Microsoft.Playwright.IPage> CreatePlaywrightPageAsync()
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();

return await browser.NewPageAsync();
}
}
23 changes: 2 additions & 21 deletions test/OrchardCoreContrib.Testing.UI.Tests/PageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ namespace OrchardCoreContrib.Testing.UI.Tests;

public class PageTests
{
private static readonly string _binFolderPath = Path.GetDirectoryName(typeof(PageTests).Assembly.Location);
private static readonly string _pagesFolderPath = Path.Combine(_binFolderPath, "Pages");

[Fact]
public void ShouldCreatePage()
{
Expand Down Expand Up @@ -66,11 +63,7 @@ public void ShouldFindElement()
public async Task ShouldClickAnElement()
{
// Arrange
var playwrightPage = await CreatePlaywrightPageAsync();

await playwrightPage.GotoAsync(Path.Combine(_pagesFolderPath, "index.html"));

var page = new Page(new PlaywrightPageAccessor(playwrightPage));
var page = await PlaywrightPageHelper.GotoAsync("index.html");

// Act
await page.ClickAsync("button");
Expand All @@ -86,11 +79,7 @@ public async Task ShouldTakeScreenshot()
// Arrange
var screenshotFilePath = "screenshot.jpg";

var playwrightPage = await CreatePlaywrightPageAsync();

await playwrightPage.GotoAsync(Path.Combine(_pagesFolderPath, "index.html"));

var page = new Page(new PlaywrightPageAccessor(playwrightPage));
var page = await PlaywrightPageHelper.GotoAsync("index.html");

// Act
await page.ScreenShotAsync(screenshotFilePath);
Expand All @@ -99,12 +88,4 @@ public async Task ShouldTakeScreenshot()
Assert.True(File.Exists(screenshotFilePath));
File.Delete(screenshotFilePath);
}

private static async Task<Microsoft.Playwright.IPage> CreatePlaywrightPageAsync()
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();

return await browser.NewPageAsync();
}
}
19 changes: 19 additions & 0 deletions test/OrchardCoreContrib.Testing.UI.Tests/PlaywrightPageHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace OrchardCoreContrib.Testing.UI.Tests;

internal class PlaywrightPageHelper
{
public static async Task<IPage> GotoAsync(string pageName)
{
var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();

var page = await browser.NewPageAsync();

await page.GotoAsync(GetFullPath(pageName));

return new Page(new PlaywrightPageAccessor(page));
}

private static string GetFullPath(string pageName)
=> new Uri(Path.Combine(Environment.CurrentDirectory, "Pages", pageName)).AbsoluteUri;
}