resetDatabaseState(); $this->pageData = [ siteLanguages::LANG_LV => (object)[ 'url' => 'index', 'menuItemXPath' => "//div[@id='navbar']//span[contains(., 'Reģistrācija')]//ancestor::a", 'gM' => (object)[ 'registration' => 'Reģistrācija', 'messagesExist' => [ 'Reģistrācija', 'Reģistrācijas forma', 'Saimnieciskās darbības veicēja informācija', 'Aizpildiet zemāk atrodošo reģistrācijas veidlapu un sāciet izmantot mūsu sistēmu jau šodien!', 'Vārds Uzvārds / Firmas nosaukums', 'Reģ. numurs', 'Ir PVN maksātājs', 'Pieejamie sistēmas moduļi', 'Vienkāršā ieraksta grāmatvedība', 'Dokumentu sagatavošanas modulis', 'Kontaktinformācija', 'Vārds', 'Uzvārds', 'E-pasts', 'Tālrunis', 'Lietotāja informācija', 'Man jau ir lietotājs, ienāciet sistēmā, lai piesaistītu jaunu kontu', 'Pierakstīties uz jaunumu saņemšanu e-pastā', 'Es esmu izlasījis un', 'piekrītu noteikumiem.', 'Noderīgas saites', ], 'fieldIsMandatory' => 'Lūdzu aizpildiet lauku!', 'invalidEMail' => 'Ievadīta nekorekta e-pasta adrese!', 'invalidEMailAlreadyTaken' => 'Lietotājs ar šo e-pastu jau ir reģistrēts!', 'invalidPhone' => 'Norādīts nepareizs tālrunis!', 'agreeToTermsH1' => 'Lietošanas noteikumi', 'alreadyHaveAnAccount' => 'Ienākt grāmatvedības sistēmā', 'logoutUseDifferentUser' => 'Izrakstīties, izmantot citu lietotāju', 'registrationEmailTitle' => 'Konts - Reģistrācija un E-pasta apstiprināšana', 'registrationEmailActText' => 'aktivizēt noklikšķinot šeit', 'registrationEmailBody' => [ 'Esiet sveicināti sistēmā ZUTENIS.', 'Esam sagatavojuši Jums lietotāja kontu, kuru atlicis tikai', 'aktivizēt noklikšķinot šeit', 'Sistēmas piekļuves dati:', 'Kontu var arī aktivizēt, noklikšķinot uz pogas', 'Ja Tev ir jautājumi par pakalpojumu, būsim priecīgi palīdzēt! ', ], 'activationSuccessfullText' => [ 'Aktivizācija veiksmīga!', 'Lai turpinātu, lūdzu nomainiet pagaidu paroli.', ], 'securityUpdateRequest' => [ 'Lai piekļūtu grāmatvedības sistēmai, ir jāiespējo', '2FA', 'Divu faktoru autentifikācijas drošība!', 'Ieslēgt', 'Iziet' ], 'securityUpdate2FAForm' => [ 'Divu faktoru autentifikācijas uzstādīšana', 'Uzinstalējiet "Google Authenticator" lietojumprogrammu savā ierīcē', 'Ja ierīci nav kameras, ievadiet atslēgu manuāli.', 'Skatieties video pamācību:', 'Ievadi Google Authenticator lietotnes piešķirto', 'Divu faktoru autentifikācijas kodu', ], 'registrationComplete' => [ 'Lūdzu pārbaudiet e-pastu', 'Jums tūliņ tiks nosūtīts aktivizācijas e-pasts!', 'Paldies par izrādīto interesi' , 'Lūdzu parbaudiet arī mestules sadaļu', 'Lai veiksmīga sadarbība!' ] ], 'elementsExist' => [ '#acc_name', '#reg_nr', '#vat_payer', '#full_system', '#document_system', '#name', '#surname', '#email', '#phone', '#login', '#loginchk', '#subscribe', '#agree_to_terms', 'input.btn.btn-primary', '#vat_reg_nr' ] ] ]; } protected function tearDown(): void { parent::tearDown(); $this->resetDatabaseState(); } protected function resetDatabaseState(): void { $this->reloadDbTables([ 'mod_users', 'mod_users_permissions', 'mod_users_subscription_mails', 'mod_account_to_create', 'mod_account_manager', 'mod_account_to_user', ]); } public function testRegistrationForm(): void { foreach ($this->pageData as $lang => $langData) { $this->goToRegistrationPage($langData); // Test error containing fields foreach (['acc_name', 'reg_nr', 'name', 'surname', 'email', 'phone',] as $field) { $this->scrollElementIntoView("#$field", self::CSS_SELECTOR); $this->webDriver->action()->moveToElement($this->byId($field))->perform(); $this->webDriver->executeScript('$("#' . $field . '").focus().blur();'); $this->elementWait('#' . $field . ' + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($langData->gM->fieldIsMandatory, $this->byCssSelector('#' . $field . ' + div.errMsg')->getText()); } // Invalid E-mail specified $this->scrollElementIntoView('#email', self::CSS_SELECTOR); $this->webDriver->action()->moveToElement($this->byId('email'))->perform(); $this->webDriver->executeScript('$("#email").focus().val("test").blur();'); $this->elementWait('#email + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($langData->gM->invalidEMail, $this->byCssSelector('#email + div.errMsg')->getText()); // Invalid Phone specified $this->scrollElementIntoView('#phone', self::CSS_SELECTOR); $this->webDriver->executeScript('$("#phone").focus().val("test").blur();'); $this->webDriver->action()->moveToElement($this->byId('phone'))->perform(); sleep(1); $this->elementWait('#phone + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($langData->gM->invalidPhone, $this->byCssSelector('#phone + div.errMsg')->getText()); // Invalid VAT specified $this->byId("vat_payer")->click(); $this->elementWait('vat_reg_nr'); $this->webDriver->action()->moveToElement($this->byId('vat_reg_nr'))->perform(); $this->webDriver->executeScript('$("#vat_reg_nr").focus().blur();'); $this->elementWait('#vat_reg_nr + div.errMsg', self::CSS_SELECTOR); $this->assertEquals($langData->gM->fieldIsMandatory, $this->byCssSelector('#vat_reg_nr + div.errMsg')->getText()); $this->byId("vat_payer")->click(); $this->elementWaitRemoved('vat_reg_nr'); $this->assertFalse($this->elementExists('#vat_payer.chked', self::CSS_SELECTOR)); // Radio check test $this->scrollElementIntoView('#document_system', self::CSS_SELECTOR); $this->assertFalse($this->elementExists('#document_system.chked', self::CSS_SELECTOR)); $this->byId("document_system")->click(); $this->assertFalse($this->elementExists('#full_system.chked', self::CSS_SELECTOR)); $this->byId("full_system")->click(); $this->byId("union_system")->click(); $this->assertTrue($this->elementExists('#union_system.chked', self::CSS_SELECTOR)); $this->byId("religious_org_system")->click(); $this->assertTrue($this->elementExists('#religious_org_system.chked', self::CSS_SELECTOR)); // Check agree to terms iframe - wait for iframe to reload $this->scrollElementIntoView('#show-terms', self::CSS_SELECTOR); $this->byCssSelector("a#show-terms")->click(); $this->elementWait('.fancybox-iframe', self::CSS_SELECTOR); $this->webDriver->switchTo()->frame($this->byCssSelector('.fancybox-iframe')); // Page weird animation cannot be caught via traditional wait conditions $this->elementWait('h1.animated', self::CSS_SELECTOR); $this->elementWait('#fh5co-home .row div.col-md-8 h1', self::CSS_SELECTOR); $this->assertEquals($langData->gM->agreeToTermsH1, $this->byCssSelector('h1')->getText()); $this->byId('close-terms-of-use')->click(); $this->webDriver->switchTo()->defaultContent(); $this->elementWaitRemoved('.fancybox-iframe', self::CSS_SELECTOR); // Check have already an account - wait for login iframe page to load $this->byCssSelector("div#loginchk")->click(); $this->elementWait('loginf'); $this->webDriver->switchTo()->frame($this->byId('loginf')); $this->elementWait('#form .relative p.font-20', self::CSS_SELECTOR); sleep(2); // Sleep while animation is complete $this->assertEquals($langData->gM->alreadyHaveAnAccount, $this->byCssSelector('#form .relative p.font-20')->getText()); $this->elementWait('#close-iframe', self::CSS_SELECTOR); $this->byId('close-iframe')->click(); $this->webDriver->switchTo()->defaultContent(); $this->elementWaitRemoved('loginf'); $this->elementWait('div#loginchk', self::CSS_SELECTOR); $this->assertFalse($this->elementExists('div#loginchk.chked', self::CSS_SELECTOR)); // Test if additional login form works $this->byCssSelector("div#loginchk")->click(); $this->elementWait('loginf'); $loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed); $this->webDriver->switchTo()->frame($this->byId('loginf')); $this->elementWait('#form .relative p.font-20', self::CSS_SELECTOR); sleep(2); // Sleep while animation is complete $this->assertEquals($langData->gM->alreadyHaveAnAccount, $this->byCssSelector('#form .relative p.font-20')->getText()); // Login user till Two-factor authentication pubUserLoginTest::logInUserByCredentials($this, pubUserLoginTest::url[$lang], $loginData); // 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); } $this->elementWaitRemoved('loginf'); $this->webDriver->switchTo()->defaultContent(); $this->elementWait('#registration-form a.logout', self::CSS_SELECTOR); $this->assertEquals($langData->gM->logoutUseDifferentUser, $this->byCssSelector('#registration-form a.logout')->getText()); $this->assertTrue($this->elementExists('div#loginchk.chked', self::CSS_SELECTOR)); // Test filled data match $this->assertEquals($loginData['user'], $this->byId('login')->getAttribute('value')); foreach (['name', 'surname', 'email', 'phone'] as $field) { $this->assertEquals($loginData[$field], $this->byId($field)->getAttribute('value')); } // Wait for the element to be clickable $this->elementWait('div#loginchk', self::CSS_SELECTOR); // Tick checkbox again - to remove input data $this->byCssSelector("div#loginchk")->click(); $this->elementWaitRemoved('#registration-form a.logout', self::CSS_SELECTOR); // Test filled data are empty $this->assertEquals('', $this->byId('login')->getAttribute('value')); foreach (['name', 'surname', 'email', 'phone'] as $field) { $this->assertEquals('', $this->byId($field)->getAttribute('value')); } } } public function testUserRegistrationCaseNew(): void { foreach ($this->pageData as $lang => $langData) { $this->goToRegistrationPage($langData); $inputData = [ 'acc_name' => 'Test ccount', 'reg_nr' => 'REG-ID123456789', 'name' => 'Mareks', 'surname' => 'Test 2', 'email' => 'keiss.mareks@gmail.com', 'phone' => '+37128639957' ]; // Fill data foreach ($inputData as $key => $value) { $this->byId($key)->clear()->sendKeys($value); } // Accept terms $this->byId("agree_to_terms")->click(); // Validate filled data $this->assertEquals($inputData['email'], $this->byId('login')->getAttribute('value')); // Send registration data $this->byCssSelector('input.btn.btn-primary')->click(); $this->waitUntilDomReadyState(); $this->assertFieldError('email', $langData->gM->invalidEMailAlreadyTaken); // Change e-mail & Perform registration action $this->sendKeysAndTriggerValidation('#email', 'keiss.mareks2@gmail.com', self::CSS_SELECTOR); // Send registration data $this->byCssSelector('input.btn.btn-primary')->click(); $this->elementWait('#registration-form .msg p', self::CSS_SELECTOR); $this->scrollElementIntoView('#registration-form .msg p', self::CSS_SELECTOR); $this->assertExpected($langData->gM->registrationComplete, $this->byTagName('body')->getText()); // Wait & get account activation e-mail confirmation // Create connection to MailHog // Sleep while e-mail is dispatched & get last message x2 - 2x CRON requests initiated - // 1. when requesting registration, 2nd when sending confirmation $messages = $this->awaitEmailFromMailHog( 'keiss.mareks2@gmail.com', $langData->gM->registrationEmailTitle, 60 * 5 ); // Validate mail content $this->assertEquals($langData->gM->registrationEmailTitle, $this->emailHtmlDecode($messages->subject)); $this->assertExpected($langData->gM->registrationEmailBody, $this->emailHtmlDecode($messages->body)); // Get password reset url from mail $doc = new DOMDocument(); $doc->loadHTML($messages->body); $xpath = new DOMXpath($doc); $activationUrl = $xpath->query("//a[@id='link']")->item(0)->attributes->item(0)->nodeValue; $path = parse_url($activationUrl, PHP_URL_PATH); $tempPassword = $xpath->query("//b[@id='pass']")->item(0)->nodeValue; $this->url($path); $this->waitUntilDomReadyState(); $this->assertExpected( $langData->gM->activationSuccessfullText, $this->byCssSelector('#act_ok')->getText() ); $this->assertTrue($this->elementExists('new_password')); $this->assertTrue($this->elementExists('rnew_password')); // Change user pwd $this->fillAndSubmitPasswordChangeForm([ 'oldPass' => $tempPassword, 'newPass' => 'testmynewpassword12!@' ]); // Wait for security update request form $this->elementWait('a.enable_2fa', self::CSS_SELECTOR); // Validate form data $this->assertExpected( $langData->gM->securityUpdateRequest, $this->byId('restricted-access')->getText(), true ); // Security request setup $this->awaitAndProceedWithSecuritySetupRequest(); // Wait for 2fa form $this->elementWait('div span#secret', self::CSS_SELECTOR); // Validate form data $this->assertExpected( $langData->gM->securityUpdate2FAForm, $this->byId('form')->getText() ); // Setup 2FA $this->awaitAndSetup2FASecurity(); // Validate dashboard welcome screen $this->elementWait("#drop_cnt > .doc > .form-data div.container.dashboard-cnt", self::CSS_SELECTOR); $this->assertTrue($this->elementExists('report_period_chosen')); } } public function testUserRegistrationAssociation(): void { $langData = $this->pageData[siteLanguages::LANG_LV]; $this->goToRegistrationPage($langData); $inputData = [ 'acc_name' => 'House management', 'reg_nr' => 'REG-ID123456789', 'name' => 'Mareks', 'surname' => 'Test 2', 'email' => 'keiss.mareks2@gmail.com', 'phone' => '+37128639957', 'system' => 'housem_system', ]; // Fill data foreach ($inputData as $key => $value) { if ($key === 'system') { $this->byId($value)->click(); } else { $this->byId($key)->clear()->sendKeys($value); } } // Accept terms $this->byId("agree_to_terms")->click(); // Validate filled data $this->assertEquals($inputData['email'], $this->byId('login')->getAttribute('value')); // Send registration data $this->byCssSelector('input.btn.btn-primary')->click(); $this->waitUntilDomReadyState(); $this->elementWait('#registration-form .msg p', self::CSS_SELECTOR); $this->scrollElementIntoView('#registration-form .msg p', self::CSS_SELECTOR); $this->assertExpected($langData->gM->registrationComplete, $this->byTagName('body')->getText()); // Wait & get account activation e-mail confirmation // Create connection to MailHog // Sleep while e-mail is dispatched & get last message x2 - 2x CRON requests initiated - // 1. when requesting registration, 2nd when sending confirmation $messages = $this->awaitEmailFromMailHog( 'keiss.mareks2@gmail.com', $langData->gM->registrationEmailTitle, 60 * 5 ); // Validate mail content $this->assertEquals($langData->gM->registrationEmailTitle, $this->emailHtmlDecode($messages->subject)); $this->assertExpected($langData->gM->registrationEmailBody, $this->emailHtmlDecode($messages->body)); // Get password reset url from mail $doc = new DOMDocument(); $doc->loadHTML($messages->body); $xpath = new DOMXpath($doc); $activationUrl = $xpath->query("//a[@id='link']")->item(0)->attributes->item(0)->nodeValue; $path = parse_url($activationUrl, PHP_URL_PATH); $tempPassword = $xpath->query("//b[@id='pass']")->item(0)->nodeValue; $this->url($path); $this->waitUntilDomReadyState(); $this->assertExpected( $langData->gM->activationSuccessfullText, $this->byCssSelector('#act_ok')->getText() ); $this->assertTrue($this->elementExists('new_password')); $this->assertTrue($this->elementExists('rnew_password')); // Change user pwd $this->fillAndSubmitPasswordChangeForm([ 'oldPass' => $tempPassword, 'newPass' => 'asdasd' ]); // Wait for security update request form $this->elementWait('a.enable_2fa', self::CSS_SELECTOR); // Validate form data $this->assertExpected( $langData->gM->securityUpdateRequest, $this->byId('restricted-access')->getText(), true ); // Security request setup $this->awaitAndProceedWithSecuritySetupRequest(); // Wait for 2fa form $this->elementWait('div span#secret', self::CSS_SELECTOR); // Validate form data $this->assertExpected( $langData->gM->securityUpdate2FAForm, $this->byId('form')->getText() ); // Setup 2FA $this->awaitAndSetup2FASecurity(); // Validate dashboard welcome screen $this->elementWait("#drop_cnt > .doc > .form-data div.container.dashboard-cnt", self::CSS_SELECTOR); $this->assertTrue($this->elementExists($this->getMenuItemSelectXpathByTitle('Apsaimniekošana'), self::XPATH)); } /* public function testLoginPageRedirectLinks(): void { foreach (self::url as $lang => $pageData) { $this->url($pageData['url']); $this->elementWait('user_login'); // Test pages clicks $pagesToVisit = []; $links = $this->webDriver->findElements(WebDriverBy::cssSelector('#frm_input > a.link')); foreach ($links as $link) { $pagesToVisit[] = $link->getAttribute('href'); } foreach ($pagesToVisit as $href) { if (isset($pageData['linksToTexts'][$href])) { $this->url($this->normalizeUrl($href)); sleep(2); // Element Wait fails for some unknown reason if (isset($pageData['linksToTexts'][$href]['wait_id'])) $this->elementWait($pageData['linksToTexts'][$href]['wait_id']); elseif (isset($pageData['linksToTexts'][$href]['wait_tag'])) $this->elementWait($pageData['linksToTexts'][$href]['wait_tag'], self::TAG_NAME); $this->assertEquals($pageData['linksToTexts'][$href]['text'], $this->byCssSelector($pageData['linksToTexts'][$href]['text_selector'])->getText()); } } } }*/ public function testRegistrationPageLoaded(): void { foreach ($this->pageData as $lang => $langData) { $this->url($langData->url); $this->awaitAndAcceptCookies(); $this->elementWait($langData->menuItemXPath, self::XPATH); $this->byXPath($langData->menuItemXPath)->click(); sleep(2); $this->elementWait('h1.to-animate', self::CSS_SELECTOR); foreach ($langData->elementsExist as $selectorToFind) { $this->assertTrue($this->elementExists($selectorToFind, self::CSS_SELECTOR)); } $this->assertExpected($langData->gM->messagesExist, $this->byTagName('body')->getText()); } } private function goToRegistrationPage(stdClass $langData = null): void { $this->url($langData->url); $this->awaitAndAcceptCookies(); $this->elementWait($langData->menuItemXPath, self::XPATH); $this->byXPath($langData->menuItemXPath)->click(); $this->pageTitleWait($langData->gM->registration); sleep(2); $this->elementWait('h1.to-animate', self::CSS_SELECTOR); } }