Skip to content

Commit 08ffee7

Browse files
Update sample code
- Make valid for nullable reference types. - Fix incorrect comment.
1 parent 92f1e16 commit 08ffee7

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ dotnet add package MartinCostello.BrowserStack.Automate
3333

3434
## Usage Examples
3535

36-
The following example shows a custom [xUnit.net](https://xunit.github.io/) ```[Trait]``` that checks for an available BrowserStack Automate session before running the test, otherwise it is skipped.
36+
The following example shows a custom [xUnit.net](https://xunit.github.io/) `[Fact]` that checks for an available BrowserStack Automate session before running the test, otherwise it is skipped.
3737

3838
```csharp
3939
namespace MyApp.Tests;
4040

41-
using System;
42-
using System.Configuration;
4341
using MartinCostello.BrowserStack.Automate;
4442
using Xunit;
4543

@@ -48,16 +46,23 @@ public sealed class RequiresBrowserStackAutomateAttribute : FactAttribute
4846
{
4947
public RequiresBrowserStackAutomateAttribute()
5048
{
51-
string userName = Environment.GetEnvironmentVariable("BrowserStack_UserName");
52-
string accessKey = Environment.GetEnvironmentVariable("BrowserStack_AccessKey");
49+
var userName = Environment.GetEnvironmentVariable("BrowserStack_UserName");
50+
var accessKey = Environment.GetEnvironmentVariable("BrowserStack_AccessKey");
5351

54-
var client = new BrowserStackAutomateClient(userName, accessKey);
55-
var plan = client.GetStatusAsync().Result;
56-
57-
if (plan.MaximumAllowedParallelSessions < 1 ||
58-
plan.ParallelSessionsRunning == plan.MaximumAllowedParallelSessions)
52+
if (userName is not null && accessKey is not null)
53+
{
54+
var client = new BrowserStackAutomateClient(userName, accessKey);
55+
var plan = client.GetStatusAsync().Result;
56+
57+
if (plan.MaximumAllowedParallelSessions < 1 ||
58+
plan.ParallelSessionsRunning == plan.MaximumAllowedParallelSessions)
59+
{
60+
Skip = "No BrowserStack Automate sessions are currently available.";
61+
}
62+
}
63+
else
5964
{
60-
Skip = "No BrowserStack Automate sessions are currently available.";
65+
Skip = "No BrowserStack Automate credentials are available.";
6166
}
6267
}
6368
}

0 commit comments

Comments
 (0)