From ba6450d4a0995b5fbd4a9ce6808d432755e37c54 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Wed, 3 Jul 2024 14:06:05 +0800 Subject: [PATCH] Cypress: confirm password message --- .../accountAdmin/confirmPasswordMessage.cy.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 cypress/e2e/accountAdmin/confirmPasswordMessage.cy.js diff --git a/cypress/e2e/accountAdmin/confirmPasswordMessage.cy.js b/cypress/e2e/accountAdmin/confirmPasswordMessage.cy.js new file mode 100644 index 0000000..2d3aa4e --- /dev/null +++ b/cypress/e2e/accountAdmin/confirmPasswordMessage.cy.js @@ -0,0 +1,43 @@ +const MSG_PWD_NOT_MATCHED = 'Confirm Password does not match.'; + +describe('Confirm that two input passwords are equal.', ()=>{ + beforeEach(() => { + cy.visit('https://REDACTED-HOST/account/account-admin'); + const username = 'cindy'; + const password = 'REDACTED-PWD'; + + cy.visit('https://REDACTED-HOST/account/account-admin'); + + cy.get('input[id="account"]').type(username); + cy.get('input[id="password"]').type(password); + cy.get('button[type="submit"]').click(); + }); + + it('Confirm that when creating an account, the two input password fields are equal; otherwise, show the message.', () => { + cy.contains('button', 'Create New').should('be.visible'); + cy.contains('button', 'Create New').click(); + + const randomNumber = Math.floor(Math.random() * 1001); + + // 將整數轉換為四位數字串,並補零 + const fourDigitString = randomNumber.toString().padStart(4, '0'); + + // 將 'unit-test-' 和生成的四位數字串組合 + const inputValue = `unit-test-${fourDigitString}`; + + // 在 id 為 input_account_field 的 input 元素內填入值 + cy.get('#input_account_field').type(inputValue); + cy.get('#input_name_field').type(inputValue); + cy.get('#input_first_pwd').type('aaaaaa'); + cy.get('#input_second_pwd').type('bbbbbb'); + + // 確保 Confirm 按鈕存在並可點擊 + cy.contains('button', 'Confirm') + .should('be.visible') + .and('be.enabled') + .click(); + + cy.contains(MSG_PWD_NOT_MATCHED).should('be.visible'); + }); +}); + \ No newline at end of file