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

Allow to define region via env variables. #79

Merged
merged 3 commits into from
Jul 2, 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
12 changes: 12 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Region.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using SauceLabs.Visual.Utils;
using System;

namespace SauceLabs.Visual
Expand Down Expand Up @@ -28,6 +29,17 @@ public override string ToString()
return Value.ToString();
}

/// <summary>
/// <c>FromEnvironment</c> returns the <c>Region</c> instance based on the environment SAUCE_REGION.
/// If the env variable is unavailable, the default region will be returned -
/// </summary>
/// <returns>the matching <c>Region</c> instance</returns>
/// <exception cref="VisualClientException"></exception>
public static Region FromEnvironment()
{
return string.IsNullOrEmpty(EnvVars.Region) ? FromName(EnvVars.Region) : UsWest1;
}

/// <summary>
/// <c>FromName</c> returns the <c>Region</c> instance corresponding to <c>name</c>.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions visual-dotnet/SauceLabs.Visual/Utils/EnvVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal class EnvVars
internal static string BuildId => Environment.GetEnvironmentVariable("SAUCE_VISUAL_BUILD_ID") ?? "";
internal static string Username => Environment.GetEnvironmentVariable("SAUCE_USERNAME") ?? "";
internal static string AccessKey => Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY") ?? "";
internal static string Region => Environment.GetEnvironmentVariable("SAUCE_REGION") ?? "";
}
}
19 changes: 19 additions & 0 deletions visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@

private string? _previousSuiteName = null;

/// <summary>
/// Creates a new instance of <c>VisualClient</c>
/// </summary>
/// <param name="wd">the instance of the WebDriver session</param>
public static async Task<VisualClient> Create(WebDriver wd)
{
return await Create(wd, Region.FromEnvironment(), EnvVars.Username, EnvVars.AccessKey, new CreateBuildOptions());
}

/// <summary>
/// Creates a new instance of <c>VisualClient</c>
/// </summary>
/// <param name="wd">the instance of the WebDriver session</param>
/// <param name="buildOptions">the options of the build creation</param>
public static async Task<VisualClient> Create(WebDriver wd, CreateBuildOptions buildOptions)
{
return await Create(wd, Region.FromEnvironment(), EnvVars.Username, EnvVars.AccessKey, buildOptions);
}

/// <summary>
/// Creates a new instance of <c>VisualClient</c>
/// </summary>
Expand Down Expand Up @@ -92,7 +111,7 @@
/// <param name="region">the Sauce Labs region to connect to</param>
/// <param name="username">the Sauce Labs username</param>
/// <param name="accessKey">the Sauce Labs access key</param>
private VisualClient(WebDriver wd, Region region, string username, string accessKey)

Check warning on line 114 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 114 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
if (StringUtils.IsNullOrEmpty(username) || StringUtils.IsNullOrEmpty(accessKey))
{
Expand Down