@@ -14,11 +14,16 @@ public class ApmUIBrowserContext : IAsyncLifetime
14
14
{
15
15
private readonly IConfigurationRoot _configuration ;
16
16
private readonly string _serviceName ;
17
+ private readonly string _playwrightScreenshotsDir ;
18
+ private readonly List < string > _output ;
17
19
18
- public ApmUIBrowserContext ( IConfigurationRoot configuration , string serviceName )
20
+ public ApmUIBrowserContext ( IConfigurationRoot configuration , string serviceName , string playwrightScreenshotsDir , List < string > output )
19
21
{
20
22
_configuration = configuration ;
21
23
_serviceName = serviceName ;
24
+ _playwrightScreenshotsDir = playwrightScreenshotsDir ;
25
+ _output = output ;
26
+
22
27
//"https://{instance}.apm.us-east-1.aws.elastic.cloud:443"
23
28
// https://{instance}.kb.us-east-1.aws.elastic.cloud/app/apm/services?comparisonEnabled=true&environment=ENVIRONMENT_ALL&rangeFrom=now-15m&rangeTo=now&offset=1d
24
29
var endpoint = configuration [ "E2E:Endpoint" ] ? . Trim ( ) ?? string . Empty ;
@@ -84,25 +89,35 @@ public async Task<IPage> OpenApmLandingPage(string testName)
84
89
return page ;
85
90
}
86
91
92
+ private void Log ( string message )
93
+ {
94
+ Console . WriteLine ( message ) ;
95
+ _output . Add ( message ) ;
96
+ }
97
+
87
98
public async Task WaitForServiceOnOverview ( IPage page )
88
99
{
89
100
var timeout = ( float ) TimeSpan . FromSeconds ( 30 ) . TotalMilliseconds ;
90
101
91
102
var servicesHeader = page . GetByRole ( AriaRole . Heading , new ( ) { Name = "Services" } ) ;
92
103
await servicesHeader . WaitForAsync ( new ( ) { State = WaitForSelectorState . Visible , Timeout = timeout } ) ;
93
104
94
- Console . WriteLine ( $ "Search for service name: { _serviceName } ") ;
105
+ await page . ScreenshotAsync ( new ( ) { Path = Path . Join ( _playwrightScreenshotsDir , "services-loaded.jpeg" ) , FullPage = true } ) ;
106
+
107
+ Log ( $ "Search for service name: { _serviceName } ") ;
95
108
96
109
//service.name : dotnet-e2e-*
97
110
var queryBar = page . GetByRole ( AriaRole . Searchbox , new ( ) { Name = "Search services by name" } ) ;
98
111
await queryBar . WaitForAsync ( new ( ) { State = WaitForSelectorState . Visible , Timeout = timeout } ) ;
99
112
await queryBar . FillAsync ( _serviceName ) ;
100
113
await queryBar . PressAsync ( "Enter" ) ;
101
114
115
+ await page . ScreenshotAsync ( new ( ) { Path = Path . Join ( _playwrightScreenshotsDir , "filter-services.jpeg" ) , FullPage = true } ) ;
116
+
102
117
Exception ? observed = null ;
103
118
104
119
var refreshTimeout = ( float ) TimeSpan . FromSeconds ( 5 ) . TotalMilliseconds ;
105
- for ( var i = 0 ; i < 10 ; i ++ )
120
+ for ( var i = 0 ; i < 20 ; i ++ )
106
121
{
107
122
try
108
123
{
@@ -113,10 +128,7 @@ public async Task WaitForServiceOnOverview(IPage page)
113
128
}
114
129
catch ( Exception e )
115
130
{
116
- await page . ScreenshotAsync ( new ( ) { Path = $ "squibble{ i } .jpeg", FullPage = true } ) ;
117
-
118
131
observed ??= e ;
119
- await page . ReloadAsync ( ) ;
120
132
}
121
133
finally
122
134
{
@@ -125,31 +137,32 @@ public async Task WaitForServiceOnOverview(IPage page)
125
137
}
126
138
if ( observed != null )
127
139
throw observed ; //TODO proper rethrow with stack
128
-
129
140
}
130
141
131
142
private int _unnamedTests ;
132
143
public async Task StopTrace ( IPage page , bool success , [ CallerMemberName ] string ? testName = null )
133
144
{
134
145
testName ??= $ "unknown_test_{ _unnamedTests ++ } ";
135
- //only dump trace zip of test name is provided.
146
+
147
+ //only dump trace zip if tests failed
136
148
if ( success )
149
+ {
137
150
await page . Context . Tracing . StopAsync ( new ( ) ) ;
151
+ }
138
152
else
139
153
{
140
154
var root = DotNetRunApplication . GetSolutionRoot ( ) ;
141
155
var zip = Path . Combine ( root . FullName , ".artifacts" , "playwright-traces" , $ "{ testName } .zip") ;
142
156
await page . Context . Tracing . StopAsync ( new ( ) { Path = zip } ) ;
143
157
144
- using var archive = ZipFile . OpenRead ( zip ) ;
145
- var entries = archive . Entries . Where ( e => e . FullName . StartsWith ( "resources" ) && e . FullName . EndsWith ( ".jpeg" ) ) . ToList ( ) ;
146
- var lastScreenshot = entries . MaxBy ( e => e . LastWriteTime ) ;
147
- lastScreenshot ? . ExtractToFile ( Path . Combine ( root . FullName , ".artifacts" , "playwright-traces" , $ "{ testName } -screenshot.jpeg") ) ;
158
+ // using var archive = ZipFile.OpenRead(zip);
159
+ // var entries = archive.Entries.Where(e => e.FullName.StartsWith("resources") && e.FullName.EndsWith(".jpeg")).ToList();
160
+ // var lastScreenshot = entries.MaxBy(e => e.LastWriteTime);
161
+ // lastScreenshot?.ExtractToFile(Path.Combine(root.FullName, ".artifacts", "playwright-traces", $"{testName}-screenshot.jpeg"));
148
162
}
149
163
await page . CloseAsync ( ) ;
150
164
}
151
165
152
-
153
166
public async Task DisposeAsync ( )
154
167
{
155
168
await Browser . DisposeAsync ( ) ;
0 commit comments