@@ -57,33 +57,92 @@ export class AgenticChatPage {
57
57
async getBackground (
58
58
property : "backgroundColor" | "backgroundImage" = "backgroundColor"
59
59
) : Promise < string > {
60
- // Wait a bit for background to apply
61
- await this . page . waitForTimeout ( 500 ) ;
60
+ // Wait for React to render and apply styles
61
+ await this . page . waitForTimeout ( 2000 ) ;
62
62
63
- // Try multiple selectors for the background element
63
+ // Wait for the main container with background style to be present
64
+ await this . page . waitForSelector ( '.flex.justify-center.items-center.h-full.w-full' , {
65
+ state : 'visible' ,
66
+ timeout : 10000
67
+ } ) ;
68
+
69
+ // Try to get the background from the main container
70
+ const mainContainer = this . page . locator ( '.flex.justify-center.items-center.h-full.w-full' ) . first ( ) ;
71
+
72
+ try {
73
+ const backgroundValue = await mainContainer . evaluate ( ( el ) => {
74
+ // Get the inline style background value
75
+ const inlineBackground = el . style . background ;
76
+ if ( inlineBackground && inlineBackground !== '--copilot-kit-background-color' ) {
77
+ return inlineBackground ;
78
+ }
79
+
80
+ // Get computed style
81
+ const computedStyle = getComputedStyle ( el ) ;
82
+ const computedBackground = computedStyle . background ;
83
+ const computedBackgroundColor = computedStyle . backgroundColor ;
84
+
85
+ // Check if it's a CSS custom property
86
+ if ( inlineBackground === '--copilot-kit-background-color' ) {
87
+ // Try to resolve the CSS custom property
88
+ const customPropValue = computedStyle . getPropertyValue ( '--copilot-kit-background-color' ) ;
89
+ if ( customPropValue ) {
90
+ return customPropValue ;
91
+ }
92
+ }
93
+
94
+ // Return computed values
95
+ if ( computedBackground && computedBackground !== 'rgba(0, 0, 0, 0)' && computedBackground !== 'transparent' ) {
96
+ return computedBackground ;
97
+ }
98
+
99
+ if ( computedBackgroundColor && computedBackgroundColor !== 'rgba(0, 0, 0, 0)' && computedBackgroundColor !== 'transparent' ) {
100
+ return computedBackgroundColor ;
101
+ }
102
+
103
+ return computedBackground || computedBackgroundColor ;
104
+ } ) ;
105
+
106
+ console . log ( `Main container background: ${ backgroundValue } ` ) ;
107
+
108
+ if ( backgroundValue && backgroundValue !== 'rgba(0, 0, 0, 0)' && backgroundValue !== 'transparent' ) {
109
+ return backgroundValue ;
110
+ }
111
+ } catch ( error ) {
112
+ console . log ( 'Error getting background from main container:' , error ) ;
113
+ }
114
+
115
+ // Fallback: try other selectors
64
116
const selectors = [
65
117
'div[style*="background"]' ,
66
118
'div[style*="background-color"]' ,
67
- '.flex.justify-center.items-center.h-full.w-full' ,
68
- 'div.flex.justify-center.items-center.h-full.w-full' ,
69
- '[class*="bg-"]' ,
70
- 'div[class*="background"]'
119
+ '.copilotKitWindow' ,
120
+ 'body'
71
121
] ;
72
122
73
123
for ( const selector of selectors ) {
74
124
try {
75
125
const element = this . page . locator ( selector ) . first ( ) ;
76
- if ( await element . isVisible ( { timeout : 1000 } ) ) {
126
+ console . log ( `Checking fallback selector: ${ selector } ` ) ;
127
+
128
+ if ( await element . isVisible ( { timeout : 5000 } ) ) {
77
129
const value = await element . evaluate (
78
130
( el , prop ) => {
79
- // Check inline style first
80
- if ( el . style . background ) return el . style . background ;
81
- if ( el . style . backgroundColor ) return el . style . backgroundColor ;
131
+ const computedStyle = getComputedStyle ( el ) ;
132
+ const inlineStyle = el . style [ prop as any ] ;
133
+
134
+ // Prefer inline style
135
+ if ( inlineStyle && inlineStyle !== 'rgba(0, 0, 0, 0)' && inlineStyle !== 'transparent' ) {
136
+ return inlineStyle ;
137
+ }
138
+
82
139
// Then computed style
83
- return getComputedStyle ( el ) [ prop as any ] ;
140
+ const computedValue = computedStyle [ prop as any ] ;
141
+ return computedValue ;
84
142
} ,
85
143
property
86
144
) ;
145
+
87
146
if ( value && value !== "rgba(0, 0, 0, 0)" && value !== "transparent" ) {
88
147
console . log ( `[${ selector } ] ${ property } : ${ value } ` ) ;
89
148
return value ;
@@ -94,13 +153,45 @@ export class AgenticChatPage {
94
153
}
95
154
}
96
155
97
- // Fallback to original element
98
- const value = await this . chatBackground . first ( ) . evaluate (
99
- ( el , prop ) => getComputedStyle ( el ) [ prop as any ] ,
100
- property
101
- ) ;
102
- console . log ( `[Fallback] ${ property } : ${ value } ` ) ;
103
- return value ;
156
+ // Final fallback
157
+ const fallbackValue = await this . page . evaluate ( ( prop ) => {
158
+ return getComputedStyle ( document . body ) [ prop as any ] ;
159
+ } , property ) ;
160
+
161
+ console . log ( `[Final Fallback] ${ property } : ${ fallbackValue } ` ) ;
162
+ return fallbackValue ;
163
+ }
164
+
165
+ async waitForBackgroundChange ( expectedBackground ?: string , timeout : number = 10000 ) : Promise < void > {
166
+ const startTime = Date . now ( ) ;
167
+
168
+ while ( Date . now ( ) - startTime < timeout ) {
169
+ try {
170
+ const currentBackground = await this . getBackground ( ) ;
171
+
172
+ // If we're looking for a specific background
173
+ if ( expectedBackground ) {
174
+ if ( currentBackground . includes ( expectedBackground ) ||
175
+ currentBackground === expectedBackground ) {
176
+ return ;
177
+ }
178
+ } else {
179
+ // Just wait for any non-default background
180
+ if ( currentBackground !== 'oklch(1 0 0)' &&
181
+ currentBackground !== 'rgba(0, 0, 0, 0)' &&
182
+ currentBackground !== 'transparent' &&
183
+ ! currentBackground . includes ( '--copilot-kit-background-color' ) ) {
184
+ return ;
185
+ }
186
+ }
187
+
188
+ await this . page . waitForTimeout ( 500 ) ;
189
+ } catch ( error ) {
190
+ await this . page . waitForTimeout ( 500 ) ;
191
+ }
192
+ }
193
+
194
+ throw new Error ( `Background did not change to expected value within ${ timeout } ms` ) ;
104
195
}
105
196
106
197
async getGradientButtonByName ( name : string | RegExp ) {
0 commit comments