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

Browse File path Playwright support #4045

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -722,18 +722,30 @@ 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))
{
if (!string.IsNullOrEmpty(keys))
{
await element.SetFileValueAsync(keys.Split(',').Select(path => path.Replace("\"", "").Trim()).ToArray());
}
}
else
{
await element.ClearAsync();
Func<Task> elementOperation = ConvertSeleniumKeyIdentifierToElementOperation(keys, element);
await elementOperation();
}
}

/// <summary>
/// Converts a Selenium key identifier to the corresponding element operation.
/// Maps the key identifier to the appropriate key press action on the element.
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)
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
{
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);
}
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Loading