Skip to content

Commit

Permalink
Merge pull request #17 from aquality-automation/cross-platform-visual…
Browse files Browse the repository at this point in the history
…ization

[Visualization] Use cross-platform solution for visual testing
  • Loading branch information
aqualityAutomation authored Mar 16, 2023
2 parents 9c75d2c + 9ebb43c commit 5258f0e
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Allure" Version="1.2.1.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
using NUnit.Framework;
using Aquality.Selenium.Template.Utilities;
using System.Drawing;
using Aquality.Selenium.Template.CustomAttributes;
using System.Diagnostics.CodeAnalysis;
using SkiaSharp;
using System.IO;
using Aquality.Selenium.Core.Visualization;

namespace Aquality.Selenium.Template.NUnit.Steps
{
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
public class CustomImageComparatorSteps
{
private readonly CustomImageComparator customImageComparator;
private readonly Image modelOfImage;
private readonly SKImage modelOfImage;

public CustomImageComparatorSteps(float customThresholdValue, string modelImageResourses)
{
modelOfImage = Image.FromFile(modelImageResourses);
modelOfImage = new FileInfo(modelImageResourses).ReadImage();
var imageWidth = modelOfImage.Width;
var imageHeight = modelOfImage.Height;
customImageComparator = new CustomImageComparator(customThresholdValue, imageWidth, imageHeight);
}

[LogStep(StepType.Step)]
public static Image GetExpectedImageFromResourse(string expectedImageResourse)
public static SKImage GetExpectedImageFromResourse(string expectedImageResourse)
{
return Image.FromFile(expectedImageResourse);
return new FileInfo(expectedImageResourse).ReadImage();
}

[LogStep(StepType.Assertion)]
public void CheckThatActualAndExpectedImagesAreTheSame(Image expectedImage)
public void CheckThatActualAndExpectedImagesAreTheSame(SKImage expectedImage)
{
var differenceBetweenImages = customImageComparator.Compare(modelOfImage, expectedImage);
Assert.AreEqual(0, differenceBetweenImages, "The images should be the same");
}

[LogStep(StepType.Assertion)]
public void CheckThatActualAndExpectedImagesAreNotTheSame(Image expectedImage)
public void CheckThatActualAndExpectedImagesAreNotTheSame(SKImage expectedImage)
{
var differenceBetweenImages = customImageComparator.Compare(modelOfImage, expectedImage);
Assert.AreNotEqual(0, differenceBetweenImages, "The images should not be the same");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Aquality.Selenium.Template.NUnit.Steps
public class FooterFormSteps
{
private readonly FooterForm footerForm = new FooterForm();
const float ComparisonThreshold = 0.08f;
const float ComparisonThreshold = 0.1f;

[LogStep(StepType.Assertion)]
public void FooterFormIsPresent()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aquality.Selenium" Version="4.9.1" />
<PackageReference Include="Aquality.Selenium" Version="4.12.0" />
<PackageReference Include="AqualityTracking.SpecFlowPlugin" Version="1.0.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1">
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="SpecFlow" Version="3.9.74" />
<PackageReference Include="SpecFlow.Allure" Version="3.5.0.73" />
<PackageReference Include="SpecFlow.NUnit" Version="3.9.74" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ Scenario Outline: Empty email validation is working on Contact Us page
When I open Contact us page
Then Contact us page is opened
When I save Contact us page dump
And I fill contact form using following data:
| Name | Value |
| Name | <Name> |
| Company | Aquality Automation |
| Phone | +44 208 816 7320 |
| Comment | I'd like to contact you! |
And I accept Privacy and Cookies Policy
And I click Send button
And I fill contact form using following data:
| Name | Value |
| Name | <Name> |
| Company | Aquality Automation |
| Phone | +44 208 816 7320 |
| Comment | I'd like to contact you! |
And I accept Privacy and Cookies Policy
And I click Send button
Then Notification about empty fields is present
And Contact us page dump is different
And Contact us page dump is different

Examples:
| Name |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

<ItemGroup>
<PackageReference Include="Allure.Commons" Version="3.5.0.73" />
<PackageReference Include="Aquality.Selenium" Version="4.9.1" />
<PackageReference Include="Aquality.Selenium" Version="4.12.0" />
<PackageReference Include="AspectInjector" Version="2.8.1" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="NUnit.Allure" Version="1.2.1.1" />
<PackageReference Include="AqualityTracking.Integrations.Core" Version="1.0.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="RestSharp" Version="108.0.3" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="RestSharp" Version="109.0.1" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ContactUsPage : BaseAppForm
private ITextBox CommentTextBox => ElementFactory.GetTextBox(By.Id("your-message"), "Project description");
private ICheckBox PrivacyCheckBox => ElementFactory.GetCheckBox(By.XPath("//input[@name='privacy']/following-sibling::span[1]"), "Privacy");
private IButton SendButton => ElementFactory.GetButton(By.XPath("//div[contains(@class,'contactsForm__submit')]//button"), "Send a message");
private ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message", Core.Elements.ElementState.ExistsInAnyState);
private ILabel EmailAlertLabel => ElementFactory.GetLabel(By.XPath("//div[contains(@class,'error')]//input[@id='your-email']"), "Email validating message", ElementState.ExistsInAnyState);
private ILabel TitleLabel => FormElement.FindChildElement<ILabel>(By.XPath("//h2[contains(@class,'blockTitle')]"), "Title");
private ILabel TermsLabel => FormElement.FindChildElement<ILabel>(By.XPath("//label[contains(@class, 'checkbox')]"), "Terms");
private ITextBox ContactUsTextBox(ContactUsTextFields contactUsTextField) => ElementFactory.GetTextBox(By.Id($"{contactUsTextField.GetId()}"), contactUsTextField.ToString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Visualization;
using System.Drawing;
using SkiaSharp;

namespace Aquality.Selenium.Template.Utilities
{
Expand All @@ -14,7 +14,7 @@ public CustomImageComparator(float defaultThreshold, int comparisonWidth, int co
imageComparator = new ImageComparator(visualizationConfiguration);
}

public float Compare(Image firstImage, Image secondImage, float? threshold = null)
public float Compare(SKImage firstImage, SKImage secondImage, float? threshold = null)
{
return imageComparator.PercentageDifference(firstImage, secondImage, threshold);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Core.Visualization;
using SkiaSharp;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Diagnostics.CodeAnalysis;

namespace Aquality.Selenium.Template.Utilities
{
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
public class ScreenshotProvider
{
public string TakeScreenshot()
Expand All @@ -17,16 +15,14 @@ public string TakeScreenshot()
EnsureDirectoryExists(directory);
var screenshotName = $"{GetType().Name}_{DateTime.Now:yyyyMMdd_HHmmss}_{Guid.NewGuid().ToString("n").Substring(0, 5)}.png";
var path = Path.Combine(directory, screenshotName);
image.Save(path, ImageFormat.Png);
image.Save(path, SKEncodedImageFormat.Png);
return path;
}

private static Image GetImage()
private static SKImage GetImage()
{
using (var stream = new MemoryStream(AqualityServices.Browser.GetScreenshot()))
{
return Image.FromStream(stream);
}
using var stream = new MemoryStream(AqualityServices.Browser.GetScreenshot());
return SKImage.FromEncodedData(stream);
}

private static void EnsureDirectoryExists(string directory)
Expand Down

0 comments on commit 5258f0e

Please sign in to comment.