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

Smart sync Action Playwright support #4044

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using GingerCore.Actions;
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
using GingerCore.Drivers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace Amdocs.Ginger.CoreNET.Drivers.CoreDrivers.Web.ActionHandlers
{
internal class ActSmartSyncHandler
{
private ActSmartSync _actSmartSync;
private IBrowserTab _browserTab;
private IBrowserElementLocator _elementLocator;
private Act mAct;

internal ActSmartSyncHandler(ActSmartSync actSmartSync, IBrowserTab browserTab, IBrowserElementLocator elementLocator)
{
_actSmartSync = actSmartSync;
_browserTab = browserTab;
_elementLocator = elementLocator;
}
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Handles the smart synchronization action asynchronously.
/// </summary>
/// <param name="act">The action to be handled.</param>
/// <returns>A task representing the asynchronous operation.</returns>
internal async Task HandleAsync(Act act)
{
mAct = act;

int MaxTimeout = DriverBase.GetMaxTimeout(_actSmartSync);
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
Stopwatch st = new Stopwatch();
try
{
st.Start();
IBrowserElement element;

switch (_actSmartSync.SmartSyncAction)
{
case ActSmartSync.eSmartSyncAction.WaitUntilDisplay:
do
{
if (st.ElapsedMilliseconds > MaxTimeout * 1000)
{
mAct.Error = "Smart Sync of WaitUntilDisplay is timeout";
break;
}
await Task.Delay(100);
element = await GetFirstMatchingElementAsync();
} while (element == null || !await element.IsVisibleAsync() || !await element.IsEnabledAsync());
break;

case ActSmartSync.eSmartSyncAction.WaitUntilDisapear:
do
{
if (st.ElapsedMilliseconds > MaxTimeout * 1000)
{
mAct.Error = "Smart Sync of WaitUntilDisapear is timeout";
break;
}
await Task.Delay(100);
element = await GetFirstMatchingElementAsync();
} while (element != null);
break;
}

}
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
finally
{
st.Stop();
}
}
/// <summary>
/// Gets the first matching browser element asynchronously.
/// </summary>
/// <returns>The first matching browser element.</returns>
private async Task<IBrowserElement> GetFirstMatchingElementAsync()
{
IEnumerable<IBrowserElement> elements = await _elementLocator.FindMatchingElements(mAct.LocateBy, mAct.LocateValue);
IBrowserElement? firstElement = elements.FirstOrDefault();
return firstElement;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ public override void RunAction(Act act)
}
actAccessibilityTestingHandler.HandleAsync().Wait();
break;
case ActSmartSync actSmartSync:
ActSmartSyncHandler actSmartSyncHandler = new(
actSmartSync,
_browser.CurrentWindow.CurrentTab,
new BrowserElementLocator(
_browser.CurrentWindow.CurrentTab,
new()
{
BusinessFlow = BusinessFlow,
Environment = Environment,
POMExecutionUtils = new POMExecutionUtils(act, act.LocateValue),
Agent = BusinessFlow.CurrentActivity.CurrentAgent,
}));
actSmartSyncHandler.HandleAsync(act).Wait();
break;
default:
act.Error = $"This Action is not supported for Playwright driver";
break;
Expand All @@ -262,7 +277,7 @@ public bool IsActionSupported(Act act, out string message)
{
message = string.Empty;

if (act is ActWithoutDriver or ActScreenShot or ActGotoURL or ActAccessibilityTesting)
if (act is ActWithoutDriver or ActScreenShot or ActGotoURL or ActAccessibilityTesting or ActSmartSync)
{
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions Ginger/GingerCoreNET/RunLib/DriverBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ public virtual double ScreenShotInitialZoom()
return 0.5;
}

Regex AttRegexWeb = new Regex("@[a-zA-Z]*", RegexOptions.Compiled);
Regex AttRegexMobile = new Regex("{[a-zA-Z]*}", RegexOptions.Compiled);
Regex AttRegexWeb = new("@[a-zA-Z]*", RegexOptions.Compiled);
Regex AttRegexMobile = new("{[a-zA-Z]*}", RegexOptions.Compiled);
public ElementLocator GetUserDefinedCustomLocatorFromTemplates(string locatorTemplate, eLocateBy locateBy, List<ControlProperty> elementProperties)
{
try
Expand Down Expand Up @@ -379,7 +379,7 @@ public ElementLocator GetUserDefinedCustomLocatorFromTemplates(string locatorTem
}
}

protected static int GetMaxTimeout(ActSmartSync act)
public static int GetMaxTimeout(ActSmartSync act)
{
try
{
Expand Down
Loading