diff options
author | Stefan Giehl <stefan@matomo.org> | 2021-09-01 16:37:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-01 16:37:38 +0300 |
commit | a3ee690ea3863ff16a828ac0afbc77243bb45f5b (patch) | |
tree | 77f3341e86608894b1020725700b348bbcd44567 /plugins/TwoFactorAuth | |
parent | ba1facfd1ecb4e618f3162aedbdb3170e9461e50 (diff) |
Use newer version of Puppeteer for UI tests (#17880)
* Use latest version of Puppeteer for UI tests
* use newer node on travis
* test
* use waitForTimeout / waitForSelector instead of waitFor
* Handle BC for removed waitFor method
* Updates expected UI test files
* update submodules
* improve/fix some UI tests
* Updates expected UI test files
* improve/fix some UI tests
* update url-parse dependency
* simplify some UI tests
* update screenshot
* avoid using merged assets that are broken
* fix expected compare exit code
* don't use merged assets for TwoFactorAuth UI tests
it seems due to too many requests to login, logout and other pages merging the CoreJS assets somehow fails, and results in returning an empty file. Even the reload fails to serve the correct content, so maybe the file, the content should be written to, is somehow locked. Disabling the merged assets seems to fix this issue for this tests. Locally the tests are also running correctly with merged assets.
* improve handling of automatic css / js reloading in UI tests
* increase timeouts of TwoFactorAuth UI tests
* fix 2fa ui test
* revert change
* update new screenshot
* updates UI screenshots
* submodule updates
Diffstat (limited to 'plugins/TwoFactorAuth')
14 files changed, 86 insertions, 69 deletions
diff --git a/plugins/TwoFactorAuth/tests/UI/TwoFactorAuthUsersManager_spec.js b/plugins/TwoFactorAuth/tests/UI/TwoFactorAuthUsersManager_spec.js index a426289eb5..30b2e8a6e6 100644 --- a/plugins/TwoFactorAuth/tests/UI/TwoFactorAuthUsersManager_spec.js +++ b/plugins/TwoFactorAuth/tests/UI/TwoFactorAuthUsersManager_spec.js @@ -35,22 +35,22 @@ describe("TwoFactorAuthUsersManager", function () { await page.evaluate(function () { $('.userEditForm .menuUserTwoFa a').click(); }); - await page.waitFor(250); - await page.waitFor('.twofa-reset > p', { visible: true }); + await page.waitForTimeout(250); + await page.waitForSelector('.twofa-reset > p', { visible: true }); expect(await page.screenshotSelector('#content,#notificationContainer')).to.matchImage('edit_with_2fa'); }); it('should ask for confirmation before resetting 2fa', async function () { await page.click('.userEditForm .twofa-reset .resetTwoFa .btn'); - const modal = await page.waitFor('.modal.open', { visible: true }); - await page.waitFor(1000); // animation + const modal = await page.waitForSelector('.modal.open', { visible: true }); + await page.waitForTimeout(1000); // animation expect(await modal.screenshot()).to.matchImage('edit_with_2fa_reset_confirm'); }); it('should be possible to confirm the reset', async function () { await page.type('.twofa-confirm-modal input[name=currentUserPassword]', 'superUserPass'); await page.click('.twofa-confirm-modal .modal-close:not(.modal-no)'); - await page.waitFor(500); // wait for modal to close + await page.waitForTimeout(500); // wait for modal to close expect(await page.screenshotSelector('#content,#notificationContainer')).to.matchImage('edit_with_2fa_reset_confirmed'); }); diff --git a/plugins/TwoFactorAuth/tests/UI/TwoFactorAuth_spec.js b/plugins/TwoFactorAuth/tests/UI/TwoFactorAuth_spec.js index 60f57eb093..8608118bab 100644 --- a/plugins/TwoFactorAuth/tests/UI/TwoFactorAuth_spec.js +++ b/plugins/TwoFactorAuth/tests/UI/TwoFactorAuth_spec.js @@ -21,6 +21,8 @@ describe("TwoFactorAuth", function () { { await (await page.jQuery('.modal.open .modal-footer a:contains('+button+')')).click(); await page.waitForNetworkIdle(); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); } async function loginUser(username, doAuth) @@ -30,6 +32,9 @@ describe("TwoFactorAuth", function () { // make sure to log out previous session await page.goto(logoutUrl); + await page.waitForNetworkIdle(); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); var cookies = await page.cookies(); cookies.forEach(cookie => { @@ -40,13 +45,22 @@ describe("TwoFactorAuth", function () { doAuth = true; } var logMeUrl = '?module=Login&action=logme&login=' + username + '&password=240161a241087c28d92d8d7ff3b6186b'; + + // avoid loading dashboard after login as it takes long + logMeUrl += '&url=' + encodeURIComponent('index.php?category=General_Visitors&subcategory=Live_VisitorLog&' + generalParams); + if (doAuth) { logMeUrl += '&authCode=123456'; // we make sure in test config this code always works } - await page.waitFor(1000); await page.goto(logMeUrl); await page.waitForNetworkIdle(); - await page.waitFor(1000); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); + + await page.webpage.setViewport({ + width: 1350, + height: 768, + }); } function requireTwoFa() { @@ -68,6 +82,7 @@ describe("TwoFactorAuth", function () { beforeEach(function () { testEnvironment.testUseMockAuth = 0; testEnvironment.restoreRecoveryCodes = 1; + testEnvironment.configOverride = { Development: { disable_merged_assets: 1 }}; testEnvironment.save(); }); @@ -82,26 +97,26 @@ describe("TwoFactorAuth", function () { async function confirmPassword() { - await page.waitFor('.confirmPasswordForm'); - await page.waitFor(() => !!window.$); - await page.evaluate(function(){ - $('.confirmPasswordForm #login_form_password').val('123abcDk3_l3'); - $('.confirmPasswordForm #login_form_submit').click(); - }); + await page.waitForSelector('.confirmPasswordForm'); + await page.waitForNetworkIdle(); + await page.type('.confirmPasswordForm #login_form_password', '123abcDk3_l3'); + await page.click('.confirmPasswordForm #login_form_submit'); + await page.waitForNetworkIdle(); + await page.waitForTimeout(100); await page.waitForNetworkIdle(); - await page.waitFor(100); } it('a user with 2fa can open the widgetized view by token without needing to verify', async function () { await page.goto('?module=Widgetize&action=iframe&moduleToWidgetize=Actions&actionToWidgetize=getPageUrls&date=2018-03-04&token_auth=a4ca4238a0b923820dcc509a6f75849b&' + generalParams); - const element = await page.$('.widget'); - expect(await element.screenshot()).to.matchImage('widgetized_no_verify'); + + // check if widget element is present, if login wouldn't work the login screen would be shown instead + const widgetsCount = await page.evaluate(() => $('.widget').length); + expect(widgetsCount).to.equal(1); }); it('when logging in through logme and not providing auth code it should show auth code screen', async function () { await loginUser('with2FA', false); - await page.waitFor(1000); - const section = await page.$('.loginSection'); + const section = await page.waitForSelector('.loginSection'); expect(await section.screenshot()).to.matchImage('logme_not_verified'); }); @@ -111,7 +126,7 @@ describe("TwoFactorAuth", function () { document.querySelector('.loginTwoFaForm #login_form_submit').click(); }); await page.waitForNetworkIdle(); - const element = await page.$('.loginSection'); + const element = await page.waitForSelector('.loginSection'); expect(await element.screenshot()).to.matchImage('logme_not_verified_wrong_code'); }); @@ -120,23 +135,21 @@ describe("TwoFactorAuth", function () { testEnvironment.save(); await page.type('.loginTwoFaForm #login_form_authcode', '123456'); - await page.waitFor(() => !!window.$); - await page.evaluate(function(){ - document.querySelector('.loginTwoFaForm #login_form_submit').click(); - }); + await page.click('.loginTwoFaForm #login_form_submit'); await page.waitForNetworkIdle(); - await page.waitFor('.widget'); + await page.waitForSelector('.widget', { timeout: 60000 }); await page.waitForNetworkIdle(); - const element = await page.$('.pageWrap'); - expect(await element.screenshot()).to.matchImage('logme_verified'); + // do not take a screenshot, as it's not relevant. We only check if there is the right amount of widgets loaded + const widgetsCount = await page.evaluate(() => $('.widget').length); + expect(widgetsCount).to.equal(9); }); it('should show user settings when two-fa enabled', async function () { await loginUser('with2FA'); await page.goto(userSettings); - await page.waitFor('.userSettings2FA', { visible: true, timeout: 0 }); - await page.waitFor(750); // animation + await page.waitForSelector('.userSettings2FA', { visible: true, timeout: 0 }); + await page.waitForTimeout(1000); // animation const elem = await page.$('.userSettings2FA'); expect(await elem.screenshot()).to.matchImage('usersettings_twofa_enabled'); }); @@ -145,36 +158,39 @@ describe("TwoFactorAuth", function () { await page.click('.showRecoveryCodesLink'); await page.waitForNetworkIdle(); const element = await page.$('.loginSection'); + await page.waitForNetworkIdle(); + await page.waitForTimeout(1000); expect(await element.screenshot()).to.matchImage('show_recovery_codes_step1'); }); it('should be possible to show recovery codes step2 done', async function () { await confirmPassword(); - await page.waitForNetworkIdle(); - const element = await page.$('#content'); - expect(await element.screenshot()).to.matchImage('show_recovery_codes_step2'); + expect(await page.screenshotSelector('#content')).to.matchImage('show_recovery_codes_step2'); }); it('should show user settings when two-fa enabled', async function () { requireTwoFa(); await page.goto(userSettings); - const element = await page.$('.userSettings2FA'); - expect(await element.screenshot()).to.matchImage('usersettings_twofa_enabled_required'); + await page.waitForTimeout(1000); + expect(await page.screenshotSelector('.userSettings2FA')).to.matchImage('usersettings_twofa_enabled_required'); }); it('should be possible to disable two factor', async function () { await loginUser('with2FADisable'); await page.goto(userSettings); + await page.waitForSelector('.disable2FaLink', { timeout: 60000 }); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); await page.click('.disable2FaLink'); const modal = await page.$('.modal.open'); - await page.waitFor(250); // animation + await page.waitForTimeout(500); // animation expect(await modal.screenshot()).to.matchImage('usersettings_twofa_disable_step1'); }); it('should be possible to disable two factor step 2 confirmed', async function () { await selectModalButton('Yes'); - await page.waitFor(150); + await page.waitForTimeout(150); const element = await page.$('.loginSection'); expect(await element.screenshot()).to.matchImage('usersettings_twofa_disable_step2'); @@ -182,7 +198,7 @@ describe("TwoFactorAuth", function () { it('should be possible to disable two factor step 3 verified', async function () { await confirmPassword(); - await page.waitFor('.userSettings2FA'); + await page.waitForSelector('.userSettings2FA'); const elem = await page.$('.userSettings2FA'); expect(await elem.screenshot()).to.matchImage('usersettings_twofa_disable_step3'); }); @@ -190,9 +206,11 @@ describe("TwoFactorAuth", function () { it('should show setup screen - step 1', async function () { await loginUser('without2FA'); await page.goto(userSettings); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); await page.click('.enable2FaLink'); await confirmPassword(); - await page.waitFor(1000); + await page.waitForTimeout(1000); const element = await page.$('#content'); expect(await element.screenshot()).to.matchImage('twofa_setup_step1'); }); @@ -214,7 +232,7 @@ describe("TwoFactorAuth", function () { it('should move to third step in setup - step 3', async function () { await page.click('.setupTwoFactorAuthentication .goToStep3'); await page.waitForNetworkIdle(); - await page.waitFor(1000); + await page.waitForTimeout(1000); const element = await page.$('#content'); expect(await element.screenshot()).to.matchImage('twofa_setup_step3'); @@ -230,7 +248,7 @@ describe("TwoFactorAuth", function () { $('.setupConfirmAuthCodeForm .confirmAuthCode').click(); }); await page.waitForNetworkIdle(); - await page.waitFor('#content', { visible: true }); + await page.waitForSelector('#content', { visible: true, timeout: 60000 }); await page.waitForNetworkIdle(); const element = await page.$('#content'); expect(await element.screenshot()).to.matchImage('twofa_setup_step4'); @@ -245,15 +263,18 @@ describe("TwoFactorAuth", function () { it('should force user to setup 2fa when not set up yet but enforced step 2', async function () { await (await page.jQuery('.setupTwoFactorAuthentication .backupRecoveryCode:first')).click(); await page.click('.setupTwoFactorAuthentication .goToStep2'); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); await page.mouse.move(-10, -10); - await page.waitFor(100); + await page.waitForTimeout(100); expect(await page.screenshotSelector('.loginSection,#content,#notificationContainer')).to.matchImage('twofa_forced_step2'); }); it('should force user to setup 2fa when not set up yet but enforced step 3', async function () { await page.click('.setupTwoFactorAuthentication .goToStep3'); + await page.waitForTimeout(100); + await page.waitForNetworkIdle(); await page.mouse.move(-10, -10); - await page.waitFor(100); expect(await page.screenshotSelector('.loginSection,#content,#notificationContainer')).to.matchImage('twofa_forced_step3'); }); @@ -268,7 +289,12 @@ describe("TwoFactorAuth", function () { $('.setupConfirmAuthCodeForm .confirmAuthCode').click(); }); await page.waitForNetworkIdle(); - expect(await page.screenshotSelector('.loginSection,#content,#notificationContainer')).to.matchImage('twofa_forced_step4'); + await page.waitForSelector('.widget'); + await page.waitForNetworkIdle(); + + // after setting up forced 2fa, the default page will be loaded (dashboard) + const widgetsCount = await page.evaluate(() => $('.widget').length); + expect(widgetsCount).to.equal(9); }); });
\ No newline at end of file diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa.png index a649c1f566..00b3177b19 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5f5d14bf5b773d0b92f80ce2d27bdbc10b3b7013f33847d83464162fa3bac827 -size 30303 +oid sha256:dfb6da1208f08bbde331b2574b7d39e945fdee4875f700eea6bccfd088ba0798 +size 30272 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa_reset_confirmed.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa_reset_confirmed.png index f99a39dbbf..ce0f28d108 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa_reset_confirmed.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_edit_with_2fa_reset_confirmed.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3b8feec74a212f4643e059ef8e08ab5daf62d009293613c7180e746b80baee37 -size 33939 +oid sha256:cb7e81d0f1a1e4e227d81839ae30c46d8c52907ab18b1bf413f34958ee479617 +size 33937 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_list.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_list.png index 2d1dd1e5f8..4890953f85 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_list.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuthUsersManager_list.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:11f13087ff3f980c9ce8c8c90d86a4aec695a55f3f84af4bdb835f622dc5e252 -size 58618 +oid sha256:3bba934644a119b01e4eda56b4261d0087a638dd607fb3dd57d81ca886f1352d +size 58963 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png deleted file mode 100644 index e4f5bea535..0000000000 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_logme_verified.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3c5b3611278ddefdf25b172f6f908a7d1a3ee2b21e7c8e64f00515f41eb0148d -size 181837 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_show_recovery_codes_step2.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_show_recovery_codes_step2.png index db073a39d4..7c3fe4293c 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_show_recovery_codes_step2.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_show_recovery_codes_step2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:317088e10aab29f589041e3b7c70c03f8f95f7fd03d16f3be012318d45e3831d -size 60515 +oid sha256:5e6cd69059dc9ddab922f00acdc798346d308ee7e0c0128f29e052c4d1d39f0b +size 60377 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step1.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step1.png index a94980cb40..6ef0195023 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step1.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a08a4516addbfa086231fec5e44f7a79a3f00e7c308a176e2475cd3efad99238 -size 92541 +oid sha256:e20d431ded80bf04f6c261d237e7599719af8eabac3821e3688ae6f17633da00 +size 92532 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step3.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step3.png index d9b6b2d11f..2c4894f065 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step3.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step3.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1d5ac43111252e3f119176bc4bc2e542fadf3134fba705b931d7d79b7e62ea6a -size 162365 +oid sha256:857005b9df442b2e755f8a969f55c167aa7f44e91e154ddd470c29d3b9723c77 +size 162355 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png deleted file mode 100644 index 1d327444bb..0000000000 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_forced_step4.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:72b20c28ef808581019beb6bed33c556b64bc9c905cffd6bf9dd7975414f40d4 -size 180835 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step1.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step1.png index 40698c6f2b..6f9b490fcf 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step1.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c2ac087bfb9043b707de3d5d37ff50a09039d2b3f6c70732bda97a6afd2304e1 -size 67133 +oid sha256:b5652c92627d5e36e653847fc1978e26885b8c35ab8591d538feeed68ff67e0b +size 67109 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step3.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step3.png index 903a041bc9..cf227b0622 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step3.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_twofa_setup_step3.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f890cdf67f6afc830a0a1705be2341d17a7130a9d83b0b16bf1a31825cbf27ed -size 114325 +oid sha256:52ec37f081e5a1b1624cf3f93551550cd87a97ae5eafc1c75b8fcefc39f2c68a +size 114302 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_usersettings_twofa_enabled.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_usersettings_twofa_enabled.png index d1df1b1827..79a6b8b3a0 100644 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_usersettings_twofa_enabled.png +++ b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_usersettings_twofa_enabled.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d7cdec9f2212374664e5e79f63e3e687e2c645c7a1c65f48661cd40ef2bdf40 -size 47304 +oid sha256:1fc401f84f8ae04fba130470f7e0f1708f9b3ae38556478592173f538a0452b5 +size 47350 diff --git a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_widgetized_no_verify.png b/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_widgetized_no_verify.png deleted file mode 100644 index 7b907f04bf..0000000000 --- a/plugins/TwoFactorAuth/tests/UI/expected-screenshots/TwoFactorAuth_widgetized_no_verify.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:668bf4024f7d8a7fe60fdeaf5eb11b8b78937b60f16fa8fdae61a361d55f5a56 -size 5148 |