From 7f1efba2b3022d8e813def9872df01482b06887b Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Wed, 3 Jul 2024 15:28:13 +0800 Subject: [PATCH] fix: need to intentionally click sort button when Cypress editAccount. Change "visible" to "exist". --- cypress/e2e/accountAdmin/editAccount.cy.js | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/accountAdmin/editAccount.cy.js b/cypress/e2e/accountAdmin/editAccount.cy.js index 9297974..130ecf8 100644 --- a/cypress/e2e/accountAdmin/editAccount.cy.js +++ b/cypress/e2e/accountAdmin/editAccount.cy.js @@ -1,6 +1,14 @@ -const TEST_ACCOUNT = 'tester-user'; +const TEST_ACCOUNT = '000000'; const MODAL_TITLE_ACCOUNT_EDIT = 'Account Edit'; const MSG_ACCOUNT_EDITED = 'Saved'; +const NUM_OF_SCROLLS = 5; + +Cypress.Commands.add('manualScrollToBottom', (repeats = 20) => { + for (let i = 0; i < repeats; i++) { + cy.scrollTo('bottom', { duration: 500 }); + cy.wait(500); + } +}); describe('Edit an account', ()=>{ beforeEach(() => { @@ -16,19 +24,27 @@ describe('Edit an account', ()=>{ }); it('Edit an account; modify name and see saved message.', () => { - cy.contains('.account-cell', TEST_ACCOUNT, { timeout: 10000 }).should('be.visible'); + // 為了讓帳號出現,必須不斷往下滾動捲軸 + for(let i = 0; i < NUM_OF_SCROLLS; i++) { + cy.get('#acct_mgmt_data_grid').scrollTo('bottom'); + cy.wait(500); + } + + + // 由於可能在畫面上是 hidden ,這邊使用 exist 而不是使用 visible + cy.contains('.account-cell', TEST_ACCOUNT, { timeout: 10000 }).should('be.exist'); // 找到包含 TEST_ACCOUNT 字串的 .account-cell 元素 cy.contains('.account-cell', TEST_ACCOUNT, { timeout: 10000 }) .parents('tr') // 找到 .account-cell 元素的祖先 tr 元素 .find('.btn-edit') // 在該 tr 元素內找到 .btn-edit 按鈕 - .should('be.visible') // 驗證該按鈕可見 + .should('be.exist') // 驗證該按鈕可見 .click(); // 點擊該按鈕 - cy.contains('h1', MODAL_TITLE_ACCOUNT_EDIT).should('be.visible'); + cy.contains('h1', MODAL_TITLE_ACCOUNT_EDIT).should('be.exist'); const randomNumber = Math.floor(Math.random() * 1001); // 將整數轉換為四位數字串,並補零 const fourDigitString = randomNumber.toString().padStart(4, '0'); - cy.get('#input_name_field').type( TEST_ACCOUNT + fourDigitString); + cy.get('#input_name_field').clear().type( TEST_ACCOUNT + '-' + fourDigitString); cy.get('#input_first_pwd').type('aaaaaa'); cy.get('#input_second_pwd').type('aaaaaa');