Skip to content

Minor cleanup #804

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

Merged
merged 2 commits into from
Nov 7, 2024
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
17 changes: 8 additions & 9 deletions UiTests/AnyOrgOrPersonalUiTest/AnyOrgOrPersonalTest.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Common;
using Microsoft.Identity.Lab.Api;
using Microsoft.Playwright;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Common;
using Microsoft.Identity.Lab.Api;
using Microsoft.Playwright;
using Xunit;
using Xunit.Abstractions;
using Process = System.Diagnostics.Process;
using TC = Common.TestConstants;

namespace MultipleApiUiTest
namespace AnyOrgOrPersonalUiTest
{
public class AnyOrgOrPersonalTest : IClassFixture<InstallPlaywrightBrowserFixture>
{
private const string SignOutPageUriPath = @"/MicrosoftIdentity/Account/SignedOut";
private const uint ClientPort = 44321;
private const string TraceFileClassName = "OpenIDConnect";
private const string TraceFileClassName = "AnyOrgOrPersonal";
private const uint NumProcessRetries = 3;
private const string SampleSlnFileName = "1-3-AnyOrgOrPersonal.sln";
private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new() { Timeout = 25000 };
private readonly string _sampleAppPath = "1-WebApp-OIDC" + Path.DirectorySeparatorChar + "1-3-AnyOrgOrPersonal" + Path.DirectorySeparatorChar.ToString();
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "AnyOrgOrPersonalUiTest" + Path.DirectorySeparatorChar.ToString() + TC.AppSetttingsDotJson;
private readonly string _sampleAppPath = "1-WebApp-OIDC" + Path.DirectorySeparatorChar + "1-3-AnyOrgOrPersonal" + Path.DirectorySeparatorChar;
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "AnyOrgOrPersonalUiTest" + Path.DirectorySeparatorChar + TC.AppSetttingsDotJson;
private readonly string _testAssemblyLocation = typeof(AnyOrgOrPersonalTest).Assembly.Location;
private readonly ITestOutputHelper _output;

Expand All @@ -38,7 +37,7 @@ public AnyOrgOrPersonalTest(ITestOutputHelper output)

[Fact]
[SupportedOSPlatform("windows")]
public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds_LoginLogout()
public async Task LocalApp_ValidEmailPasswordCreds_LoginLogout()
{
// Setup web app and api environmental variables.
var clientEnvVars = new Dictionary<string, string>
Expand Down
4 changes: 2 additions & 2 deletions UiTests/B2CUiTest/B2CUiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class B2CUiTest : IClassFixture<InstallPlaywrightBrowserFixture>
private const string SampleSolutionFileName = "4-2-B2C-Secured-API.sln";
private const uint TodoListClientPort = 5000;
private const uint TodoListServicePort = 44332;
private const string TraceClassName = "B2C-Login";
private const string TraceClassName = "B2C";

private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new() { Timeout = 25000 };
private readonly string _sampleClientAppPath;
Expand All @@ -46,7 +46,7 @@ public B2CUiTest(ITestOutputHelper output)

[Fact]
[SupportedOSPlatform("windows")]
public async Task B2C_ValidCreds_LoginLogout()
public async Task LocalApp_ValidEmailPasswordCreds_LoginLogout()
{
// Web app and api environmental variable setup.
Dictionary<string, Process>? processes = null;
Expand Down
12 changes: 6 additions & 6 deletions UiTests/Common/TestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public static class TestConstants
public const string TodoTitle2 = "Testing edit todo item";
public const string WebAppCrashedString = $"The web app process has exited prematurely.";

public static readonly string s_oidcWebAppExe = Path.DirectorySeparatorChar.ToString() + "WebApp-OpenIDConnect-DotNet.exe";
public static readonly string s_oidcWebAppPath = Path.DirectorySeparatorChar.ToString() + "WebApp-OpenIDConnect";
public static readonly string s_todoListClientExe = Path.DirectorySeparatorChar.ToString() + "TodoListClient.exe";
public static readonly string s_todoListClientPath = Path.DirectorySeparatorChar.ToString() + "Client";
public static readonly string s_todoListServiceExe = Path.DirectorySeparatorChar.ToString() + "TodoListService.exe";
public static readonly string s_todoListServicePath = Path.DirectorySeparatorChar.ToString() + "TodoListService";
public static readonly string s_oidcWebAppExe = Path.DirectorySeparatorChar + "WebApp-OpenIDConnect-DotNet.exe";
public static readonly string s_oidcWebAppPath = Path.DirectorySeparatorChar + "WebApp-OpenIDConnect";
public static readonly string s_todoListClientExe = Path.DirectorySeparatorChar + "TodoListClient.exe";
public static readonly string s_todoListClientPath = Path.DirectorySeparatorChar + "Client";
public static readonly string s_todoListServiceExe = Path.DirectorySeparatorChar + "TodoListService.exe";
public static readonly string s_todoListServicePath = Path.DirectorySeparatorChar + "TodoListService";
}
}
57 changes: 2 additions & 55 deletions UiTests/Common/UiTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Microsoft.Data.SqlClient;
using Microsoft.Playwright;
using System.Diagnostics;
using System.Management;
using System.Runtime.Versioning;
using System.Text;
using Xunit.Abstractions;

Expand Down Expand Up @@ -56,24 +54,6 @@ public static async Task FirstLogin_MicrosoftIdFlow_ValidEmailPassword(IPage pag
await StaySignedIn_MicrosoftIdFlow(page, staySignedInText, output);
}

/// <summary>
/// Login flow for anytime after the first time in a given browsing session.
/// </summary>
/// <param name="page">Playwright Page object the web app is accessed from</param>
/// <param name="email">email of the user to sign in</param>
/// <param name="password">password for sign in</param>
/// <param name="output">Used to communicate output to the test's Standard Output</param>
/// <param name="staySignedIn">Whether to select "stay signed in" on login</param>
public static async Task SuccessiveLogin_MicrosoftIdFlow_ValidEmailPassword(IPage page, string email, string password, ITestOutputHelper? output = null, bool staySignedIn = false)
{
string staySignedInText = staySignedIn ? "Yes" : "No";

WriteLine(output, $"Logging in again in this browsing session... selecting user via email: {email}.");
await SelectKnownAccountByEmail_MicrosoftIdFlow(page, email);
await EnterPasswordAsync(page, password, output);
await StaySignedIn_MicrosoftIdFlow(page, staySignedInText, output);
}

/// <summary>
/// Enters the email of the user to sign in.
/// </summary>
Expand Down Expand Up @@ -155,21 +135,6 @@ private static void WriteLine(ITestOutputHelper? output, string message)
}
}

/// <summary>
/// This starts the recording of playwright trace files. The corresponding EndAndWritePlaywrightTrace method will also need to be used.
/// This is not used anywhere by default and will need to be added to the code if desired.
/// </summary>
/// <param name="page">The page object whose context the trace will record.</param>
public static async Task StartPlaywrightTrace(IPage page)
{
await page.Context.Tracing.StartAsync(new()
{
Screenshots = true,
Snapshots = true,
Sources = true
});
}

/// <summary>
/// Starts a process from an executable, sets its working directory, and redirects its output to the test's output.
/// </summary>
Expand All @@ -179,7 +144,7 @@ await page.Context.Tracing.StartAsync(new()
/// <param name="portNumber">The port for the process to listen on.</param>
/// <param name="isHttp">If the launch URL is http or https. Default is https.</param>
/// <returns>The started process.</returns>
public static Process StartProcessLocally(string testAssemblyLocation, string appLocation, string executableName, Dictionary<string, string>? environmentVariables = null)
private static Process StartProcessLocally(string testAssemblyLocation, string appLocation, string executableName, Dictionary<string, string>? environmentVariables = null)
{
string applicationWorkingDirectory = GetApplicationWorkingDirectory(testAssemblyLocation, appLocation);
ProcessStartInfo processStartInfo = new ProcessStartInfo(applicationWorkingDirectory + executableName)
Expand Down Expand Up @@ -258,7 +223,7 @@ private static string GetAbsoluteAppDirectory(string testAssemblyLocation, strin
/// <returns>An absolute path to a Playwright Trace zip folder</returns>
public static string GetTracePath(string testAssemblyLocation, string traceName)
{
const string traceParentFolder = "E2E Tests";
const string traceParentFolder = "UiTests";
const string traceFolder = "PlaywrightTraces";
const string zipExtension = ".zip";
const int netVersionNumberLength = 3;
Expand Down Expand Up @@ -323,24 +288,6 @@ private static void KillProcessTrees(Queue<Process> processQueue)
#endif
}

/// <summary>
/// Gets the child processes of a process on Windows
/// </summary>
/// <param name="process">The parent process</param>
/// <returns>A list of child processes</returns>
[SupportedOSPlatform("windows")]
public static IList<Process> GetChildProcesses(this Process process)
{
ManagementObjectSearcher processSearch = new ManagementObjectSearcher($"Select * From Win32_Process Where ParentProcessID={process.Id}");
IList<Process> processList = processSearch.Get()
.Cast<ManagementObject>()
.Select(mo =>
Process.GetProcessById(Convert.ToInt32(mo["ProcessID"], System.Globalization.CultureInfo.InvariantCulture)))
.ToList();
processSearch.Dispose();
return processList;
}

/// <summary>
/// Checks if all processes in a list are alive
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions UiTests/GraphUserTokenCache/GraphUserTokenCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class GraphUserTokenCacheTest
private const string SqlDbName = "MY_TOKEN_CACHE_DATABASE";
private const string SqlServerConnectionString = "Server=(localdb)\\mssqllocaldb;Integrated Security=true";
private const string SqlTableName = "TokenCache";
private const string TraceFileClassName = "GraphUserTokenCacheTest";
private const string TraceFileClassName = "GraphUserTokenCache";
private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new() { Timeout = 25000 };
private readonly ITestOutputHelper _output;
private readonly string _sampleAppPath = "2-WebApp-graph-user" + Path.DirectorySeparatorChar + "2-2-TokenCache" + Path.DirectorySeparatorChar.ToString();
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "GraphUserTokenCache" + Path.DirectorySeparatorChar.ToString() + TC.AppSetttingsDotJson;
private readonly string _sampleAppPath = "2-WebApp-graph-user" + Path.DirectorySeparatorChar + "2-2-TokenCache" + Path.DirectorySeparatorChar;
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "GraphUserTokenCache" + Path.DirectorySeparatorChar + TC.AppSetttingsDotJson;
private readonly string _testAssemblyLocation = typeof(GraphUserTokenCacheTest).Assembly.Location;

public GraphUserTokenCacheTest(ITestOutputHelper output)
Expand All @@ -35,7 +35,7 @@ public GraphUserTokenCacheTest(ITestOutputHelper output)
}

[Fact]
public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds_LoginLogoutAsync()
public async Task LocalApp_ValidEmailPasswordCreds_LoginLogout()
{
// Setup web app and api environmental variables.
var clientEnvVars = new Dictionary<string, string>
Expand Down
10 changes: 5 additions & 5 deletions UiTests/HybridFlowUiTest/HybridFlowTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class HybridFlowTest : IClassFixture<InstallPlaywrightBrowserFixture>
{
private const string SignOutPageUriPath = @"/MicrosoftIdentity/Account/SignedOut";
private const uint ClientPort = 44321;
private const string TraceFileClassName = "OpenIDConnect-HybridFlow";
private const string TraceFileClassName = "HybridFlow";
private const uint NumProcessRetries = 3;
private const string SampleSlnFileName = "2-5-HybridFlow.sln";
private const string SampleExeFileName = "2-5-HybridFlow.exe";
private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new() { Timeout = 25000 };
private readonly string _sampleAppPath = "2-WebApp-graph-user" + Path.DirectorySeparatorChar + "2-5-HybridFlow" + Path.DirectorySeparatorChar.ToString();
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "HybridFlowUiTest" + Path.DirectorySeparatorChar.ToString() + TC.AppSetttingsDotJson;
private readonly string _sampleAppPath = "2-WebApp-graph-user" + Path.DirectorySeparatorChar + "2-5-HybridFlow" + Path.DirectorySeparatorChar;
private readonly string _testAppsettingsPath = "UiTests" + Path.DirectorySeparatorChar + "HybridFlowUiTest" + Path.DirectorySeparatorChar + TC.AppSetttingsDotJson;
private readonly string _testAssemblyLocation = typeof(HybridFlowTest).Assembly.Location;
private readonly ITestOutputHelper _output;

Expand All @@ -38,7 +38,7 @@ public HybridFlowTest(ITestOutputHelper output)

[Fact]
[SupportedOSPlatform("windows")]
public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds_LoginLogout()
public async Task LocalApp_ValidEmailPasswordCreds_LoginLogout()
{
// Setup web app and api environmental variables.
var clientEnvVars = new Dictionary<string, string>
Expand Down Expand Up @@ -68,7 +68,7 @@ public async Task ChallengeUser_MicrosoftIdFlow_LocalApp_ValidEmailPasswordCreds
var clientProcessOptions = new ProcessStartOptions(
_testAssemblyLocation,
_sampleAppPath,
Path.DirectorySeparatorChar.ToString() + SampleExeFileName,
Path.DirectorySeparatorChar + SampleExeFileName,
clientEnvVars
);

Expand Down
4 changes: 4 additions & 0 deletions UiTests/PlaywrightTraces/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore all files in this directory, which is needed for PR pipeline test traces
*
# Except this file
!.gitignore
Loading