Skip to content

Commit 95d6a61

Browse files
authored
Add ability to compare visual state of form with pre-saved dump (#90) +semver: feature
* created form interface and implementation * implemented DumpManager to save the dump and compare with it * moved VisualStateProvider to Visualization namespace * moved LogElementState delegates to Logging namespace
1 parent b1447fd commit 95d6a61

File tree

21 files changed

+651
-50
lines changed

21 files changed

+651
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ msbuild.wrn
3737
.vs/
3838

3939
Log/
40+
VisualDumps/

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml

Lines changed: 128 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Configurations/IVisualizationConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ public interface IVisualizationConfiguration
1919
/// Height of the image resized for comparison.
2020
/// </summary>
2121
int ComparisonHeight { get; }
22+
23+
/// <summary>
24+
/// Path used to save and load page dumps.
25+
/// </summary>
26+
string PathToDumps { get; }
2227
}
2328
}

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Configurations/VisualizationConfiguration.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Aquality.Selenium.Core.Utilities;
2+
using System.IO;
23

34
namespace Aquality.Selenium.Core.Configurations
45
{
@@ -24,5 +25,14 @@ public VisualizationConfiguration(ISettingsFile settingsFile)
2425
public int ComparisonWidth => settingsFile.GetValueOrDefault(".visualization.comparisonWidth", 16);
2526

2627
public int ComparisonHeight => settingsFile.GetValueOrDefault(".visualization.comparisonHeight", 16);
28+
29+
public string PathToDumps
30+
{
31+
get
32+
{
33+
var pathInConfiguration = settingsFile.GetValueOrDefault(".visualization.pathToDumps", "../../../Resources/VisualDumps/");
34+
return pathInConfiguration.Contains(".") ? Path.GetFullPath(pathInConfiguration) : pathInConfiguration;
35+
}
36+
}
2737
}
2838
}

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/CachedElementStateProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Aquality.Selenium.Core.Elements.Interfaces;
2+
using Aquality.Selenium.Core.Logging;
23
using Aquality.Selenium.Core.Waitings;
34
using OpenQA.Selenium;
45
using System;

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/Element.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Aquality.Selenium.Core.Elements
1818
/// </summary>
1919
public abstract class Element : IElement
2020
{
21-
private readonly ElementState elementState;
21+
internal readonly ElementState elementState;
2222
private IElementCacheHandler elementCacheHandler;
2323

2424
protected Element(By locator, string name, ElementState state)

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementStateProvider.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Aquality.Selenium.Core.Elements.Interfaces;
2+
using Aquality.Selenium.Core.Logging;
23
using Aquality.Selenium.Core.Waitings;
34
using OpenQA.Selenium;
45
using System;
@@ -33,22 +34,22 @@ public ElementStateProvider(By elementLocator, IConditionalWait conditionalWait,
3334

3435
public bool WaitForDisplayed(TimeSpan? timeout = null)
3536
{
36-
return DoAndLogWaitForState(() => IsAnyElementFound(timeout, ElementState.Displayed), "displayed");
37+
return DoAndLogWaitForState(() => IsAnyElementFound(timeout, ElementState.Displayed), "displayed", timeout);
3738
}
3839

3940
public bool WaitForNotDisplayed(TimeSpan? timeout = null)
4041
{
41-
return DoAndLogWaitForState(() => ConditionalWait.WaitFor(() => !IsDisplayed, timeout), "not.displayed");
42+
return DoAndLogWaitForState(() => ConditionalWait.WaitFor(() => !IsDisplayed, timeout), "not.displayed", timeout);
4243
}
4344

4445
public bool WaitForExist(TimeSpan? timeout = null)
4546
{
46-
return DoAndLogWaitForState(() => IsAnyElementFound(timeout, ElementState.ExistsInAnyState), "exist");
47+
return DoAndLogWaitForState(() => IsAnyElementFound(timeout, ElementState.ExistsInAnyState), "exist", timeout);
4748
}
4849

4950
public bool WaitForNotExist(TimeSpan? timeout = null)
5051
{
51-
return DoAndLogWaitForState(() => ConditionalWait.WaitFor(() => !IsExist, timeout), "not.exist");
52+
return DoAndLogWaitForState(() => ConditionalWait.WaitFor(() => !IsExist, timeout), "not.exist", timeout);
5253
}
5354

5455
private bool IsAnyElementFound(TimeSpan? timeout, ElementState state)
@@ -58,12 +59,12 @@ private bool IsAnyElementFound(TimeSpan? timeout, ElementState state)
5859

5960
public bool WaitForEnabled(TimeSpan? timeout = null)
6061
{
61-
return DoAndLogWaitForState(() => IsElementInDesiredState(element => IsElementEnabled(element), "ENABLED", timeout), "enabled");
62+
return DoAndLogWaitForState(() => IsElementInDesiredState(element => IsElementEnabled(element), "ENABLED", timeout), "enabled", timeout);
6263
}
6364

6465
public bool WaitForNotEnabled(TimeSpan? timeout = null)
6566
{
66-
return DoAndLogWaitForState(() => IsElementInDesiredState(element => !IsElementEnabled(element), "NOT ENABLED", timeout), "not.enabled");
67+
return DoAndLogWaitForState(() => IsElementInDesiredState(element => !IsElementEnabled(element), "NOT ENABLED", timeout), "not.enabled", timeout);
6768
}
6869

6970
protected virtual bool IsElementEnabled(IWebElement element)

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/Interfaces/IElement.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OpenQA.Selenium;
1+
using Aquality.Selenium.Core.Visualization;
2+
using OpenQA.Selenium;
23
using OpenQA.Selenium.Remote;
34
using System;
45

@@ -27,6 +28,11 @@ public interface IElement : IParent
2728
/// <value>Instance of <see cref="IElementStateProvider"/></value>
2829
IElementStateProvider State { get; }
2930

31+
/// <summary>
32+
/// Gets element visual state.
33+
/// </summary>
34+
IVisualStateProvider Visual { get; }
35+
3036
/// <summary>
3137
/// Finds current element by specified <see cref="Locator"/>
3238
/// </summary>
@@ -43,7 +49,7 @@ public interface IElement : IParent
4349
/// <summary>
4450
/// Gets element attribute value by its name.
4551
/// </summary>
46-
/// <param name="attr">Name of attrbiute</param>
52+
/// <param name="attr">Name of attribute</param>
4753
/// <returns>Value of element attribute.</returns>
4854
string GetAttribute(string attr);
4955

0 commit comments

Comments
 (0)