Skip to content

Commit

Permalink
Browse File path Playwright support
Browse files Browse the repository at this point in the history
  • Loading branch information
GokulBothe99 committed Dec 30, 2024
1 parent a7e26aa commit fc1b41c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,26 @@ private async Task HandleGetFontAsync()


/// <summary>
/// Handles sending keys to a browser element.
/// Retrieves the element, clears its current value, and sends the specified keys.
/// Handles sending keys to a browser element.
/// If the element is a file input, it sets the file value.
/// For other input types, it clears the current value and performs an operation based on the provided keys.
/// </summary>
private async Task HandleSendKeysAsync()
{
IBrowserElement element = await GetFirstMatchingElementAsync();
await element.ClearAsync();
string keys = _act.GetInputParamCalculatedValue("Value");
Func<Task> elementOperation = ConvertSeleniumKeyIdentifierToElementOperation(keys, element);
await elementOperation();
string tagName = await element.TagNameAsync();
string type = await element.AttributeValueAsync("type");
if (string.Equals(tagName, IBrowserElement.InputTagName, StringComparison.OrdinalIgnoreCase) && string.Equals(type, "file", StringComparison.OrdinalIgnoreCase))
{
await element.SetFileValueAsync(keys);
}
else
{
await element.ClearAsync();
Func<Task> elementOperation = ConvertSeleniumKeyIdentifierToElementOperation(keys, element);
await elementOperation();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ internal interface IBrowserElement
public Task<IBrowserShadowRoot?> ShadowRootAsync();

public Task<AxeResult?> TestAccessibilityAsync(AxeRunOptions? options = null);
public Task SetFileValueAsync(string value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1002,5 +1002,44 @@ private Task<bool> ShadowRootExists(IPlaywrightElementHandle playwrightElementHa

return await _playwrightLocator.RunAxe(options);
}

/// <summary>
/// Sets the file value using the appropriate Playwright locator or element handle.
/// </summary>
/// <param name="value">The file path to set.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public Task SetFileValueAsync(string value)
{
if (_playwrightLocator != null)
{
return SetFileValueAsync(_playwrightLocator, value);
}
else
{
return SetFileValueAsync(_playwrightElementHandle!, value);
}
}

/// <summary>
/// Sets the file value using a Playwright locator.
/// </summary>
/// <param name="playwrightLocator">The Playwright locator.</param>
/// <param name="value">The file path to set.</param>
/// <returns>A task representing the asynchronous operation.</returns>
private Task SetFileValueAsync(IPlaywrightLocator playwrightLocator, string value)
{
return playwrightLocator.SetInputFilesAsync(value);
}

/// <summary>
/// Sets the file value using a Playwright element handle.
/// </summary>
/// <param name="playwrightElementHandle">The Playwright element handle.</param>
/// <param name="value">The file path to set.</param>
/// <returns>A task representing the asynchronous operation.</returns>
private Task SetFileValueAsync(IPlaywrightElementHandle playwrightElementHandle, string value)
{
return playwrightElementHandle.SetInputFilesAsync(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public override WebBrowserType BrowserType
protected NgWebDriver ngDriver;
private String DefaultWindowHandler = null;

private Proxy mProxy = new Proxy();
private Proxy mProxy = new();

// FOr BMP - Browser Mob Proxy
Server BMPServer;
Expand Down Expand Up @@ -5575,7 +5575,7 @@ private void CreatePOMMetaData(ObservableList<ElementInfo> foundElementsList, Li
}
}

Regex AttRegex = new Regex("@[a-zA-Z]*", RegexOptions.Compiled);
Regex AttRegex = new("@[a-zA-Z]*", RegexOptions.Compiled);
private void CreateXpathFromUserTemplate(string xPathTemplate, HTMLElementInfo hTMLElement)
{
try
Expand Down Expand Up @@ -10934,31 +10934,31 @@ public async Task GetNetworkLogAsync(ActBrowserElement act)
{
try
{
if (isNetworkLogMonitoringStarted)
if (isNetworkLogMonitoringStarted)
{
act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList()));
act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList()));
foreach (var val in networkRequestLogList.ToList())
{
act.AddOrUpdateReturnParamActual("Raw Request", Newtonsoft.Json.JsonConvert.SerializeObject(networkRequestLogList.Select(x => x.Item2).ToList()));
act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList()));
foreach (var val in networkRequestLogList.ToList())
{
act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2));
}

foreach (var val in networkResponseLogList.ToList())
{
act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2));
}
act.AddOrUpdateReturnParamActual($"{act.ControlAction} {val.Item1}", Convert.ToString(val.Item2));
}
else

foreach (var val in networkResponseLogList.ToList())
{
act.ExInfo = $"Action is skipped,{nameof(ActBrowserElement.eControlAction.StartMonitoringNetworkLog)} Action is not started";
act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped;
act.AddOrUpdateReturnParamActual($"{act.ControlAction} {val.Item1}", Convert.ToString(val.Item2));
}
}
else
{
act.ExInfo = $"Action is skipped,{nameof(ActBrowserElement.eControlAction.StartMonitoringNetworkLog)} Action is not started";
act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Skipped;
}
}
catch(Exception ex)
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
}


}

Expand Down Expand Up @@ -11022,19 +11022,19 @@ public async Task StopMonitoringNetworkLog(ActBrowserElement act)
act.AddOrUpdateReturnParamActual("Raw Response", Newtonsoft.Json.JsonConvert.SerializeObject(networkResponseLogList.Select(x => x.Item2).ToList(), Formatting.Indented));
foreach (var val in networkRequestLogList.ToList())
{
act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString()} {val.Item1}", Convert.ToString(val.Item2));
act.AddOrUpdateReturnParamActual($"{act.ControlAction} {val.Item1}", Convert.ToString(val.Item2));
}
foreach (var val in networkResponseLogList.ToList())
{
act.AddOrUpdateReturnParamActual($"{act.ControlAction.ToString() } {val.Item1}", Convert.ToString(val.Item2));
act.AddOrUpdateReturnParamActual($"{act.ControlAction} {val.Item1}", Convert.ToString(val.Item2));
}

await devToolsDomains.Network.Disable(new OpenQA.Selenium.DevTools.V127.Network.DisableCommandSettings());
devToolsSession.Dispose();
devTools.CloseDevToolsSession();

string requestPath = _BrowserHelper.CreateNetworkLogFile("NetworklogRequest", networkRequestLogList);
act.ExInfo = $"RequestFile : { requestPath }\n";
act.ExInfo = $"RequestFile : {requestPath}\n";
string responsePath = _BrowserHelper.CreateNetworkLogFile("NetworklogResponse", networkResponseLogList);
act.ExInfo = $"{act.ExInfo} ResponseFile : {responsePath}\n";

Expand Down Expand Up @@ -11103,7 +11103,7 @@ private void OnNetworkRequestSent(object sender, NetworkRequestSentEventArgs e)
{
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
}
}
}


private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEventArgs e)
Expand All @@ -11123,7 +11123,7 @@ private void OnNetworkResponseReceived(object sender, NetworkResponseReceivedEve
}
else
{
networkResponseLogList.Add(new Tuple<string, object>($"ResponseUrl:{e.ResponseUrl}", JsonConvert.SerializeObject(e, Formatting.Indented)));
networkResponseLogList.Add(new Tuple<string, object>($"ResponseUrl:{e.ResponseUrl}", JsonConvert.SerializeObject(e, Formatting.Indented)));
}
}
}
Expand Down

0 comments on commit fc1b41c

Please sign in to comment.