Skip to content

Commit 6e369fc

Browse files
committed
Addressing PR comments
1 parent 7b7e203 commit 6e369fc

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

UiTests/Common/UiTestHelpers.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ namespace Common
1515
public static class UiTestHelpers
1616
{
1717
/// <summary>
18-
/// Navigates to a web page with retry logic to ensure establish a connection in case a web app needs more startup time.
18+
/// Navigates to a web page with retry logic to more reliably connect in case a web app needs more startup time.
1919
/// </summary>
2020
/// <param name="uri">The uri to navigate to</param>
2121
/// <param name="page">A page in a playwright browser</param>
22-
/// <returns></returns>
2322
public static async Task NavigateToWebApp(string uri, IPage page)
2423
{
2524
uint InitialConnectionRetryCount = 5;
@@ -124,13 +123,13 @@ public static async Task EnterPasswordAsync(IPage page, string password, ITestOu
124123
await FillEntryBox(passwordInputLocator, password);
125124
}
126125

127-
public static async Task StaySignedIn_MicrosoftIdFlow(IPage page, string staySignedInText, ITestOutputHelper? output = null)
126+
private static async Task StaySignedIn_MicrosoftIdFlow(IPage page, string staySignedInText, ITestOutputHelper? output = null)
128127
{
129128
WriteLine(output, $"Logging in ... Clicking {staySignedInText} on whether the browser should stay signed in.");
130129
await page.GetByRole(AriaRole.Button, new() { Name = staySignedInText }).ClickAsync();
131130
}
132131

133-
public static async Task FillEntryBox(ILocator entryBox, string entryText)
132+
private static async Task FillEntryBox(ILocator entryBox, string entryText)
134133
{
135134
await entryBox.ClickAsync();
136135
await entryBox.FillAsync(entryText);
@@ -269,6 +268,10 @@ public static string GetTracePath(string testAssemblyLocation, string traceName)
269268
);
270269
}
271270

271+
/// <summary>
272+
/// Goes through all processes and ends them and any child processes they spawned
273+
/// </summary>
274+
/// <param name="processes"></param>
272275
public static void EndProcesses(Dictionary<string, Process>? processes)
273276
{
274277
Queue<Process> processQueue = new();
@@ -286,7 +289,7 @@ public static void EndProcesses(Dictionary<string, Process>? processes)
286289
/// Kills the processes in the queue and all of their children
287290
/// </summary>
288291
/// <param name="processQueue">queue of parent processes</param>
289-
public static void KillProcessTrees(Queue<Process> processQueue)
292+
private static void KillProcessTrees(Queue<Process> processQueue)
290293
{
291294
#if WINDOWS
292295
Process currentProcess;
@@ -381,6 +384,13 @@ internal static async Task<string> GetValueFromKeyvaultWitDefaultCreds(Uri keyva
381384
return (await client.GetSecretAsync(keyvaultSecretName)).Value.Value;
382385
}
383386

387+
/// <summary>
388+
/// Starts all processes in the given list and verifies that they are running
389+
/// </summary>
390+
/// <param name="processDataEntries">The startup options for each process to be started</param>
391+
/// <param name="processes">A dictionary to hold the process objects once started</param>
392+
/// <param name="numRetries">The number of times to retry starting a process</param>
393+
/// <returns>A boolean to say whether all the processes were able to start up successfully</returns>
384394
public static bool StartAndVerifyProcessesAreRunning(List<ProcessStartOptions> processDataEntries, out Dictionary<string, Process> processes, uint numRetries)
385395
{
386396
processes = new Dictionary<string, Process>();
@@ -469,9 +479,17 @@ private static void SwapFiles(string path1, string path2)
469479

470480
// Write the contents of file2 to file1
471481
File.WriteAllText(path1, file2Contents);
472-
473-
// Write the contents of file1 to file2
474-
File.WriteAllText(path2, file1Contents);
482+
try
483+
{
484+
// Write the contents of file1 to file2
485+
File.WriteAllText(path2, file1Contents);
486+
}
487+
catch (Exception)
488+
{
489+
// If the second write fails, revert the first write
490+
File.WriteAllText(path1, file1Contents);
491+
throw;
492+
}
475493

476494
Console.WriteLine("File contents swapped successfully.");
477495
}
@@ -547,6 +565,9 @@ public void Dispose()
547565
}
548566
}
549567

568+
/// <summary>
569+
/// A POCO class to hold the options for starting a process
570+
/// </summary>
550571
public class ProcessStartOptions
551572
{
552573
public string TestAssemblyLocation { get; }

0 commit comments

Comments
 (0)