@@ -2,8 +2,63 @@ import { test, expect, Page } from '@playwright/test';
2
2
3
3
// Helper functions
4
4
async function openLocalhost ( page : Page , port : number ) {
5
+ // Set up console and error logging
6
+ const consoleMessages : string [ ] = [ ] ;
7
+ const pageErrors : string [ ] = [ ] ;
8
+
9
+ page . on ( 'console' , ( msg ) => {
10
+ consoleMessages . push ( `[${ msg . type ( ) } ] ${ msg . text ( ) } ` ) ;
11
+ } ) ;
12
+
13
+ page . on ( 'pageerror' , ( err ) => {
14
+ pageErrors . push ( `Page error: ${ err . message } \nStack: ${ err . stack || 'No stack trace' } ` ) ;
15
+ } ) ;
16
+
5
17
await page . goto ( `http://localhost:${ port } ` ) ;
6
- await page . waitForLoadState ( 'networkidle' ) ;
18
+
19
+ // Wait for the page to load but don't wait for networkidle since env loading might be polling
20
+ await page . waitForLoadState ( 'load' ) ;
21
+
22
+ // Wait for React to render - either the loading screen or the main content
23
+ await page . waitForSelector ( 'body > div' , { timeout : 10000 } ) ;
24
+
25
+ // Log any errors found
26
+ if ( pageErrors . length > 0 ) {
27
+ console . log ( '=== PAGE ERRORS ===' ) ;
28
+ pageErrors . forEach ( error => console . log ( error ) ) ;
29
+ console . log ( '==================' ) ;
30
+ }
31
+
32
+ if ( consoleMessages . length > 0 ) {
33
+ console . log ( '=== CONSOLE MESSAGES ===' ) ;
34
+ consoleMessages . forEach ( msg => console . log ( msg ) ) ;
35
+ console . log ( '========================' ) ;
36
+ }
37
+ }
38
+
39
+ async function waitForEnvironmentLoading ( page : Page ) {
40
+ // Wait for either the loading screen to disappear or main content to appear
41
+ // The loading screen shows "Loading environment configuration..."
42
+ const loadingText = page . locator ( 'text=Loading environment configuration...' ) ;
43
+ const mainContent = page . locator ( 'h1' ) ;
44
+
45
+ try {
46
+ // Wait up to 15 seconds for either loading to finish or main content to appear
47
+ await Promise . race ( [
48
+ loadingText . waitFor ( { state : 'hidden' , timeout : 15000 } ) ,
49
+ mainContent . waitFor ( { state : 'visible' , timeout : 15000 } )
50
+ ] ) ;
51
+ } catch ( error ) {
52
+ console . log ( 'Environment loading timeout - checking current page state' ) ;
53
+ const pageContent = await page . content ( ) ;
54
+ console . log ( 'Current page content length:' , pageContent . length ) ;
55
+
56
+ // If still loading, wait a bit more and proceed
57
+ if ( await loadingText . isVisible ( ) ) {
58
+ console . log ( 'Still showing loading screen, waiting 10 more seconds...' ) ;
59
+ await page . waitForTimeout ( 10000 ) ;
60
+ }
61
+ }
7
62
}
8
63
9
64
async function checkElementWithTextPresence ( page : Page , selector : string , text : string ) {
@@ -32,7 +87,7 @@ const appsData = [
32
87
host : 3000 ,
33
88
} ,
34
89
{
35
- header : 'Dynamic Remotes with Runtime Environment Variables ' ,
90
+ header : 'Dynamic System Host ' ,
36
91
subheader : 'Remote' ,
37
92
buttonH2 : 'Remote Widget' ,
38
93
buttonParagraph : 'Using momentjs for format the date' ,
@@ -49,6 +104,11 @@ test.describe('Dynamic Remotes Runtime Environment Variables E2E Tests', () => {
49
104
test ( `should display ${ subheader } app widget functionality and application elements` , async ( { page } ) => {
50
105
await openLocalhost ( page , host ) ;
51
106
107
+ // Wait for environment loading to complete for host app
108
+ if ( host === 3000 ) {
109
+ await waitForEnvironmentLoading ( page ) ;
110
+ }
111
+
52
112
// Check main header
53
113
await checkElementWithTextPresence ( page , 'h1' , header ) ;
54
114
@@ -83,7 +143,8 @@ test.describe('Dynamic Remotes Runtime Environment Variables E2E Tests', () => {
83
143
} ) ;
84
144
85
145
await page . goto ( 'http://localhost:3000' ) ;
86
- await page . waitForLoadState ( 'networkidle' ) ;
146
+ await page . waitForLoadState ( 'load' ) ;
147
+ await waitForEnvironmentLoading ( page ) ;
87
148
88
149
// Check that env-config.json was loaded
89
150
const envConfigRequests = networkRequests . filter ( url =>
@@ -95,6 +156,7 @@ test.describe('Dynamic Remotes Runtime Environment Variables E2E Tests', () => {
95
156
96
157
test ( 'should demonstrate dynamic remote loading with environment config' , async ( { page } ) => {
97
158
await openLocalhost ( page , 3000 ) ;
159
+ await waitForEnvironmentLoading ( page ) ;
98
160
99
161
// Click to load remote component
100
162
await clickElementWithText ( page , 'button' , 'Load Remote Widget' ) ;
@@ -113,7 +175,8 @@ test.describe('Dynamic Remotes Runtime Environment Variables E2E Tests', () => {
113
175
const startTime = Date . now ( ) ;
114
176
115
177
await page . goto ( 'http://localhost:3000' ) ;
116
- await page . waitForLoadState ( 'networkidle' ) ;
178
+ await page . waitForLoadState ( 'load' ) ;
179
+ await waitForEnvironmentLoading ( page ) ;
117
180
118
181
const loadTime = Date . now ( ) - startTime ;
119
182
expect ( loadTime ) . toBeLessThan ( 10000 ) ; // Should load within 10 seconds
0 commit comments