getLoginCredentialsByType($eUserLogin); $this->url($loginData['url']); $this->waitUntilDomReadyState(); // Check if we landed on dashboard - already logged in if ($this->elementExists('report_period_chosen')) { return; } // Else continue with the login $this->elementWait('user_login'); $this->byId("user_login")->sendKeys($loginData['user']); $this->byId("user_password")->sendKeys($loginData['password']); $this->byCssSelector("form#frm_input div#agree_to_terms")->click(); $this->byCssSelector("form#frm_input button.btn.btn-block")->click(); $this->waitUntilDomReadyState(); $this->awaitAndFill2FASecurityAfterLoginRequest($loginData); if (strlen($siteAccount) > 0) { $this->awaitAndSelectAccount($siteAccount); } else { sleep(1); // Sleep - otherwise awaitAndAcceptCookies() fail. } $this->awaitAndAcceptCookies(); } function fillAndSubmitPasswordChangeForm(array $data) { if ($this->byId("old_password")->isEnabled()) { $this->byId("old_password")->clear()->sendKeys($data['oldPass']); } $this->byId("new_password")->sendKeys($data['newPass']); $this->byId("rnew_password")->sendKeys($data['newPass']); $this->byCssSelector("form#pwd_cnt > button.btn.btn-block")->click(); $this->waitUntilDomReadyState(); } function awaitAndProceedWithSecuritySetupRequest() { $this->elementWait('a.enable_2fa', self::CSS_SELECTOR); $this->byCssSelector('a.enable_2fa')->click(); $this->waitUntilDomReadyState(); } function awaitAndFill2FASecurityAfterLoginRequest(array $loginData): void { // Wait for form to load 2fa elements & continue with testing $this->elementWait('frm_2fa_input'); // Validate code $oGoogle2FA = new cGoogle2FA(); $next2FACode = $oGoogle2FA->getGoogleAuthCode($loginData['2fa']); foreach (str_split($next2FACode) as $i => $char) { $this->byCssSelector("form#frm_2fa_input div#fields input[tabindex='" . ++$i . "']")->sendKeys($char); } $this->waitUntilDomReadyState(); } function awaitAndAcceptCookies(): void { if ($this->elementExists('div.accept_cookies a#accept-cookies', self::CSS_SELECTOR)) { $this->elementWait('div#popup_onload.accept_cookies a#accept-cookies', self::CSS_SELECTOR); $this->byId('accept-cookies')->click(); $this->elementWaitRemoved('#popup_onload.accept_cookies', self::CSS_SELECTOR); $this->waitUntilDomReadyState(); } } function awaitAndSelectAccount(string $accountTitleToSelect): void { // Wait for company selection screen by default user has now multiple companies $xPathSelector = "//div[@class='container']/div/div/form" . "//li[not(contains(@style,'display:none'))]/a/i[contains(., '$accountTitleToSelect')]"; $this->elementWait($xPathSelector, self::XPATH); $this->assertEquals($accountTitleToSelect, $this->byXPath($xPathSelector)->getText()); $this->byXPath($xPathSelector)->click(); $this->waitUntilDomReadyState(); } function awaitAndSetup2FASecurity(): string { $this->elementWait('div span#secret', self::CSS_SELECTOR); $securityCode = $this->byCssSelector('div span#secret')->getText(); // Validate code $oGoogle2FA = new cGoogle2FA(); $next2FACode = $oGoogle2FA->getGoogleAuthCode($securityCode); // Fill form 2fa data foreach (str_split($next2FACode) as $i => $char) { $this->byCssSelector("form#frm_2fa_input div#fields input[tabindex='" . ++$i . "']")->sendKeys($char); } $this->waitUntilDomReadyState(); return $securityCode; } }