From c86163fd101553d56d9280b363d18b1ef80877eb Mon Sep 17 00:00:00 2001 From: Annie Huang Date: Mon, 13 Nov 2023 15:19:54 +0800 Subject: [PATCH] Update tests: - Add public command to press enter until story end - Add public command to check status pending --- tests/cypress/e2e/helloworld.cy.js | 33 +++++++++++++++--------------- tests/cypress/support/commands.js | 21 ++++++++++++++++++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/tests/cypress/e2e/helloworld.cy.js b/tests/cypress/e2e/helloworld.cy.js index d6b097e..cbdd011 100644 --- a/tests/cypress/e2e/helloworld.cy.js +++ b/tests/cypress/e2e/helloworld.cy.js @@ -1,5 +1,4 @@ /// - export default function checkLoginUI() { cy.get('h1.text-text-primary') .should('contain', 'Linux Odyssey') @@ -49,6 +48,12 @@ describe('example helloworld app', () => { 'be.visible' ) }) + it('Check login fail', () => { + cy.LoginWithPassword('dddd', '123456') + cy.get('p').contains('Wrong username or password.').should('be.visible') + cy.LoginWithPassword(`ddd\``, '123456') + cy.get('p').contains('Invalid username or password.').should('be.visible') + }) it('Login-Password Already Register', () => { cy.LoginWithPassword( Cypress.env('defaultAccount'), @@ -64,6 +69,8 @@ describe('example helloworld app', () => { cy.findByRole('button', { name: 'Hello, Linux World!' }).should( 'be.visible' ) + cy.findByRole('link', { name: 'Bug Report' }).should('be.visible') + cy.findByRole('button', { name: 'Sign Out' }).should('be.visible') }) it('Check QuestInfo', () => { cy.get('#topic').should('contain', 'Hello, Linux World!') @@ -128,10 +135,8 @@ describe('example helloworld app', () => { // Stage1 cy.log('Stage1') cy.typeInCommand(answerarr[0]) - cy.get('input[id="currentStatus"]', { timeout: 1000000 }).should( - 'have.value', - 'active' - ) + cy.checkPending() + cy.waitUntilActive() cy.get('#Lbutton').should('be.visible').and('be.disabled') cy.get('#Rbutton').should('be.visible').and('be.disabled') cy.checkHint(1, 1) @@ -140,10 +145,8 @@ describe('example helloworld app', () => { // Stage2 cy.log('Stage2') cy.typeInCommand(answerarr[1]) - cy.get('input[id="currentStatus"]', { timeout: 1000000 }).should( - 'have.value', - 'active' - ) + cy.checkPending() + cy.waitUntilActive() cy.get('#tree') .get('a') .should('contain', 'forgotten_scroll.txt') @@ -158,20 +161,16 @@ describe('example helloworld app', () => { // Stage3 cy.log('Stage3') cy.typeInCommand(answerarr[2]) - cy.get('input[id="currentStatus"]', { timeout: 1000000 }).should( - 'have.value', - 'active' - ) + cy.checkPending() + cy.waitUntilActive() cy.getQuestInfo('✓ 查看卷軸').should('be.visible') cy.getQuestInfo('解除封印').should('be.visible') cy.checkHint(3, 3) // Stage4 cy.log('Stage4') cy.typeInCommand(answerarr[3]) - cy.get('input[id="currentStatus"]', { timeout: 1000000 }).should( - 'have.value', - 'active' - ) + cy.checkPending() + cy.waitUntilActive() cy.getQuestInfo('✓ 解除封印').should('be.visible') cy.findByRole( 'heading', diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index fac1858..2e58468 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -27,7 +27,8 @@ Cypress.Commands.add('typeInCommand', (command) => { Cypress.Commands.add('getQuestInfo', (id) => { return cy .get('#quest') - .find('p.text-text') + .find('li') + .find('p') .contains(`${id}`, { timeout: 100000 }) }) Cypress.Commands.add('checkHint', (index, total) => { @@ -36,3 +37,21 @@ Cypress.Commands.add('checkHint', (index, total) => { .contains(`${index}/${total}`) .should('be.visible') }) +Cypress.Commands.add('waitUntilActive', () => { + cy.get('input[id="currentStatus"]', { timeout: 1000000 }) + .invoke('val') + .then((value) => { + if (value === 'active' || value === 'finished') { + cy.log('story ends') + return + } + cy.typeInCommand('{enter}') + cy.waitUntilActive() + }) +}) +Cypress.Commands.add('checkPending', () => { + cy.get('input[id="currentStatus"]', { timeout: 1000000 }).should( + 'have.value', + 'pending' + ) +})