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

[Visual Testing] Add ability of visualization checks for the Form +semver: breaking #204

Merged
merged 9 commits into from
Jun 10, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ msbuild.wrn
.vs/

Log/
VisualDumps/
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Edge.SeleniumTools" Version="3.141.2" />
<PackageReference Include="Aquality.Selenium.Core" Version="1.3.1" />
<PackageReference Include="Aquality.Selenium.Core" Version="1.6.1" />
<PackageReference Include="WebDriverManager" Version="2.11.1" />
</ItemGroup>

Expand Down
45 changes: 15 additions & 30 deletions Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void SwitchToTab(int index, bool closeCurrent = false)
var names = TabHandles;
if (index < 0 || names.Count <= index)
{
throw new IndexOutOfRangeException(
throw new ArgumentOutOfRangeException(
$"Index of browser tab '{index}' you provided is out of range {0}..{names.Count}");
}

Expand Down
22 changes: 13 additions & 9 deletions Aquality.Selenium/src/Aquality.Selenium/Elements/Element.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using OpenQA.Selenium;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Elements.Actions;
using Aquality.Selenium.Elements.Interfaces;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Configurations;
using Aquality.Selenium.Core.Utilities;
using Aquality.Selenium.Core.Applications;
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Core.Logging;
using Aquality.Selenium.Core.Utilities;
using Aquality.Selenium.Core.Visualization;
using Aquality.Selenium.Core.Waitings;
using Aquality.Selenium.Elements.Actions;
using Aquality.Selenium.Elements.Interfaces;
using OpenQA.Selenium;
using System.Reflection;
using System.Linq;
using CoreElement = Aquality.Selenium.Core.Elements.Element;
using ICoreElementFactory = Aquality.Selenium.Core.Elements.Interfaces.IElementFactory;
using ICoreElementFinder = Aquality.Selenium.Core.Elements.Interfaces.IElementFinder;
using ICoreElementStateProvider = Aquality.Selenium.Core.Elements.Interfaces.IElementStateProvider;
using Aquality.Selenium.Core.Configurations;
using System.Reflection;
using System.Linq;

namespace Aquality.Selenium.Elements
{
Expand Down Expand Up @@ -55,6 +57,8 @@ protected Element(By locator, string name, ElementState state) : base(locator, n

protected override IConditionalWait ConditionalWait => AqualityServices.ConditionalWait;

protected override IImageComparator ImageComparator => AqualityServices.Get<IImageComparator>();

public void ClickAndWait()
{
Click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Core.Elements.Interfaces;
using Aquality.Selenium.Core.Elements.Interfaces;
using Aquality.Selenium.Core.Logging;
using Aquality.Selenium.Core.Waitings;
using OpenQA.Selenium;
using CoreElementStateProvider = Aquality.Selenium.Core.Elements.ElementStateProvider;
Expand Down
75 changes: 25 additions & 50 deletions Aquality.Selenium/src/Aquality.Selenium/Forms/Form.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenQA.Selenium;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Core.Logging;
using System.Drawing;
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Core.Logging;
using Aquality.Selenium.Core.Forms;
using Aquality.Selenium.Elements.Interfaces;
using OpenQA.Selenium;
using IElementStateProvider = Aquality.Selenium.Core.Elements.Interfaces.IElementStateProvider;
using Aquality.Selenium.Core.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Core.Waitings;

namespace Aquality.Selenium.Forms
{
/// <summary>
/// Defines base class for any UI form.
/// </summary>
public abstract class Form
public abstract class Form : Form<IElement>
{
private readonly ILabel formLabel;
/// <summary>
Expand All @@ -39,6 +40,21 @@ protected Form(By locator, string name)
/// </summary>
protected static Logger Logger => AqualityServices.Logger;

/// <summary>
/// Visualization configuration used by <see cref="Form{T}.Dump"/>.
/// </summary>
protected override IVisualizationConfiguration VisualizationConfiguration => AqualityServices.Get<IVisualizationConfiguration>();

/// <summary>
/// Localized logger used by <see cref="Form{T}.Dump"/>.
/// </summary>
protected override ILocalizedLogger LocalizedLogger => AqualityServices.LocalizedLogger;

/// <summary>
/// Conditional wait <see cref="IConditionalWait"/>
/// </summary>
protected static IConditionalWait ConditionalWait => AqualityServices.ConditionalWait;

/// <summary>
/// Element factory <see cref="IElementFactory"/>
/// </summary>
Expand All @@ -52,15 +68,7 @@ protected Form(By locator, string name)
/// <summary>
/// Name of the form.
/// </summary>
public string Name { get; }

/// <summary>
/// Return form state for form locator
/// </summary>
/// <value>True - form is opened,
/// False - form is not opened.</value>
[Obsolete("This property will be removed in the future release. Use State.WaitForDisplayed() if needed")]
public bool IsDisplayed => FormElement.State.WaitForDisplayed();
public override string Name { get; }

/// <summary>
/// Provides ability to get form's state (whether it is displayed, exists or not) and respective waiting functions.
Expand All @@ -70,7 +78,7 @@ protected Form(By locator, string name)
/// <summary>
/// Gets size of form element defined by its locator.
/// </summary>
public Size Size => FormElement.GetElement().Size;
public Size Size => FormElement.Visual.Size;

/// <summary>
/// Scroll form without scrolling entire page
Expand All @@ -81,38 +89,5 @@ public void ScrollBy(int x, int y)
{
FormElement.JsActions.ScrollBy(x, y);
}

/// <summary>
/// Finds child element of current form by its locator.
/// </summary>
/// <typeparam name="T">Type of child element that has to implement IElement.</typeparam>
/// <param name="childLocator">Locator of child element relative to form.</param>
/// <param name="name">Child element name.</param>
/// <param name="supplier">Delegate that defines constructor of child element in case of custom element.</param>
/// <param name="state">Child element state.</param>
/// <returns>Instance of child element.</returns>
[Obsolete("This method will be removed in the future release. Use FormElement property methods to find child element")]
protected T FindChildElement<T>(By childLocator, string name = null, ElementSupplier<T> supplier = null, ElementState state = ElementState.Displayed)
where T : IElement
{
return FormElement.FindChildElement(childLocator, name, supplier, state);
}

/// <summary>
/// Finds child elements of current form by their locator.
/// </summary>
/// <typeparam name="T">Type of child elements that has to implement IElement.</typeparam>
/// <param name="childLocator">Locator of child elements relative to form.</param>
/// <param name="name">Child elements name.</param>
/// <param name="supplier">Delegate that defines constructor of child element in case of custom element type.</param>
/// <param name="expectedCount">Expected number of elements that have to be found (zero, more then zero, any).</param>
/// <param name="state">Child elements state.</param>
/// <returns>List of child elements.</returns>
[Obsolete("This method will be removed in the future release. Use FormElement property methods to find child elements")]
protected IList<T> FindChildElements<T>(By childLocator, string name = null, ElementSupplier<T> supplier = null, ElementsCount expectedCount = ElementsCount.Any, ElementState state = ElementState.Displayed)
where T : IElement
{
return FormElement.FindChildElements(childLocator, name, supplier, expectedCount, state);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,11 @@
},
"elementCache": {
"isEnabled": false
},
"visualization": {
"defaultThreshold": 0.012,
"comparisonWidth": 16,
"comparisonHeight": 16,
"pathToDumps": "../../../Resources/VisualDumps/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.13.0" />
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Elements;
using Aquality.Selenium.Tests.Integration.TestApp;
using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms;
using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms;
using NUnit.Framework;
Expand Down Expand Up @@ -47,7 +46,7 @@ public void Should_BePossibleTo_HighlightElement()
[Test]
public void Should_BePossibleTo_HoverMouse()
{
AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice);
OpenAutomationPracticeSite();
var productList = new ProductListForm();
productList.NavigateToLastProduct();

Expand All @@ -60,7 +59,7 @@ public void Should_BePossibleTo_HoverMouse()
[Test]
public void Should_BePossibleTo_SetFocus()
{
AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice);
OpenAutomationPracticeSite();
var productList = new ProductListForm();
productList.NavigateToLastProduct();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Tests.Integration.TestApp;
using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms;
using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms;
using NUnit.Framework;
Expand Down Expand Up @@ -39,7 +38,7 @@ public void Should_BePossibleTo_RightClick()
[Test]
public void Should_BePossibleTo_MoveToElement()
{
AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice);
OpenAutomationPracticeSite();
var productList = new ProductListForm();
productList.NavigateToLastProduct();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void Should_BePossibleTo_SwitchToNewTabByIndex_AndClose()
[Test]
public void Should_BeThrow_IfSwitchToNewTab_ByIncorrectIndex()
{
Assert.Throws(typeof(IndexOutOfRangeException), () => { AqualityServices.Browser.Tabs().SwitchToTab(10, true); });
Assert.Throws<ArgumentOutOfRangeException>(() => { AqualityServices.Browser.Tabs().SwitchToTab(10, true); });
}

private void CheckSwitchingBy(int expectedTabCount, Action switchMethod)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Tests.Integration.TestApp;
using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms;
using Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms;
using TheInternetAuthenticationForm = Aquality.Selenium.Tests.Integration.TestApp.TheInternet.Forms.AuthenticationForm;
Expand Down Expand Up @@ -189,12 +188,11 @@ public void Should_BePossibleTo_SetWindowSize()
[Test]
public void Should_BePossibleTo_ScrollWindowBy()
{
var browser = AqualityServices.Browser;
browser.GoTo(Constants.UrlAutomationPractice);
OpenAutomationPracticeSite();
var sliderForm = new SliderForm();
var initialY = sliderForm.FormPointInViewPort.Y;
var formHeight = sliderForm.Size.Height;
browser.ScrollWindowBy(0, formHeight);
AqualityServices.Browser.ScrollWindowBy(0, formHeight);
Assert.LessOrEqual(Math.Abs(formHeight - (initialY - sliderForm.FormPointInViewPort.Y)), 1, "Window should be scrolled.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Elements;
using Aquality.Selenium.Tests.Integration.TestApp;
using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms;
using NUnit.Framework;
using System;
Expand Down Expand Up @@ -30,7 +28,7 @@ private static readonly Func<ElementState, ElementsCount, IList<Label>>[] Elemen
[SetUp]
public void BeforeTest()
{
AqualityServices.Browser.GoTo(Constants.UrlAutomationPractice);
OpenAutomationPracticeSite();
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Aquality.Selenium.Core.Elements;
using Aquality.Selenium.Elements.Interfaces;
using Aquality.Selenium.Forms;
using Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Helpers;
using OpenQA.Selenium;

namespace Aquality.Selenium.Tests.Integration.TestApp.AutomationPractice.Forms
Expand All @@ -26,8 +27,7 @@ public ProductListForm() : base(By.XPath(FormLocator), "Product list")

public void NavigateToLastProduct()
{
AqualityServices.Browser.GoTo(GetLastProduct().Href);
AqualityServices.Browser.WaitForPageToLoad();
SiteLoader.OpenAutomationPracticeSite(GetLastProduct().Href);
}

public ILink GetLastProduct()
Expand Down
Loading