@@ -161,7 +161,25 @@ async function chooseTarget(dialog: Locator, ariaLabel: 'Target groups' | 'Targe
161161}
162162
163163async function clickSectionAction ( section : Locator , actionLabel : string | RegExp ) {
164- await section . getByRole ( 'button' , { name : actionLabel } ) . first ( ) . click ( )
164+ let lastError : unknown
165+
166+ for ( let attempt = 0 ; attempt < 5 ; attempt ++ ) {
167+ const button = section . getByRole ( 'button' , { name : actionLabel } ) . first ( )
168+
169+ try {
170+ await button . waitFor ( { state : 'visible' , timeout : 2000 } )
171+ await button . scrollIntoViewIfNeeded ( ) . catch ( ( ) => { } )
172+ await button . click ( { timeout : 2000 } )
173+ return
174+ } catch ( error ) {
175+ lastError = error
176+ await new Promise ( ( resolve ) => setTimeout ( resolve , 250 ) )
177+ }
178+ }
179+
180+ throw lastError instanceof Error
181+ ? lastError
182+ : new Error ( `Failed to click section action matching "${ String ( actionLabel ) } "` )
165183}
166184
167185async function removeRuleWithConfirmation ( page : Page , dialog : Locator , section : Locator , actionLabel : string | RegExp ) {
@@ -194,6 +212,11 @@ async function removeAllRulesByAction(
194212
195213 await removeRuleWithConfirmation ( page , dialog , section , actionLabel )
196214 await waitForEditorIdle ( dialog )
215+ await expect . poll ( async ( ) => {
216+ return section . getByRole ( 'button' , { name : actionLabel } ) . count ( )
217+ } , {
218+ timeout : 5000 ,
219+ } ) . toBeLessThan ( currentCount )
197220 }
198221
199222 throw new Error ( `Failed to remove all rules for action "${ actionLabel } " after multiple attempts` )
0 commit comments