Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel committed Mar 22, 2024
1 parent ea67975 commit 61ae201
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 14 additions & 1 deletion visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics;
using System.Linq;
using OpenQA.Selenium;
using SauceLabs.Visual.Models;

Expand All @@ -24,6 +26,17 @@ public class VisualCheckOptions
/// </summary>
public string? TestName { get; set; }

internal bool HasIncompleteTestContext() => string.IsNullOrEmpty(SuiteName) || string.IsNullOrEmpty(TestName);
private bool HasIncompleteTestContext() => string.IsNullOrEmpty(SuiteName) || string.IsNullOrEmpty(TestName);

internal void PopulateTestContext(string callerMemberName, string? previousSuiteName)
{
if (!string.IsNullOrEmpty(callerMemberName) && HasIncompleteTestContext())
{
var stack = new StackTrace();
var frame = stack.GetFrames()?.FirstOrDefault(f => f.GetMethod().Name == callerMemberName);
SuiteName ??= frame?.GetMethod().DeclaringType?.FullName ?? previousSuiteName;
TestName ??= callerMemberName;
}
}
}
}
10 changes: 2 additions & 8 deletions visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,8 @@ public Task<string> VisualCheck(string name, VisualCheckOptions? options = null,
[CallerMemberName] string callerMemberName = "")
{
options ??= new VisualCheckOptions();
if (!string.IsNullOrEmpty(callerMemberName) && options.HasIncompleteTestContext())
{
var stack = new StackTrace();
var frame = stack.GetFrames()?.FirstOrDefault(f => f.GetMethod().Name == callerMemberName);
options.SuiteName ??= frame?.GetMethod().DeclaringType?.FullName ?? _previousSuiteName;
options.TestName ??= callerMemberName;
_previousSuiteName = options.SuiteName;
}
options.PopulateTestContext(callerMemberName, _previousSuiteName);
_previousSuiteName = options.SuiteName;
return VisualCheckAsync(name, options);
}

Expand Down

0 comments on commit 61ae201

Please sign in to comment.