diff --git a/packages/functional-tests/pages/login.ts b/packages/functional-tests/pages/login.ts index 6e568ace79..77fd414ea1 100644 --- a/packages/functional-tests/pages/login.ts +++ b/packages/functional-tests/pages/login.ts @@ -26,6 +26,14 @@ export const selectors = { VPASSWORD: '#vpassword', SYNC_CONNECTED_HEADER: '#fxa-connected-heading', NOTES_HEADER: '#notes-by-firefox', + MIN_LENGTH_MET: '#password-too-short.password-strength-met', + MIN_LENGTH_FAIL: '#password-too-short.password-strength-fail', + NOT_COMMON_FAIL: '#password-too-common.password-strength-fail', + NOT_COMMON_UNMET: '#password-too-common.password-strength-unmet', + NOT_COMMON_MET: '#password-too-common.password-strength-met', + NOT_EMAIL_UNMET: '#password-same-as-email.password-strength-unmet', + NOT_EMAIL_MET: '#password-same-as-email.password-strength-met', + NOT_EMAIL_FAIL: '#password-same-as-email.password-strength-fail', }; export class LoginPage extends BaseLayout { @@ -56,6 +64,14 @@ export class LoginPage extends BaseLayout { TOOLTIP: '.tooltip', VPASSWORD: '#vpassword', SYNC_CONNECTED_HEADER: '#fxa-connected-heading', + MIN_LENGTH_MET: '#password-too-short.password-strength-met', + MIN_LENGTH_FAIL: '#password-too-short.password-strength-fail', + NOT_COMMON_FAIL: '#password-too-common.password-strength-fail', + NOT_COMMON_UNMET: '#password-too-common.password-strength-unmet', + NOT_COMMON_MET: '#password-too-common.password-strength-met', + NOT_EMAIL_UNMET: '#password-same-as-email.password-strength-unmet', + NOT_EMAIL_MET: '#password-same-as-email.password-strength-met', + NOT_EMAIL_FAIL: '#password-same-as-email.password-strength-fail', }; get emailHeader() { @@ -108,6 +124,54 @@ export class LoginPage extends BaseLayout { } } + async minLengthFailError() { + const error = this.page.locator(this.selectors.MIN_LENGTH_FAIL); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async minLengthSuccess() { + const error = this.page.locator(this.selectors.MIN_LENGTH_MET); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async notEmailUnmetError() { + const error = this.page.locator(this.selectors.NOT_EMAIL_UNMET); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async notEmailFailError() { + const error = this.page.locator(this.selectors.NOT_EMAIL_FAIL); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async notEmailSuccess() { + const error = this.page.locator(this.selectors.NOT_EMAIL_MET); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async notCommonPasswordUnmetError() { + const error = this.page.locator(this.selectors.NOT_COMMON_UNMET); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async notCommonPasswordSuccess() { + const error = this.page.locator(this.selectors.NOT_COMMON_MET); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + + async notCommonPasswordFailError() { + const error = this.page.locator(this.selectors.NOT_COMMON_FAIL); + await error.waitFor({ state: 'visible' }); + return error.isVisible(); + } + async fillOutFirstSignUp( email: string, password: string, diff --git a/packages/functional-tests/tests/settings/password.spec.ts b/packages/functional-tests/tests/settings/password.spec.ts index 4b43b504c8..3bff46d64e 100644 --- a/packages/functional-tests/tests/settings/password.spec.ts +++ b/packages/functional-tests/tests/settings/password.spec.ts @@ -57,3 +57,73 @@ test.describe('severity-1 #smoke', () => { expect(status).toEqual('Not Set'); }); }); + +test.describe('password strength tests', () => { + test.beforeEach(async ({ target, credentials, page, pages: { login } }) => { + const email = login.createEmail(); + await page.goto(target.contentServerUrl, { waitUntil: 'networkidle' }); + credentials.email = email; + + //Enter email at email first and then goto the sign up page + await login.setEmail(credentials.email); + await login.submit(); + }); + + test('test different password errors and success', async ({ + credentials, + pages: { login }, + }) => { + //Submit without providing a password + await login.submitButton.click(); + + //Verify the error + expect(await login.minLengthFailError()).toBe(true); + expect(await login.notEmailUnmetError()).toBe(true); + expect(await login.notCommonPasswordUnmetError()).toBe(true); + + //Submit a short password + await login.setPassword('p'); + await login.submitButton.click(); + + //Verify the error + expect(await login.minLengthFailError()).toBe(true); + expect(await login.notEmailUnmetError()).toBe(true); + expect(await login.notCommonPasswordUnmetError()).toBe(true); + + //Submit a common password + await login.setPassword('password'); + await login.submitButton.click(); + + //Verify the error + expect(await login.minLengthSuccess()).toBe(true); + expect(await login.notEmailSuccess()).toBe(true); + expect(await login.notCommonPasswordFailError()).toBe(true); + + //Submit password same as email + await login.setPassword(credentials.email); + await login.submitButton.click(); + + //Verify the error + expect(await login.minLengthSuccess()).toBe(true); + expect(await login.notEmailFailError()).toBe(true); + expect(await login.notCommonPasswordUnmetError()).toBe(true); + + //Submit password same as local part of email + const newEmail = credentials.email.split('@')[0]; + await login.setPassword(newEmail); + await login.submitButton.click(); + + //Verify the error + expect(await login.minLengthSuccess()).toBe(true); + expect(await login.notEmailFailError()).toBe(true); + expect(await login.notCommonPasswordUnmetError()).toBe(true); + + //Submit a common password + await login.setPassword('password123123'); + + //Verify the success message + expect(await login.minLengthSuccess()).toBe(true); + expect(await login.notEmailSuccess()).toBe(true); + expect(await login.notCommonPasswordSuccess()).toBe(true); + }); +});