Saucery.XUnit
4.5.14
Prefix Reserved
dotnet add package Saucery.XUnit --version 4.5.14
NuGet\Install-Package Saucery.XUnit -Version 4.5.14
<PackageReference Include="Saucery.XUnit" Version="4.5.14" />
paket add Saucery.XUnit --version 4.5.14
#r "nuget: Saucery.XUnit, 4.5.14"
// Install Saucery.XUnit as a Cake Addin #addin nuget:?package=Saucery.XUnit&version=4.5.14 // Install Saucery.XUnit as a Cake Tool #tool nuget:?package=Saucery.XUnit&version=4.5.14
Saucery.XUnit
Saucery handles all the plumbing required to integrate with SauceLabs, making writing XUnit tests a breeze, so you only need to tell Saucery what you want. Saucery takes care of the how.
Note: The tests specified below are provided as examples only. Your tests, of course, will be specific to your System Under Test.
Initial Setup
- You'll need a SauceLabs account. You can get a free trial account here.
- If you want to run your tests locally you need to set 2 environment variables, SAUCE_USER_NAME and SAUCE_API_KEY
- To run your test suite from your GitHub Actions pipeline you need to set two secrets SAUCE_USER_NAME and SAUCE_API_KEY. Instructions on how to set Github Secrets are here.
Writing XUnit Tests
- In your solution create a simple class library.
- Add properties CopyLocalLockFileAssemblies and GenerateRuntimeConfigurationFiles to the top PropertyGroup of the project file and set them both to true.
- Add a NuGet Reference to Saucery.XUnit and xunit.runner.visualstudio.
Your Project file should look something like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Saucery.XUnit" Version="4.5.7" />
</ItemGroup>
</Project>
The ExternalMerlin.XUnit dogfood integration tests use the following template:
using ExternalMerlin.XUnit.PageObjects;
using Saucery.Core.Dojo;
using Saucery.XUnit;
using Xunit.Abstractions;
[assembly: CollectionBehavior(MaxParallelThreads = 5)]
namespace ExternalMerlin.XUnit;
public class DataDrivenTests(ITestOutputHelper output, BaseFixture baseFixture) : SauceryXBase(output, baseFixture)
{
[Theory]
[MemberData(nameof(AllCombinations))]
public void DataDrivenTest(BrowserVersion requestedPlatform, int data)
{
InitialiseDriver(requestedPlatform);
var guineaPigPage = new GuineaPigPage(BaseFixture.SauceryDriver(), "https://saucelabs.com/");
guineaPigPage.TypeField(BaseFixture.SauceryDriver(), "comments", data.ToString());
}
public static IEnumerable<object[]> AllCombinations => GetAllCombinations([4, 5]);
}
The above code will run 2 unit tests (2 DataDrivenTitle tests) on all the platforms you specify.
Parallelism
- Parallelism in XUnit is currently achieved by having tests in multiple classes.
- The Level of Parallelism is determined by the number of parallel threads you have paid for in your SauceLabs account.
- Parallism is optional so you can exclude
[assembly: CollectionBehavior(MaxParallelThreads = 5)]
lines if you wish. We recommend placing this line in aUsings.cs
as it will apply to all your TestFixtures.
Next, let's break down the key line.
public class DataDrivenTests(ITestOutputHelper output, BaseFixture baseFixture) : SauceryXBase(output, baseFixture)
Your class must subclass SauceryXBase
and pass an ITestOutputHelper
and a BaseFixture
. SauceryX will take care of the rest.
You need to specify a class to tell SauceryX what platforms you want to test on. In this example its called RequestedPlatformData
but you can call it anything you like.
Let's look at what it should contain.
using Saucery.Core.DataSources;
using Saucery.Core.OnDemand;
using Saucery.Core.OnDemand.Base;
using Saucery.Core.Util;
namespace ExternalMerlin.XUnit;
public class RequestedPlatformData : SauceryTestData
{
static RequestedPlatformData()
{
List<SaucePlatform> platforms =
[
//Real Devices
new AndroidRealDevice("Google Pixel 8 Pro", "14"),
new IOSRealDevice("iPhone 14 Pro Max", "16"),
//Emulated Mobile Platforms
new AndroidPlatform("Google Pixel 8 Pro GoogleAPI Emulator", "14.0", SauceryConstants.DEVICE_ORIENTATION_PORTRAIT),
new IOSPlatform("iPhone 14 Pro Max Simulator", "16.2", SauceryConstants.DEVICE_ORIENTATION_LANDSCAPE),
//Desktop Platforms
new DesktopPlatform(SauceryConstants.PLATFORM_LINUX, SauceryConstants.BROWSER_CHROME, SauceryConstants.BROWSER_VERSION_LATEST),
new DesktopPlatform(SauceryConstants.PLATFORM_WINDOWS_11, SauceryConstants.BROWSER_CHROME, "75"),
new DesktopPlatform(SauceryConstants.PLATFORM_WINDOWS_10, SauceryConstants.BROWSER_CHROME, "76", SauceryConstants.SCREENRES_2560_1600)
];
SetPlatforms(platforms, PlatformFilter.Emulated);
}
public static IEnumerable<object[]> AllPlatforms => GetAllPlatforms();
}
The List<SaucePlatform>
is what you will specify. The rest of the class is mandatory. Check out SauceryConstants
for all the platform, browser and screenres enums.
Platform Range Expansion
Platform range expansion is a feature unique to Saucery. Say you wanted to test on a range of browser versions but you didn't want to specify each individually. That's fine. Saucery supports specifying ranges.
new DesktopPlatform(SauceryConstants.PLATFORM_WINDOWS_11, SauceryConstants.BROWSER_CHROME, "100->119")
This will test on Windows 11 Chrome all available versions from 100 to 119 inclusive.
Real Devices
Yes, Saucery supports Real Devices!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Meziantou.Xunit.ParallelTestFramework (>= 2.3.0)
- Microsoft.NET.Test.Sdk (>= 17.12.0)
- Saucery.Core (>= 4.5.14)
- xunit (>= 2.9.3)
- XunitContext (>= 3.3.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.5.14 | 198 | 1/27/2025 |
4.5.13 | 387 | 1/21/2025 |
4.5.12 | 138 | 1/21/2025 |
4.5.11 | 185 | 1/19/2025 |
4.5.10 | 265 | 1/17/2025 |
4.5.9 | 183 | 1/12/2025 |
4.5.8 | 504 | 12/28/2024 |
4.5.7 | 632 | 12/9/2024 |
4.5.6 | 754 | 9/26/2024 |
4.5.5 | 270 | 9/13/2024 |
4.5.4 | 383 | 8/1/2024 |
4.5.3 | 418 | 7/12/2024 |
4.5.2 | 172 | 7/10/2024 |
4.5.1 | 391 | 6/29/2024 |
4.5.0 | 189 | 6/25/2024 |
4.4.6 | 180 | 6/24/2024 |
4.4.5 | 179 | 6/23/2024 |
4.4.4 | 266 | 5/26/2024 |
4.4.3 | 646 | 12/16/2023 |
4.4.2 | 255 | 12/11/2023 |
4.4.1 | 165 | 12/11/2023 |
4.4.0 | 326 | 12/8/2023 |
4.3.0 | 290 | 11/18/2023 |
4.2.0 | 333 | 8/5/2023 |
4.0.0 | 317 | 4/22/2023 |
ChangeLog:
v4.0.0
- Initial Release with dependency on Saucery.Core