Skip to content

Commit 30e4cbd

Browse files
authored
Merge pull request #42 from tawk/tests-login-update
Tests update for OAuth login
2 parents b5277f9 + d103ca3 commit 30e4cbd

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

.github/workflows/ui-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
ref: ${{ github.event.workflow_run.head_sha }}
2020

2121
- name: cached dependencies
22-
uses: actions/cache@v2
22+
uses: actions/cache@v3
2323
id: cached-dependencies
2424
with:
2525
path: |

tests/TestFiles/Modules/Web.php

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,45 @@ public function goto_widget_selection() {
184184

185185
// driver currently on tawk-iframe frame
186186
// incase the current session hasn't logged in to the plugin yet.
187-
$login_form_id = '#loginForm';
188-
$login_form = $this->driver->find_and_check_element( $login_form_id );
189-
if ( false === is_null( $login_form ) ) {
190-
$this->driver->find_element_and_input( '#email', $this->tawk->username );
191-
$this->driver->find_element_and_input( '#password', $this->tawk->password );
192-
$this->driver->find_element_and_click( '#login-button' );
187+
$login_button_id = '#login-button';
188+
$login_button = $this->driver->find_and_check_element( $login_button_id );
189+
if ( true === is_null( $login_button ) ) {
190+
return;
191+
}
192+
193+
$this->driver->find_element_and_click( '#login-button' );
194+
195+
$window_handles = $this->driver->get_driver()->getWindowHandles();
196+
$this->driver->get_driver()->switchTo()->window( end( $window_handles ) );
197+
198+
// driver currently on tawk.to OAuth login popout.
199+
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;
193208
}
209+
210+
// handle login page.
211+
$this->driver->find_element_and_input( '#email', $this->tawk->username );
212+
$this->driver->find_element_and_input( '#password', $this->tawk->password );
213+
$this->driver->find_element_and_click( 'button[type="submit"]' );
214+
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();
221+
}
222+
223+
// go back to tawk-iframe frame.
224+
$this->driver->get_driver()->switchTo()->window( reset( $window_handles ) );
225+
$this->driver->wait_for_frame_and_switch( '#tawk-iframe', 10 );
194226
}
195227

196228
public function goto_visibility_options() {

0 commit comments

Comments
 (0)