Skip to content

Commit

Permalink
Updated summery for all Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
prashelke committed Nov 28, 2024
1 parent b85f6ab commit 0393cdd
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ limitations under the License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
Expand Down Expand Up @@ -567,100 +568,130 @@ private async Task HandleSwitchToDefaultWindowOperationAsync()

await _browser.CurrentWindow.SetTabAsync(firstTab);
}

/// <summary>
/// This asynchronous method accepts a message box (such as a dialog box) in the current browser tab.
/// If an error occurs, it logs the error and updates the Error property.
/// </summary>
/// <returns></returns>
private async Task HandleAcceptMessageBoxOperationAsync()
{
try
{
await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).AcceptMessageBox();
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Accepting MessageBox.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
return;
}
}

/// <summary>
/// This asynchronous method dismisses a message box (closes it) in the current browser tab.
/// If an error occurs, it logs the error and updates the Error property.
/// </summary>
/// <returns></returns>
private async Task HandleDismissMessageBoxOperationAsync()
{
try
{
await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).DismissMessageBox();
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Dismiss MessageBox.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Dismiss MessageBox - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
return;
}
}
/// <summary>
/// This method retrieves the text of the message box from the current browser tab.
/// If an error occurs, it logs the error and returns an empty string.

/// </summary>
/// <returns></returns>
private string HandleGetMessageBoxTextOperation()
{
try
{
return ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).GetMessageBoxText();
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Get MessageBox Text.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Get MessageBox Text - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
return string.Empty;
}
}

/// <summary>
/// This asynchronous method sets the text of the message box in the current browser tab.
/// If an error occurs, it logs the error.
/// </summary>
/// <param name="MessageBoxText"></param>
/// <returns></returns>
private async Task HandleSetMessageBoxTextOperationAsync(string MessageBoxText)
{
try
{
await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).SetMessageBoxText(MessageBoxText);
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Set MessageBox Text.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Set MessageBox Text - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
}
}

/// <summary>
/// This asynchronous method starts monitoring and capturing network logs in the current browser tab. If an error occurs,
/// it logs the error and updates the Error property.
/// </summary>
/// <returns></returns>
private async Task HandleStartMonitoringNetworkLogOperationAsync()
{
try
{
await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StartCaptureNetworkLog(_act);
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Accepting MessageBox.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
return;
}
}

/// <summary>
/// This asynchronous method retrieves the captured network logs from the current browser tab.
/// If an error occurs, it logs the error and updates the Error property.
/// </summary>
/// <returns></returns>
private async Task HandleGetNetworkLogOperationAsync()
{
try
{
await ((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).GetCaptureNetworkLog(_act);
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Accepting MessageBox.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
return;
}
}

/// <summary>
/// This asynchronous method stops monitoring and capturing network logs in the current browser tab.
/// If an error occurs, it logs the error and updates the Error property.
/// </summary>
/// <returns></returns>
private async Task HandleStopMonitoringNetworkLogOperationAsync()
{
try
{
((PlaywrightBrowserTab)_browser!.CurrentWindow.CurrentTab).StopCaptureNetworkLog(_act);
}
catch (Exception e)
catch (Exception ex)
{
_act.Error = "Error when Accepting MessageBox.";
Reporter.ToLog(eLogLevel.ERROR, "Error when Accepting MessageBox - " + e.Message);
_act.Error = $"Error when {MethodBase.GetCurrentMethod().Name}.";
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,12 @@ public static bool IsFrameLocatorSupported(eLocateBy locateBy)
{
return SupportedFrameLocators.Contains(locateBy);
}

/// <summary>
/// This asynchronous method initiates the process of capturing network logs for the current page.
/// It sets up the necessary data structures and event handlers to monitor network requests and responses.
/// </summary>
/// <param name="act"></param>
/// <returns></returns>
public async Task StartCaptureNetworkLog(ActBrowserElement act)
{
try
Expand All @@ -643,7 +648,12 @@ await Task.Run(() =>
}

}

/// <summary>
/// This asynchronous method retrieves the captured network logs (requests and responses) for the current browser element and stores them in the act object.
/// It only performs the action if network log monitoring has been started.
/// </summary>
/// <param name="act"></param>
/// <returns></returns>
public async Task GetCaptureNetworkLog(ActBrowserElement act)
{
try
Expand Down Expand Up @@ -677,7 +687,11 @@ await Task.Run(() =>
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
}
}

/// <summary>
/// This asynchronous method stops the network log capture by unsubscribing from the network request and response events.
/// It then processes and stores the captured logs, saves them to files, and attaches the files as artifacts to the act object.
/// </summary>
/// <param name="act"></param>

public async void StopCaptureNetworkLog(ActBrowserElement act)

Check warning on line 696 in Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Playwright/PlaywrightBrowserTab.cs#L696

Return 'Task' instead.
{
Expand Down Expand Up @@ -719,8 +733,13 @@ await Task.Run(() =>

}



/// <summary>
/// This method handles the network request event, capturing the details of outgoing network requests.
/// It adds the request URL and its serialized data to the network log if the request matches the specified criteria.
/// </summary>
/// <param name="sender"></param>
/// <param name="request"></param>
private async void OnNetworkRequestSent(object? sender, IRequest request)
{
try
Expand All @@ -740,7 +759,12 @@ private async void OnNetworkRequestSent(object? sender, IRequest request)
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
}
}

/// <summary>
/// This method handles the network response event, capturing details about the response once it's received.
/// It checks if the response should be logged based on the configured criteria and adds relevant information to the network response log.
/// </summary>
/// <param name="sender"></param>
/// <param name="response"></param>
private async void OnNetworkResponseReceived(object? sender, IResponse response)
{
await response.FinishedAsync();
Expand Down Expand Up @@ -798,7 +822,10 @@ await Task.Run(() => {
Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
}
}

/// <summary>
/// This asynchronous method accepts (clicks the "OK" or equivalent) on a message box or dialog.
/// </summary>
/// <returns></returns>
public async Task AcceptMessageBox()
{
try
Expand All @@ -811,7 +838,10 @@ public async Task AcceptMessageBox()
}

}

/// <summary>
/// This asynchronous method dismisses (closes or cancels) a message box or dialog.
/// </summary>
/// <returns></returns>
public async Task DismissMessageBox()
{
try
Expand All @@ -825,7 +855,10 @@ public async Task DismissMessageBox()
}

}

/// <summary>
/// This method retrieves the text content of the current message box or dialog.
/// </summary>
/// <returns></returns>
public string GetMessageBoxText()
{
try
Expand All @@ -839,7 +872,11 @@ public string GetMessageBoxText()
}

}

/// <summary>
/// This asynchronous method sets the text (usually for a prompt dialog) in the message box.
/// </summary>
/// <param name="MessageBoxText"></param>
/// <returns></returns>
public async Task SetMessageBoxText(string MessageBoxText)
{
try
Expand Down

0 comments on commit 0393cdd

Please sign in to comment.