Skip to content
Open
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
136 changes: 136 additions & 0 deletions .github/workflows/crossBrowserTesting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Cross-browser testing

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "27 20 * * 0"

jobs:

# Summary:
#
# * Installs and configures the environment
# * Builds the solution in Debug configuration
# * Runs just the Selenium tests
# * In Debug configuration (.NET tests)
# * Using the BrowserStack browser configuration

browser_tests:

strategy:
matrix:
include:
- browserName: Chrome
browserVersion: latest-50
os: Windows
osVersion: 11
# - browserName: Chrome
# browserVersion: latest
# os: Windows
# osVersion: 11
# - browserName: Edge
# browserVersion: latest
# os: Windows
# osVersion: 11
# - browserName: Firefox
# browserVersion: latest
# os: Windows
# osVersion: 11
# - browserName: Firefox
# browserVersion: latest-40
# os: Windows
# osVersion: 11
# - browserName: Safari
# browserVersion: 17.3
# os: OS X
# osVersion: Sonoma
# - browserName: Safari
# browserVersion: 26.2
# os: OS X
# osVersion: Tahoe

name: Run tests
runs-on: ubuntu-24.04
timeout-minutes: 30

env:
RunNumber: ${{ github.run_number }}.${{ github.run_attempt }}
VersionSuffix: crossbrowser.${{ github.run_number }}
Configuration: Release
Tfm: net8.0
DotnetVersion: 8.0.x
WebDriverFactory__SelectedConfiguration: BrowserStack
BSbrowserName: ${{ matrix.browserName }}
BSbrowserVersion: ${{ matrix.browserVersion }}
BSos: ${{ matrix.os }}
BSosVersion: ${{ matrix.osVersion }}
BSuserName: ${{ secrets.BROWSERSTACK_USERNAME }}
BSaccessKey: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BSprojectName: CSF.Screenplay
BSbuildName: ghActionsRun.${{ github.run_number }}.${{ github.run_attempt }}_${{ matrix.browserName }}:${{ matrix.browserVersion }}_${{ matrix.os }}:${{ matrix.osVersion }}

steps:
- name: Checkout
uses: actions/checkout@v4

# Install build dependencies

- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DotnetVersion }}
- name: Install Node.js for building JSON-to-HTML report converter
uses: actions/setup-node@v6.2.0

# Environment setup pre-build

- name: Restore .NET packages
run: dotnet restore
- name: Restore Node modules
run: |
cd CSF.Screenplay.JsonToHtmlReport.Template/src
npm ci
cd ../..

# Build and test the solution

- name: Build the solution
run: dotnet build -c ${{ env.Configuration }}
- name: Run .NET tests with coverage
id: dotnet_tests
run: dotnet test -c ${{ env.Configuration }} --no-build Tests/CSF.Screenplay.Selenium.Tests -- NumberOfTestWorkers=5
continue-on-error: true

# Post-test tasks (artifacts, overall status)
- name: Upload .NET test results artifacts
uses: actions/upload-artifact@v4
with:
name: NUnit test results
path: Tests/CSF.Screenplay.Selenium.Tests/**/TestResults.xml
- name: Upload Screenplay JSON report artifact
uses: actions/upload-artifact@v4
with:
name: Screenplay JSON reports
path: Tests/CSF.Screenplay.Selenium.Tests/**/ScreenplayReport_*.json
- name: Convert Screenplay reports to HTML
continue-on-error: true
run: |
for report in $(find Tests/CSF.Screenplay.Selenium.Tests/ -type f -name "ScreenplayReport_*.json")
do
reportDir=$(dirname "$report")
outputFile="$reportDir/ScreenplayReport.html"
dotnet run --no-build --framework $Tfm -c {{ env.Configuration }} --project CSF.Screenplay.JsonToHtmlReport --ReportPath "$report" --OutputPath "$outputFile"
done
- name: Upload Screenplay HTML report artifact
uses: actions/upload-artifact@v4
with:
name: Screenplay HTML reports
path: Tests/**/ScreenplayReport.html
- name: Fail the build if any test failures
if: steps.dotnet_tests.outcome == 'failure'
run: |
echo "Failing the build due to test failures"
exit 1
7 changes: 3 additions & 4 deletions .github/workflows/dotnetCi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
BranchParam: ${{ github.event_name == 'pull_request' && 'sonar.pullrequest.branch' || 'sonar.branch.name' }}
PullRequestParam: ${{ github.event_name == 'pull_request' && format('/d:sonar.pullrequest.key={0}', github.event.number) || '' }}
DISPLAY: :99
# Change selected factory to VerboseChrome to debug Chrome-related issues
WebDriverFactory__SelectedConfiguration: DefaultChrome

steps:
- name: Checkout
Expand Down Expand Up @@ -171,7 +173,7 @@ jobs:
do
reportDir=$(dirname "$report")
outputFile="$reportDir/ScreenplayReport.html"
dotnet run --no-build --framework $Tfm --project CSF.Screenplay.JsonToHtmlReport --ReportPath "$report" --OutputPath "$outputFile"
dotnet run --no-build --framework $Tfm -c ${{ env.Configuration }} --project CSF.Screenplay.JsonToHtmlReport --ReportPath "$report" --OutputPath "$outputFile"
done
- name: Upload Screenplay HTML report artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -202,6 +204,3 @@ jobs:
with:
name: Docs website
path: docs/**/*

# runBrowserTests:
# TODO: Use build-results artifacts and run tests on matrix of browsers
13 changes: 13 additions & 0 deletions CSF.Screenplay/ScreenplayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ public static ScopeAndPerformance CreateScopedPerformance(this Screenplay screen
return new ScopeAndPerformance(performance, scope);
}

/// <summary>
/// Gets the event bus from the screenplay's service provider.
/// </summary>
/// <param name="screenplay">The screenplay from which to retrieve the event bus.</param>
/// <returns>The <see cref="IHasPerformanceEvents"/> event bus instance.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="screenplay"/> is <see langword="null" />.</exception>
public static IHasPerformanceEvents GetEventBus(this Screenplay screenplay)
{
if (screenplay is null)
throw new ArgumentNullException(nameof(screenplay));
return screenplay.ServiceProvider.GetRequiredService<IHasPerformanceEvents>();
}

static AsyncPerformanceLogic GetAsyncPerformanceLogic(SyncPerformanceLogic syncPerformanceLogic)
{
return (services, token) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class ClearCookiesTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class ClearLocalStorageTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class ClearTheContentsTests
{
static readonly ITarget
Expand Down
2 changes: 1 addition & 1 deletion Tests/CSF.Screenplay.Selenium.Tests/Actions/ClickTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class ClickTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class DeleteTheCookieTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class DeselectAllTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class DeselectByIndexTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class DeselectByTextTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class DeselectByValueTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class ExecuteJavaScriptTests
{
const string scriptBody = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class OpenUrlTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class SelectByIndexTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class SelectByTextTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class SelectByValueTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class SendKeysTests
{
static readonly ITarget
Expand Down
3 changes: 1 addition & 2 deletions Tests/CSF.Screenplay.Selenium.Tests/Actions/WaitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using System;
using CSF.Screenplay.Performables;
using CSF.Screenplay.Selenium.Elements;
using OpenQA.Selenium;
using static CSF.Screenplay.PerformanceStarter;
using static CSF.Screenplay.Selenium.PerformableBuilder;

namespace CSF.Screenplay.Selenium.Actions;

[TestFixture]
[TestFixture, Parallelizable]
public class WaitTests
{
static readonly ITarget
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using CSF.Extensions.WebDriver.Factories;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Safari;
using static CSF.Screenplay.Selenium.BrowserStack.BrowserStackEnvironment;

namespace CSF.Screenplay.Selenium.BrowserStack;

/// <summary>
/// Implementation of <see cref="ICreatesWebDriverFromOptions"/> which creates drivers for BrowserStack.
/// </summary>
/// <remarks>
/// <para>
/// I'm using this instead of the BrowserStack SDK because I'm already modifying the way that tests run via Screenplay, so I want to avoid
/// messing with them twice. Later, I can give a try with the official SDK to see if its compatible with Screenplay.
/// </para>
/// </remarks>
public class BrowserStackDriverFactory : ICreatesWebDriverFromOptions
{
const string AdditionalOptionsCapabilityName = "bstack:options";

const string GridUrl = "http://localhost:4444/wd/hub/";

public WebDriverAndOptions GetWebDriver(WebDriverCreationOptions options, Action<DriverOptions>? supplementaryConfiguration = null)
{
var driverOptions = GetDriverOptions();
driverOptions.AddAdditionalOption(AdditionalOptionsCapabilityName, GetBrowserStackOptions());
var driver = new RemoteWebDriver(new Uri(GridUrl), driverOptions);
return new (driver, driverOptions);
}

DriverOptions GetDriverOptions()
{
var browserName = GetBrowserName();
return browserName switch
{
"Chrome" => new ChromeOptions(),
"Edge" => new EdgeOptions(),
"Firefox" => new FirefoxOptions(),
"Safari" => new SafariOptions(),
_ => throw new InvalidOperationException($"The {BrowserName} environment variable: '{GetBrowserName()}' must indicate a supported browser"),
};
}

static Dictionary<string, object?> GetBrowserStackOptions()
{
return new ()
{
{ "os", GetOperatingSystem() },
{ "osVersion", GetOperatingSystemVersion() },
{ "browserVersion", GetBrowserVersion() },
{ "userName", GetBrowserStackUserName() },
{ "accessKey", GetBrowserStackAccessKey() },
{ "local", bool.TrueString.ToLowerInvariant() },
{ "projectName", GetProjectName() },
{ "buildName", GetBuildName() },
{ "sessionName", GetTestName() }
};
}

static string GetTestName() => TestContext.CurrentContext.Test.ID;
}
Loading
Loading