[ 'url' => 'ienakt-gramatvedibas-sistema', 'header' => 'Ienākt grāmatvedības sistēmā', 'header-2fa' => 'Divu faktoru autentifikācija', 'exists' => [ 'input.code2fa[tabindex=\'1\']', 'input.code2fa[tabindex=\'2\']', 'input.code2fa[tabindex=\'3\']', 'input.code2fa[tabindex=\'4\']', 'input.code2fa[tabindex=\'5\']', 'input.code2fa[tabindex=\'6\']', 'button#submit' ], 'text-exists' => [ 'Divu faktoru autentifikācija', 'Ievadi Google Authenticator lietotnes piešķirto', 'Divu faktoru autentifikācijas kodu', 'Ienākt', 'Atpakaļ uz autentifikāciju', 'Ja esat zaudējis piekļuvi sava autentifikācijas ierīcei,' ], 'inv-code' => '2 faktoru autentifikācijas koda kļūda!', 'fill-field' => 'Lūdzu aizpildiet lauku!', 'welcome-msg' => ['Laipni lūdzam,', 'Grāmatvedības sistēma', 'Sākums'] ] ]; public function testLogin2fa(): void { $loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed); foreach (self::url as $lang => $pageData) { // Login - redirect to 2FA $this->url($pageData['url']); $this->switchToLanguage($lang); $this->elementWait('user_login'); // Input login data $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->elementWait('frm_2fa_input'); $this->assertEquals( $pageData['header-2fa'], $this->byCssSelector('div#form > .relative > p.font-20')->getText() ); // Validate 2fa code from google $oGoogle2FA = new cGoogle2FA(); $next2FACode = $oGoogle2FA->getGoogleAuthCode($loginData['2fa']); foreach (str_split($next2FACode) as $i => $char) { $this->byCssSelector("input.code2fa[tabindex='" . ++$i . "']")->clear()->sendKeys($char); } // Wait for company selection screen by default user has now multiple companies $this->elementWait( "//ul[@id='favorite']//li/a/i[contains(text(),'" . siteAccounts::ACCOUNT_SELF_EMPLOYED . "')]", self::XPATH ); $this->elementExists( "//ul[@id='favorite']//li/a/i[contains(text(),'" . siteAccounts::ACCOUNT_SELF_EMPLOYED . "')]", self::XPATH ); $this->byXPath( "//ul[@id='favorite']//li/a/i[contains(text(),'" . siteAccounts::ACCOUNT_SELF_EMPLOYED . "')]/.." )->click(); $this->waitUntilDomReadyState(); // Accept cookies message $this->awaitAndAcceptCookies(); $this->switchToLanguage($lang); // Validate dashboard welcome messages $this->elementWait("#drop_cnt > .doc > .form-data div.container.dashboard-cnt", self::CSS_SELECTOR); $this->assertExpected($pageData['welcome-msg'], $this->byTagName('body')->getText()); // Log Out $this->logout(); $this->assertEquals($pageData['header'], $this->byCssSelector('div#form > .relative > p.font-20')->getText()); } } public function testLogin2faForm(): void { $loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed); foreach (self::url as $lang => $pageData) { // Login - redirect to 2FA $this->url($pageData['url']); // Login user till Two-factor authentication pubUserLoginTest::logInUserByCredentials($this, pubUserLoginTest::url[$lang], $loginData); // Test if 2FA page loaded correctly foreach ($pageData['exists'] as $selectorToFind) { $this->assertTrue($this->elementExists($selectorToFind, self::CSS_SELECTOR), "Could not find element by selector -> {$selectorToFind}"); } // Check for form texts in page $this->assertExpected($pageData['text-exists'], $this->byTagName('body')->getText()); // Check validation $i = 0; $inputs = $this->webDriver->findElements(WebDriverBy::cssSelector('#frm_2fa_input input.code2fa')); foreach ($inputs as $element) { $i++; $this->webDriver->action()->moveToElement($this->byCssSelector("input.code2fa[tabindex='" . $i . "']"))->perform(); $this->webDriver->executeScript('$("input.code2fa:focus").blur();'); $this->webDriver->executeScript('$("input.code2fa[tabindex=\'' . $i . '\']").focus().blur().focus();'); $this->byCssSelector("input.code2fa[tabindex='" . $i . "']")->click(); $this->elementWait("input.code2fa[tabindex='" . $i . "'] + div.errMsg", self::CSS_SELECTOR); $this->assertEquals($pageData['fill-field'], $this->byCssSelector( "input.code2fa[tabindex='" . $i . "'] + div.errMsg")->getText(), "2FA code for 2FA not found by input index {$i}" ); } // Send random code foreach ($inputs as $element) { $element->sendKeys('1'); } $this->elementWait('div.status_error', self::CSS_SELECTOR); $this->assertEquals($pageData['inv-code'], $this->byCssSelector('div.status_error')->getText()); // Check for logout - log out $this->byCssSelector("#frm_2fa_input > a.link")->click(); $this->elementWait('user_login'); $this->assertEquals($pageData['header'], $this->byCssSelector('div#form > .relative > p.font-20')->getText()); } } }