Skip to content

Commit d612385

Browse files
authored
Merge pull request #43 from tawk/tests-login-update
Fix tests - handle oauth consent skipped
2 parents 473d633 + d1cfeec commit d612385

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

tests/TestFiles/Modules/Web.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,37 @@ public function goto_widget_selection() {
192192

193193
$this->driver->find_element_and_click( '#login-button' );
194194

195-
$window_handles = $this->driver->get_driver()->getWindowHandles();
196-
$this->driver->get_driver()->switchTo()->window( end( $window_handles ) );
195+
$window_handles = $this->driver->get_driver()->getWindowHandles();
196+
$new_window_handle = end( $window_handles );
197+
198+
$this->driver->get_driver()->switchTo()->window( $new_window_handle );
197199

198200
// driver currently on tawk.to OAuth login popout.
199201

200-
// handle currently logged in page.
201-
$allow_id = '#allow';
202-
$allow_button = $this->driver->find_and_check_element( $allow_id );
203-
if ( false === is_null( $allow_button ) ) {
204-
$allow_button->click();
205-
$this->driver->get_driver()->switchTo()->window( reset( $window_handles ) );
206-
$this->driver->wait_for_frame_and_switch( '#tawk-iframe', 10 );
207-
return;
208-
}
202+
// currently logged in page not shown because driver creates new browser instance.
209203

210204
// handle login page.
211205
$this->driver->find_element_and_input( '#email', $this->tawk->username );
212206
$this->driver->find_element_and_input( '#password', $this->tawk->password );
213207
$this->driver->find_element_and_click( 'button[type="submit"]' );
214208

215-
// handle consent page.
216-
$allow_id = '#allow';
217-
$allow_button = $this->driver->find_and_check_element( $allow_id );
218-
219-
if ( false === is_null( $allow_button ) ) {
220-
$allow_button->click();
209+
$start = microtime( true );
210+
while ( ( microtime( true ) - $start ) < 5 ) {
211+
// consent already allowed, window will automatically close.
212+
$current_handles = $this->driver->get_driver()->getWindowHandles();
213+
if ( ! in_array( $new_window_handle, $current_handles, true ) ) {
214+
break;
215+
}
216+
217+
// handle consent page if shown.
218+
try {
219+
$this->driver->find_element_and_click( '#allow' );
220+
break;
221+
} catch ( \Exception $e ) { // phpcs:ignore
222+
// consent button not found, do nothing.
223+
}
224+
225+
usleep( 10000 );
221226
}
222227

223228
// go back to tawk-iframe frame.

tests/docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ services:
5959

6060
selenium:
6161
container_name: selenium
62-
image: selenium/standalone-${SELENIUM_BROWSER}:latest
62+
image: selenium/standalone-${SELENIUM_BROWSER}:4.28 # 4.29: intermittent driver session loss when OAuth popout is closed
6363
shm_size: 2g
6464
ports:
6565
- ${SELENIUM_PORT}:4444

0 commit comments

Comments
 (0)