@@ -473,15 +473,32 @@ export async function verifyHoldMusicElement(page: Page): Promise<void> {
473473 * @returns Promise<void>
474474 */
475475export async function endTask ( page : Page ) : Promise < void > {
476- const endButton = page . getByTestId ( 'call-control:end-call' ) . nth ( 0 ) ;
477- await endButton . waitFor ( { state : 'visible' , timeout : OPERATION_TIMEOUT } ) ;
476+ const allEndButtons = page . getByTestId ( 'call-control:end-call' ) ;
477+ await allEndButtons . first ( ) . waitFor ( { state : 'visible' , timeout : OPERATION_TIMEOUT } ) ;
478+
479+ const buttonCount = await allEndButtons . count ( ) ;
480+ let selectedEndButton = allEndButtons . first ( ) ;
481+ let hasEnabledEndButton = false ;
482+
483+ for ( let i = 0 ; i < buttonCount ; i ++ ) {
484+ const candidate = allEndButtons . nth ( i ) ;
485+ const isVisible = await candidate . isVisible ( ) . catch ( ( ) => false ) ;
486+ if ( ! isVisible ) {
487+ continue ;
488+ }
489+
490+ selectedEndButton = candidate ;
491+ const isEnabled = await candidate . isEnabled ( ) . catch ( ( ) => false ) ;
492+ if ( isEnabled ) {
493+ hasEnabledEndButton = true ;
494+ break ;
495+ }
496+ }
478497
479- // Check if button is disabled and wait for it to be enabled
480- const isDisabled = await endButton . isDisabled ( ) ;
481- if ( isDisabled ) {
498+ if ( ! hasEnabledEndButton ) {
482499 await holdCallToggle ( page ) ;
483- await expect ( endButton ) . toBeEnabled ( { timeout : AWAIT_TIMEOUT } ) ;
500+ await expect ( selectedEndButton ) . toBeEnabled ( { timeout : AWAIT_TIMEOUT } ) ;
484501 }
485502
486- await endButton . click ( { timeout : AWAIT_TIMEOUT } ) ;
503+ await selectedEndButton . click ( { timeout : AWAIT_TIMEOUT } ) ;
487504}
0 commit comments