From 604800650d66a304aa0b6e8f5b8080a36b8440ca Mon Sep 17 00:00:00 2001 From: eug-L Date: Tue, 15 Apr 2025 17:43:11 +0300 Subject: [PATCH 1/2] handle oauth consent skipped for tests --- tests/TestFiles/Modules/Web.php | 39 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/TestFiles/Modules/Web.php b/tests/TestFiles/Modules/Web.php index c7c2332..13cd62a 100644 --- a/tests/TestFiles/Modules/Web.php +++ b/tests/TestFiles/Modules/Web.php @@ -192,32 +192,37 @@ public function goto_widget_selection() { $this->driver->find_element_and_click( '#login-button' ); - $window_handles = $this->driver->get_driver()->getWindowHandles(); - $this->driver->get_driver()->switchTo()->window( end( $window_handles ) ); + $window_handles = $this->driver->get_driver()->getWindowHandles(); + $new_window_handle = end( $window_handles ); + + $this->driver->get_driver()->switchTo()->window( $new_window_handle ); // driver currently on tawk.to OAuth login popout. - // handle currently logged in page. - $allow_id = '#allow'; - $allow_button = $this->driver->find_and_check_element( $allow_id ); - if ( false === is_null( $allow_button ) ) { - $allow_button->click(); - $this->driver->get_driver()->switchTo()->window( reset( $window_handles ) ); - $this->driver->wait_for_frame_and_switch( '#tawk-iframe', 10 ); - return; - } + // currently logged in page not shown because driver creates new browser instance. // handle login page. $this->driver->find_element_and_input( '#email', $this->tawk->username ); $this->driver->find_element_and_input( '#password', $this->tawk->password ); $this->driver->find_element_and_click( 'button[type="submit"]' ); - // handle consent page. - $allow_id = '#allow'; - $allow_button = $this->driver->find_and_check_element( $allow_id ); - - if ( false === is_null( $allow_button ) ) { - $allow_button->click(); + $start = microtime( true ); + while ( ( microtime( true ) - $start ) < 5 ) { + // consent already allowed, window will automatically close. + $current_handles = $this->driver->get_driver()->getWindowHandles(); + if ( ! in_array( $new_window_handle, $current_handles, true ) ) { + break; + } + + // handle consent page if shown. + try { + $this->driver->find_element_and_click( '#allow' ); + break; + } catch ( \Exception $e ) { // phpcs:ignore + // consent button not found, do nothing. + } + + usleep( 10000 ); } // go back to tawk-iframe frame. From d1cfeec95d97c6b953f49e5f994b1e13d454b4fe Mon Sep 17 00:00:00 2001 From: eug-L Date: Wed, 16 Apr 2025 12:25:17 +0300 Subject: [PATCH 2/2] update selenium to 4.28 to address intermittent session loss issue with OAuth popout --- tests/docker/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml index 63f3f44..3519cd5 100644 --- a/tests/docker/docker-compose.yml +++ b/tests/docker/docker-compose.yml @@ -59,7 +59,7 @@ services: selenium: container_name: selenium - image: selenium/standalone-${SELENIUM_BROWSER}:latest + image: selenium/standalone-${SELENIUM_BROWSER}:4.28 # 4.29: intermittent driver session loss when OAuth popout is closed shm_size: 2g ports: - ${SELENIUM_PORT}:4444