@@ -75,6 +75,51 @@ export const interactionSteps = (wp: WebPlaywright): TStepperSteps => ({
7575 gwta : `wait for {target: ${ DOMAIN_STRING_OR_PAGE_LOCATOR } }` ,
7676 action : async ( { target } : { target : string } , featureStep : TFeatureStep ) => {
7777 try {
78+ // Check if we're being called from within inElement with a shadow DOM context
79+ if ( wp . inContainerSelector ) {
80+ try {
81+ // Get the actual Page object (not through withPage which might return a Locator)
82+ const page = await wp . getPage ( ) ;
83+ // Assume the container is a shadow DOM host - wait for element in shadow root
84+ await page . waitForFunction (
85+ ( { containerSel, innerSel } ) => {
86+ const host = document . querySelector ( containerSel ) ;
87+ if ( ! host ?. shadowRoot ) return false ;
88+
89+ const element = host . shadowRoot . querySelector ( innerSel ) ;
90+ if ( ! element ) return false ;
91+
92+ // Use getBoundingClientRect to check if element has dimensions
93+ const rect = element . getBoundingClientRect ( ) ;
94+ if ( rect . width === 0 || rect . height === 0 ) return false ;
95+
96+ // Check computed styles for common hiding methods
97+ const computed = window . getComputedStyle ( element ) ;
98+ if ( computed . display === 'none' || computed . visibility === 'hidden' || computed . opacity === '0' ) return false ;
99+
100+ // Check if element is behind other layers (negative z-index parent)
101+ let current = element . parentElement ;
102+ while ( current ) {
103+ const style = window . getComputedStyle ( current ) ;
104+ if ( style . display === 'none' || style . visibility === 'hidden' || style . opacity === '0' ) return false ;
105+ const zIndex = parseInt ( style . zIndex ) ;
106+ if ( ! isNaN ( zIndex ) && zIndex < 0 ) return false ;
107+ current = current . parentElement ;
108+ }
109+
110+ return true ;
111+ } ,
112+ { containerSel : wp . inContainerSelector , innerSel : target } ,
113+ { timeout : 30000 }
114+ ) ;
115+ return OK ;
116+ } catch ( e ) {
117+ // Shadow DOM approach failed, return error
118+ return actionNotOK ( `Did not find ${ target } in shadow DOM: ${ e } ` ) ;
119+ }
120+ }
121+
122+ // Regular wait (not in shadow DOM)
78123 await wp . withPage ( async ( page : Page ) => await locateByDomain ( page , featureStep , 'target' ) . waitFor ( ) ) ;
79124 return OK ;
80125 } catch ( e ) {
@@ -221,12 +266,14 @@ export const interactionSteps = (wp: WebPlaywright): TStepperSteps => ({
221266 } ,
222267 inElement : {
223268 gwta : `in {container: ${ DOMAIN_STRING_OR_PAGE_LOCATOR } }, {what: ${ DOMAIN_STATEMENT } }` ,
224- action : async ( { what } : { container : string ; what : TFeatureStep [ ] } , featureStep : TFeatureStep ) => {
269+ action : async ( { container , what } : { container : string ; what : TFeatureStep [ ] } , featureStep : TFeatureStep ) => {
225270 return await wp . withPage ( async ( page : Page ) => {
226271 const containerLocator = locateByDomain ( page , featureStep , 'container' ) ;
227272 wp . inContainer = containerLocator ;
273+ wp . inContainerSelector = container ; // Store the selector string for shadow DOM detection
228274 const whenResult = await doExecuteFeatureSteps ( what , [ wp ] , wp . getWorld ( ) , ExecMode . CYCLES ) ;
229275 wp . inContainer = undefined ;
276+ wp . inContainerSelector = undefined ;
230277 return whenResult ;
231278 } ) ;
232279 } ,
0 commit comments