18
18
namespace B2CUiTest
19
19
{
20
20
public class B2CUiTest : IClassFixture < InstallPlaywrightBrowserFixture >
21
- {
21
+ { // if some other app is listening on the port I want can I kick it off? Also, could I kill the process using the port or at least ID it?
22
22
private const string KeyvaultEmailName = "IdWeb-B2C-user" ;
23
23
private const string KeyvaultPasswordName = "IdWeb-B2C-password" ;
24
24
private const string KeyvaultClientSecretName = "IdWeb-B2C-Client-ClientSecret" ;
25
25
private const string NameOfUser = "unknown" ;
26
+ private const uint ProcessStartupRetryNum = 3 ;
26
27
private const uint TodoListClientPort = 5000 ;
27
28
private const uint TodoListServicePort = 44332 ;
28
29
private const string TraceClassName = "B2C-Login" ;
29
30
private readonly LocatorAssertionsToBeVisibleOptions _assertVisibleOptions = new ( ) { Timeout = 25000 } ;
30
- private readonly string _sampleAppPath = Path . Join ( "4-WebApp-your-API" , "4-2-B2C" ) ;
31
+ private readonly string _sampleClientAppPath = Path . Join ( "4-WebApp-your-API" , "4-2-B2C" , TC . s_todoListClientPath ) ;
32
+ private readonly string _sampleServiceAppPath = Path . Join ( "4-WebApp-your-API" , "4-2-B2C" , TC . s_todoListServicePath ) ;
31
33
private readonly Uri _keyvaultUri = new ( "https://webappsapistests.vault.azure.net" ) ;
32
34
private readonly ITestOutputHelper _output ;
33
- private readonly string _testAssemblyPath = typeof ( B2CUiTest ) . Assembly . Location ;
35
+ private readonly string _testAssemblyLocation = typeof ( B2CUiTest ) . Assembly . Location ;
34
36
35
37
public B2CUiTest ( ITestOutputHelper output )
36
38
{
@@ -42,6 +44,7 @@ public B2CUiTest(ITestOutputHelper output)
42
44
public async Task B2C_ValidCreds_LoginLogout ( )
43
45
{
44
46
// Web app and api environmental variable setup.
47
+ Dictionary < string , Process > ? processes = null ;
45
48
DefaultAzureCredential azureCred = new ( ) ;
46
49
string clientSecret = await UiTestHelpers . GetValueFromKeyvaultWitDefaultCreds ( _keyvaultUri , KeyvaultClientSecretName , azureCred ) ;
47
50
var serviceEnvVars = new Dictionary < string , string >
@@ -67,21 +70,14 @@ public async Task B2C_ValidCreds_LoginLogout()
67
70
IBrowserContext context = await browser . NewContextAsync ( new BrowserNewContextOptions { IgnoreHTTPSErrors = true } ) ;
68
71
await context . Tracing . StartAsync ( new ( ) { Screenshots = true , Snapshots = true , Sources = true } ) ;
69
72
70
- Process ? serviceProcess = null ;
71
- Process ? clientProcess = null ;
72
-
73
73
try
74
74
{
75
75
// Start the web app and api processes.
76
76
// The delay before starting client prevents transient devbox issue where the client fails to load the first time after rebuilding.
77
- serviceProcess = UiTestHelpers . StartProcessLocally ( _testAssemblyPath , _sampleAppPath + TC . s_todoListServicePath , TC . s_todoListServiceExe , serviceEnvVars ) ;
78
- await Task . Delay ( 3000 ) ;
79
- clientProcess = UiTestHelpers . StartProcessLocally ( _testAssemblyPath , _sampleAppPath + TC . s_todoListClientPath , TC . s_todoListClientExe , clientEnvVars ) ;
77
+ var clientProcessOptions = new ProcessStartOptions ( _testAssemblyLocation , _sampleClientAppPath , TC . s_todoListClientExe , clientEnvVars ) ; // probs need to add client specific path
78
+ var serviceProcessOptions = new ProcessStartOptions ( _testAssemblyLocation , _sampleServiceAppPath , TC . s_todoListServiceExe , serviceEnvVars ) ;
80
79
81
- if ( ! UiTestHelpers . ProcessesAreAlive ( new List < Process > ( ) { clientProcess , serviceProcess } ) )
82
- {
83
- Assert . Fail ( TC . WebAppCrashedString ) ;
84
- }
80
+ UiTestHelpers . StartAndVerifyProcessesAreRunning ( [ serviceProcessOptions , clientProcessOptions ] , out processes , ProcessStartupRetryNum ) ;
85
81
86
82
// Navigate to web app the retry logic ensures the web app has time to start up to establish a connection.
87
83
IPage page = await context . NewPageAsync ( ) ;
@@ -93,11 +89,11 @@ public async Task B2C_ValidCreds_LoginLogout()
93
89
await page . GotoAsync ( TC . LocalhostUrl + TodoListClientPort ) ;
94
90
break ;
95
91
}
96
- catch ( PlaywrightException ex )
92
+ catch ( PlaywrightException )
97
93
{
98
94
await Task . Delay ( 1000 ) ;
99
95
InitialConnectionRetryCount -- ;
100
- if ( InitialConnectionRetryCount == 0 ) { throw ex ; }
96
+ if ( InitialConnectionRetryCount == 0 ) { throw ; }
101
97
}
102
98
}
103
99
LabResponse labResponse = await LabUserHelper . GetB2CLocalAccountAsync ( ) ;
@@ -127,14 +123,11 @@ public async Task B2C_ValidCreds_LoginLogout()
127
123
}
128
124
finally
129
125
{
130
- // Add the following to make sure all processes and their children are stopped.
131
- Queue < Process > processes = new Queue < Process > ( ) ;
132
- if ( serviceProcess != null ) { processes . Enqueue ( serviceProcess ) ; }
133
- if ( clientProcess != null ) { processes . Enqueue ( clientProcess ) ; }
134
- UiTestHelpers . KillProcessTrees ( processes ) ;
126
+ // End all processes.
127
+ UiTestHelpers . EndProcesses ( processes ) ;
135
128
136
129
// Stop tracing and export it into a zip archive.
137
- string path = UiTestHelpers . GetTracePath ( _testAssemblyPath , TraceFileName ) ;
130
+ string path = UiTestHelpers . GetTracePath ( _testAssemblyLocation , TraceFileName ) ;
138
131
await context . Tracing . StopAsync ( new ( ) { Path = path } ) ;
139
132
_output . WriteLine ( $ "Trace data for { TraceFileName } recorded to { path } .") ;
140
133
0 commit comments