This repository contains a .NET client library/NuGet package for the BrowserStack Automate REST API.
Features include:
- Querying the status of a BrowserStack Automate plan.
- Querying the available browsers.
- Querying and deleting builds.
- Querying and deleting projects.
- Querying and deleting sessions.
- Querying session log.
- Setting the status of a session.
- Regenerating the API access key.
The assembly supports .NET Standard 2.0.
dotnet add package MartinCostello.BrowserStack.Automate
The following example shows a custom xUnit.net [Fact]
that checks for an available BrowserStack Automate session before running the test, otherwise it is skipped.
namespace MyApp.Tests;
using MartinCostello.BrowserStack.Automate;
using Xunit;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class RequiresBrowserStackAutomateAttribute : FactAttribute
{
public RequiresBrowserStackAutomateAttribute()
{
var userName = Environment.GetEnvironmentVariable("BrowserStack_UserName");
var accessKey = Environment.GetEnvironmentVariable("BrowserStack_AccessKey");
if (userName is not null && accessKey is not null)
{
using var client = new BrowserStackAutomateClient(userName, accessKey);
var plan = client.GetStatusAsync().Result;
if (plan.MaximumAllowedParallelSessions < 1 ||
plan.ParallelSessionsRunning == plan.MaximumAllowedParallelSessions)
{
Skip = "No BrowserStack Automate sessions are currently available.";
}
}
else
{
Skip = "No BrowserStack Automate credentials are available.";
}
}
}
Any feedback or issues can be added to the issues for this project in GitHub.
The repository is hosted in GitHub: https://github.com/martincostello/browserstack-automate.git
This project is licensed under the Apache 2.0 license.
To build and test the assembly run one of the following set of commands:
$env:BrowserStack_UserName = "MyUserName"
$env:BrowserStack_AccessKey = "MyAccessKey"
./build.ps1
If you do not have a BrowserStack Automate access key you can still just run the build script and the integration tests that require credentials will be skipped.