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

Bump to version 2.3.1 #31

Merged
merged 1 commit into from
Dec 10, 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
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ You can checkout this Github repository or you can use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.CodeQuality.Prod -version 2.3.0
Install-Package SoloX.CodeQuality.Prod -version 2.3.1
or
Install-Package SoloX.CodeQuality.Test -version 2.3.0
Install-Package SoloX.CodeQuality.Test -version 2.3.1
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.CodeQuality.Prod --version 2.3.0
dotnet add package SoloX.CodeQuality.Prod --version 2.3.1
or
dotnet add package SoloX.CodeQuality.Test --version 2.3.0
dotnet add package SoloX.CodeQuality.Test --version 2.3.1
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.CodeQuality.Prod" Version="2.3.0">
<PackageReference Include="SoloX.CodeQuality.Prod" Version="2.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
or
<PackageReference Include="SoloX.CodeQuality.Test" Version="2.3.0">
<PackageReference Include="SoloX.CodeQuality.Test" Version="2.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down Expand Up @@ -218,17 +218,17 @@ You can checkout this Github repository or use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.CodeQuality.Playwright -version 2.3.0
Install-Package SoloX.CodeQuality.Playwright -version 2.3.1
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.CodeQuality.Playwright --version 2.3.0
dotnet add package SoloX.CodeQuality.Playwright --version 2.3.1
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.0" />
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.1" />
```

* * *
Expand Down Expand Up @@ -406,6 +406,10 @@ await playwrightTest.GotoPageAsync("index.html", async (page) =>
> Note: you can check on the [Playwright](https://playwright.dev/dotnet/) web site to find out more about the
> [Codegen Tool](https://playwright.dev/dotnet/docs/codegen-intro).

> Note: you can also specify the [Playwright device](https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json)
> name in the BuildAsync method to simulate browser behavior for a specific device such as desktop, tablet and mobile
> devices.

* * *

## Test Helpers
Expand All @@ -420,29 +424,29 @@ You can checkout this Github repository or you can use the NuGet package:

**Install using the command line from the Package Manager:**
```bash
Install-Package SoloX.CodeQuality.Test.Helpers -version 2.3.0
Install-Package SoloX.CodeQuality.Test.Helpers -version 2.3.1

Install-Package SoloX.CodeQuality.Test.Helpers.XUnit -version 2.3.0
Install-Package SoloX.CodeQuality.Test.Helpers.XUnit -version 2.3.1

Install-Package SoloX.CodeQuality.Test.Helpers.NUnit -version 2.3.0
Install-Package SoloX.CodeQuality.Test.Helpers.NUnit -version 2.3.1
```

**Install using the .Net CLI:**
```bash
dotnet add package SoloX.CodeQuality.Test.Helpers --version 2.3.0
dotnet add package SoloX.CodeQuality.Test.Helpers --version 2.3.1

dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit --version 2.3.0
dotnet add package SoloX.CodeQuality.Test.Helpers.XUnit --version 2.3.1

dotnet add package SoloX.CodeQuality.Test.Helpers.NUnit --version 2.3.0
dotnet add package SoloX.CodeQuality.Test.Helpers.NUnit --version 2.3.1
```

**Install editing your project file (csproj):**
```xml
<PackageReference Include="SoloX.CodeQuality.Test.Helpers" Version="2.3.0" />
<PackageReference Include="SoloX.CodeQuality.Test.Helpers" Version="2.3.1" />

<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit" Version="2.3.0" />
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.XUnit" Version="2.3.1" />

<PackageReference Include="SoloX.CodeQuality.Test.Helpers.NUnit" Version="2.3.0" />
<PackageReference Include="SoloX.CodeQuality.Test.Helpers.NUnit" Version="2.3.1" />
```

* * *
Expand Down
2 changes: 1 addition & 1 deletion src/SharedProperties.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>2.3.0</Version>
<Version>2.3.1</Version>
<Authors>Xavier Solau</Authors>
<Copyright>Copyright © 2021 Xavier Solau</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
54 changes: 54 additions & 0 deletions src/libs/SoloX.CodeQuality.Playwright/Devices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// ----------------------------------------------------------------------
// <copyright file="Devices.cs" company="Xavier Solau">
// Copyright © 2021 Xavier Solau.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
// </copyright>
// ----------------------------------------------------------------------

namespace SoloX.CodeQuality.Playwright
{
/// <summary>
/// Some Playwright devices.
/// For more information see https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json
/// </summary>
public static class Devices
{
/// <summary>
/// Safari on desktop.
/// </summary>
public const string DesktopSafari = "Desktop Safari";
/// <summary>
/// Chrome on desktop.
/// </summary>
public const string DesktopChrome = "Desktop Chrome";
/// <summary>
/// Edge on desktop.
/// </summary>
public const string DesktopEdge = "Desktop Edge";
/// <summary>
/// Firefox on desktop.
/// </summary>
public const string DesktopFirefox = "Desktop Firefox";

/// <summary>
/// Pixel.
/// </summary>
public const string Pixel = "Pixel 7";
/// <summary>
/// Pixel landscape.
/// </summary>
public const string PixelLandscape = "Pixel 7 landscape";

#pragma warning disable IDE1006 // Naming Styles
/// <summary>
/// Pixel.
/// </summary>
public const string iPhone = "iPhone 15";
/// <summary>
/// Pixel landscape.
/// </summary>
public const string iPhoneLandscape = "iPhone 15 landscape";
#pragma warning restore IDE1006 // Naming Styles
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public interface IPlaywrightTestBuilder
/// Build and set up Web host and Playwright test driver.
/// </summary>
/// <param name="browser">Browser override (optional).</param>
/// <param name="deviceName">Device name to use (optional).</param>
/// <returns>The Playwright test.</returns>
Task<IPlaywrightTest> BuildAsync(Browser? browser = null);
Task<IPlaywrightTest> BuildAsync(Browser? browser = null, string? deviceName = null);
}
}
26 changes: 22 additions & 4 deletions src/libs/SoloX.CodeQuality.Playwright/PlaywrightDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class PlaywrightDriver : IAsyncDisposable
private static readonly object LockSync = new object();
private static bool playwrightInstalled;

private readonly BrowserNewContextOptions? browserNewContextOptions;
private BrowserNewContextOptions? browserNewContextOptions;
private readonly TracingStartOptions? tracingStartOptions;
private readonly int goToPageRetryCount;

Expand All @@ -49,12 +49,10 @@ public class PlaywrightDriver : IAsyncDisposable
/// Build PlaywrightDriver instance.
/// </summary>
/// <param name="goToPageRetryCount">Goto page retry count.</param>
/// <param name="browserNewContextOptions">New context options.</param>
/// <param name="tracingStartOptions">Tracing start options.</param>
public PlaywrightDriver(int goToPageRetryCount = 3, BrowserNewContextOptions? browserNewContextOptions = null, TracingStartOptions? tracingStartOptions = null)
public PlaywrightDriver(int goToPageRetryCount = 3, TracingStartOptions? tracingStartOptions = null)
{
this.goToPageRetryCount = goToPageRetryCount;
this.browserNewContextOptions = browserNewContextOptions;
this.tracingStartOptions = tracingStartOptions;
}

Expand Down Expand Up @@ -162,6 +160,26 @@ private static void InstallPlaywrightBin()
}
}

/// <summary>
/// Setup BrowserNewContextOptions for the given device name and/or the given builder.
/// </summary>
/// <param name="deviceName">Device name to get the options from.</param>
/// <param name="browserNewContextOptionsBuilder">BrowserNewContextOptions builder.</param>
public void SetupBrowserNewContextOptions(string? deviceName = null, Action<BrowserNewContextOptions>? browserNewContextOptionsBuilder = null)
{
BrowserNewContextOptions options;
if (string.IsNullOrEmpty(deviceName) || !Playwright.Devices.TryGetValue(deviceName, out options))
{
options = new BrowserNewContextOptions();
}

options.IgnoreHTTPSErrors = true;

browserNewContextOptionsBuilder?.Invoke(options);

this.browserNewContextOptions = options;
}

/// <summary>
/// Open a Browser page and navigate to the given URL before applying the given test handler.
/// </summary>
Expand Down
11 changes: 5 additions & 6 deletions src/libs/SoloX.CodeQuality.Playwright/PlaywrightTestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@ private sealed class PlaywrightTestBuilderInternal : IPlaywrightTestBuilder, IPl
private Action<TracingStartOptions> traceFileOptionsBuilder = options => { };
private Action<BrowserNewContextOptions> browserNewContextOptionsBuilder = options => { };

public async Task<IPlaywrightTest> BuildAsync(Browser? browser = null)
public async Task<IPlaywrightTest> BuildAsync(Browser? browser = null, string? deviceName = null)
{
var port = SharedPortStore.GetPort(this.portRange);

var browserNewContextOptions = new BrowserNewContextOptions { IgnoreHTTPSErrors = true };

this.browserNewContextOptionsBuilder(browserNewContextOptions);

var traceFileOptions = new TracingStartOptions()
{
Screenshots = true,
Expand All @@ -67,14 +63,16 @@ public async Task<IPlaywrightTest> BuildAsync(Browser? browser = null)

this.traceFileOptionsBuilder(traceFileOptions);

var playwrightDriver = new PlaywrightDriver(this.goToPageRetryCount, browserNewContextOptions, traceFileOptions);
var playwrightDriver = new PlaywrightDriver(this.goToPageRetryCount, traceFileOptions);

var browserTypeLaunchOptions = new BrowserTypeLaunchOptions();

this.browserTypeLaunchOptionsBuilder(browserTypeLaunchOptions);

await playwrightDriver.InitializeAsync(browserTypeLaunchOptions).ConfigureAwait(false);

playwrightDriver.SetupBrowserNewContextOptions(deviceName, this.browserNewContextOptionsBuilder);

var disposable = (IAsyncDisposable?)null;
var url = this.onLineHost;

Expand Down Expand Up @@ -283,6 +281,7 @@ public Task GotoPageAsync(string relativePath, Func<IPage, Task> testHandler, st
return this.playwrightDriver.GotoPageAsync(
this.url.TrimEnd('/') + "/" + relativePath.TrimStart('/'),
testHandler,
browserType: this.browser,
traceFile: traceFile,
pageSetupHandler: pageSetupHandler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PlaywrightTestBuilderLocalTest()
.WithPlaywrightOptions(opt =>
{
//opt.Headless = false;
//opt.SlowMo = 1000;
//opt.SlowMo = 5000;
//opt.Timeout = 60000;
})
.WithPlaywrightNewContextOptions(opt =>
Expand All @@ -51,13 +51,17 @@ public PlaywrightTestBuilderLocalTest()
}

[Theory]
[InlineData(Browser.Chromium)]
[InlineData(Browser.Firefox)]
[InlineData(Browser.Webkit)]
public async Task ItShouldOpenTheHomePageFromStaticHomeFile(Browser browser)
[InlineData(Browser.Chromium, null)]
[InlineData(Browser.Chromium, Devices.Pixel)]
[InlineData(Browser.Chromium, Devices.PixelLandscape)]
[InlineData(Browser.Firefox, null)]
[InlineData(Browser.Webkit, null)]
[InlineData(Browser.Webkit, Devices.iPhone)]
[InlineData(Browser.Webkit, Devices.iPhoneLandscape)]
public async Task ItShouldOpenTheHomePageFromStaticHomeFile(Browser browser, string? deviceName)
{
var playwrightTest = await this.builder
.BuildAsync(browser)
.BuildAsync(browser, deviceName: deviceName)
.ConfigureAwait(true);

await using var _ = playwrightTest.ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.0" />
<PackageReference Include="SoloX.CodeQuality.Playwright" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading