File tree 1 file changed +30
-11
lines changed
src/mono/wasm/Wasm.Build.Tests 1 file changed +30
-11
lines changed Original file line number Diff line number Diff line change @@ -102,24 +102,43 @@ public async Task<string> StartServerAndGetUrlAsync(
102
102
103
103
public async Task < IBrowser > SpawnBrowserAsync (
104
104
string browserUrl ,
105
- bool headless = true
105
+ bool headless = true ,
106
+ int timeout = 10000 ,
107
+ int maxRetries = 3
106
108
) {
107
109
var url = new Uri ( browserUrl ) ;
108
110
Playwright = await Microsoft . Playwright . Playwright . CreateAsync ( ) ;
109
111
// codespaces: ignore certificate error -> Microsoft.Playwright.PlaywrightException : net::ERR_CERT_AUTHORITY_INVALID
110
112
string [ ] chromeArgs = new [ ] { $ "--explicitly-allowed-ports={ url . Port } ", "--ignore-certificate-errors" } ;
111
113
_testOutput . WriteLine ( $ "Launching chrome ('{ s_chromePath . Value } ') via playwright with args = { string . Join ( ',' , chromeArgs ) } ") ;
112
- Browser = await Playwright . Chromium . LaunchAsync ( new BrowserTypeLaunchOptions {
113
- ExecutablePath = s_chromePath . Value ,
114
- Headless = headless ,
115
- Args = chromeArgs
116
- } ) ;
117
- Browser . Disconnected += ( sender , e ) =>
114
+
115
+ int attempt = 0 ;
116
+ while ( attempt < maxRetries )
118
117
{
119
- Browser = null ;
120
- _testOutput . WriteLine ( "Browser has been disconnected" ) ;
121
- } ;
122
- return Browser ;
118
+ try
119
+ {
120
+ Browser = await Playwright . Chromium . LaunchAsync ( new BrowserTypeLaunchOptions {
121
+ ExecutablePath = s_chromePath . Value ,
122
+ Headless = headless ,
123
+ Args = chromeArgs ,
124
+ Timeout = timeout
125
+ } ) ;
126
+ Browser . Disconnected += ( sender , e ) =>
127
+ {
128
+ Browser = null ;
129
+ _testOutput . WriteLine ( "Browser has been disconnected" ) ;
130
+ } ;
131
+ break ;
132
+ }
133
+ catch ( System . TimeoutException ex )
134
+ {
135
+ attempt ++ ;
136
+ _testOutput . WriteLine ( $ "Attempt { attempt } failed with TimeoutException: { ex . Message } ") ;
137
+ }
138
+ }
139
+ if ( attempt == maxRetries )
140
+ throw new Exception ( $ "Failed to launch browser after { maxRetries } attempts") ;
141
+ return Browser ! ;
123
142
}
124
143
125
144
// FIXME: options
You can’t perform that action at this time.
0 commit comments