-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
OSOE-415: Visual verification update and code refactoring
- Loading branch information
Showing
10 changed files
with
114 additions
and
81 deletions.
There are no files selected for viewing
Binary file modified
BIN
+323 Bytes
(100%)
...ts/BasicVisualVerificationTests_VerifyHomePage_By_TagName_-body_Unix_chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+323 Bytes
(100%)
...ts/BasicVisualVerificationTests_VerifyHomePage_By_TagName_-body_Unix_msedge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+92 Bytes
(100%)
...BasicVisualVerificationTests_VerifyHomePage_By_TagName_-body_Win32NT_chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+92 Bytes
(100%)
...BasicVisualVerificationTests_VerifyHomePage_By_TagName_-body_Win32NT_msedge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-761 Bytes
(83%)
...ficationTests_VerifyNavbar_By_ClassName[Contains]_-navbar-brand_Unix_chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-761 Bytes
(83%)
...ficationTests_VerifyNavbar_By_ClassName[Contains]_-navbar-brand_Unix_msedge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+597 Bytes
(120%)
...ationTests_VerifyNavbar_By_ClassName[Contains]_-navbar-brand_Win32NT_chrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+597 Bytes
(120%)
...ationTests_VerifyNavbar_By_ClassName[Contains]_-navbar-brand_Win32NT_msedge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 68 additions & 8 deletions
76
Lombiq.Tests.UI/Models/VisualVerificationMatchApprovedContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,72 @@ | ||
using Atata; | ||
using Lombiq.Tests.UI.Services; | ||
using OpenQA.Selenium; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Lombiq.Tests.UI.Models; | ||
|
||
public record VisualVerificationMatchApprovedContext | ||
public class VisualVerificationMatchApprovedContext | ||
{ | ||
public string ModuleName { get; set; } | ||
public string MethodName { get; set; } | ||
public string BrowserName { get; set; } | ||
public string BaselineFileName { get; set; } | ||
public string BaselineResourceName { get; set; } | ||
public string ModuleDirectory { get; set; } | ||
public string BaselineImagePath { get; set; } | ||
public string ModuleName { get; } | ||
public string MethodName { get; } | ||
public string BrowserName { get; } | ||
public string BaselineFileName { get; } | ||
public string BaselineResourceName { get; } | ||
public string ModuleDirectory { get; } | ||
public string BaselineImagePath { get; } | ||
|
||
public VisualVerificationMatchApprovedContext( | ||
UITestContext context, | ||
VisualVerificationMatchApprovedConfiguration configuration, | ||
EnhancedStackFrame testFrame) | ||
{ | ||
ModuleName = GetModuleName(testFrame); | ||
MethodName = GetMethodName(testFrame); | ||
BrowserName = context.Driver.As<IHasCapabilities>().Capabilities.GetCapability("browserName") as string; | ||
|
||
BaselineFileName = configuration.BaselineFileNameFormatter(configuration, this); | ||
BaselineResourceName = $"{testFrame.MethodInfo.DeclaringType!.Namespace}.{BaselineFileName}.png"; | ||
|
||
ModuleDirectory = Path.GetDirectoryName(testFrame.GetFileName()); | ||
BaselineImagePath = Path.Combine(ModuleDirectory!, $"{BaselineFileName}.png"); | ||
} | ||
|
||
private static string GetModuleName(EnhancedStackFrame frame) | ||
{ | ||
var currentMethod = frame.MethodInfo.DeclaringType!; | ||
string moduleName; | ||
|
||
// This is required to retrieve the class from the inheritance chain where the method was declared but not | ||
// overridden. | ||
do | ||
{ | ||
moduleName = currentMethod.Name; | ||
currentMethod = currentMethod.DeclaringType; | ||
} | ||
while (currentMethod is not null); | ||
|
||
var depthMark = new Regex("^(?<module>.*)`[0-9]+$", RegexOptions.ExplicitCapture); | ||
if (depthMark.IsMatch(moduleName)) | ||
{ | ||
moduleName = depthMark.Match(moduleName).Groups["module"].Value; | ||
} | ||
|
||
return moduleName; | ||
} | ||
|
||
// Retrieves the method name. Removes the decoration in case of if it inherited from a base class but not overridden. | ||
// Because of the inheritance, the method name gets some decoration in stack trace. | ||
private static string GetMethodName(EnhancedStackFrame frame) | ||
{ | ||
var methodName = frame.MethodInfo.Name!; | ||
var inheritedMethod = new Regex("^<(?<method>.*)>.*$", RegexOptions.ExplicitCapture); | ||
if (inheritedMethod.IsMatch(methodName)) | ||
{ | ||
methodName = inheritedMethod.Match(methodName).Groups["method"].Value; | ||
} | ||
|
||
return methodName; | ||
} | ||
} |