-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b86a81f
commit 78d1a9c
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
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
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
100 changes: 100 additions & 0 deletions
100
src/Yapoml.Selenium/Components/Conditions/ValueConditions.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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using OpenQA.Selenium; | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using Yapoml.Framework.Logging; | ||
using Yapoml.Selenium.Components.Conditions.Generic; | ||
using Yapoml.Selenium.Services.Locator; | ||
|
||
namespace Yapoml.Selenium.Components.Conditions | ||
{ | ||
public class ValueConditions<TConditions> : TextualConditions<TConditions> | ||
{ | ||
private IElementHandler _elementHandler; | ||
|
||
public ValueConditions(TConditions conditions, IElementHandler elementHandler, TimeSpan timeout, TimeSpan pollingInterval, string subject, ILogger logger) | ||
: base(conditions, timeout, pollingInterval, subject, logger) | ||
{ | ||
_elementHandler = elementHandler; | ||
} | ||
|
||
public override NumericConditions<TConditions, int> Length => new TextualLengthConditons<TConditions>(_conditions, _timeout, _pollingInterval, FetchValueFunc, $"value of {_elementHandler.ComponentMetadata.Name}", _logger); | ||
|
||
protected override Func<string> FetchValueFunc => () => RelocateOnStaleReference(() => _elementHandler.Locate().GetAttribute("value")); | ||
|
||
protected override string GetIsError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value of the {_elementHandler.ComponentMetadata.Name} is not '{expectedValue}',{GetDifference("it was:", expectedValue, latestValue)}"; | ||
} | ||
|
||
protected override string GetIsNotError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value of the {_elementHandler.ComponentMetadata.Name} is '{latestValue}', when expected to be not."; | ||
} | ||
|
||
protected override string GetIsEmptyError(string latestValue) | ||
{ | ||
return $"StValueyle '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} is not empty, when expected to be empty."; | ||
} | ||
|
||
protected override string GetIsNotEmptyError(string latestValue) | ||
{ | ||
return $"Value of the {_elementHandler.ComponentMetadata.Name} is empty, when expected to be not empty."; | ||
} | ||
|
||
protected override string GetStartsWithError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component does not start with '{expectedValue}' yet."; | ||
} | ||
|
||
protected override string GetDoesNotStartWithError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component starts with '{expectedValue}'."; | ||
} | ||
|
||
protected override string GetEndsWithError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component doesn't end with '{expectedValue}'."; | ||
} | ||
|
||
protected override string GetDoesNotEndWithError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component ends with '{expectedValue}'."; | ||
} | ||
|
||
protected override string GetContainsError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component doesn't contain '{expectedValue}' yet."; | ||
} | ||
|
||
protected override string GetDoesNotContainError(string latestValue, string expectedValue) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component contains '{expectedValue}'."; | ||
} | ||
|
||
protected override string GetMatchesError(string latestValue, Regex regex) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component doesn't match '{regex}'."; | ||
} | ||
|
||
protected override string GetDoesNotMatchError(string latestValue, Regex regex) | ||
{ | ||
return $"Value '{latestValue}' of the {_elementHandler.ComponentMetadata.Name} component matches '{regex}'."; | ||
} | ||
|
||
private T RelocateOnStaleReference<T>(Func<T> act) | ||
{ | ||
try | ||
{ | ||
return act(); | ||
} | ||
catch (StaleElementReferenceException) | ||
{ | ||
_elementHandler.Invalidate(); | ||
|
||
_elementHandler.Locate(); | ||
|
||
return act(); | ||
} | ||
} | ||
} | ||
} |