Skip to content

Commit

Permalink
Wrap ExecuteScript with ActionsRetrier (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
paveliam authored Apr 14, 2020
1 parent 075c2da commit 5e51545
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Aquality.Selenium.Browsers;
using Aquality.Selenium.Configurations;
using Aquality.Selenium.Core.Localization;
using Aquality.Selenium.Core.Utilities;
using Aquality.Selenium.Elements.Interfaces;

namespace Aquality.Selenium.Elements.Actions
Expand All @@ -29,6 +30,8 @@ public JsActions(IElement element, string elementType, ILocalizedLogger logger,

private Browser Browser => AqualityServices.Browser;

private IElementActionRetrier ActionRetrier => AqualityServices.Get<IElementActionRetrier>();

protected ILocalizedLogger Logger { get; }

/// <summary>
Expand Down Expand Up @@ -157,18 +160,20 @@ public string GetXPath()
/// <returns>Point object.</returns>
public Point GetViewPortCoordinates()
{
var coordinates = ExecuteScript<IList<object>>(JavaScript.GetViewPortCoordinates).Select(item => double.Parse(item.ToString())).ToArray();
var coordinates = ExecuteScript<IList<object>>(JavaScript.GetViewPortCoordinates)
.Select(item => double.Parse(item.ToString()))
.ToArray();
return new Point((int)Math.Round(coordinates[0]), (int)Math.Round(coordinates[1]));
}

protected T ExecuteScript<T>(JavaScript scriptName, params object[] arguments)
{
return Browser.ExecuteScript<T>(scriptName, ResolveArguments(arguments));
return ActionRetrier.DoWithRetry(() => Browser.ExecuteScript<T>(scriptName, ResolveArguments(arguments)));
}

protected void ExecuteScript(JavaScript scriptName, params object[] arguments)
{
Browser.ExecuteScript(scriptName, ResolveArguments(arguments));
ActionRetrier.DoWithRetry(() => Browser.ExecuteScript(scriptName, ResolveArguments(arguments)));
}

protected internal void LogElementAction(string messageKey, params object[] args)
Expand Down

0 comments on commit 5e51545

Please sign in to comment.