Skip to content

Commit

Permalink
Allow to define region via env variables. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
konraddysput authored Jul 2, 2024
1 parent 7f29bed commit f11daa3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
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 @@ public class VisualClient : IDisposable

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

0 comments on commit f11daa3

Please sign in to comment.