From 277d619518729ae50843f08f95f00e356334948c Mon Sep 17 00:00:00 2001 From: Annie Huang Date: Thu, 23 Nov 2023 23:27:58 +0800 Subject: [PATCH] fix cypress fail --- tests/cypress/e2e/helloworld.cy.js | 6 ++---- tests/cypress/support/commands.js | 14 +++++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/cypress/e2e/helloworld.cy.js b/tests/cypress/e2e/helloworld.cy.js index a152066..1dfcb9c 100644 --- a/tests/cypress/e2e/helloworld.cy.js +++ b/tests/cypress/e2e/helloworld.cy.js @@ -137,7 +137,7 @@ describe('example helloworld app', () => { it('Typing in Terminal', () => { cy.typeInCommand('12345{enter}') cy.get('@Terminaltextbox') - .should('contain', 'zsh: command not found: 12345') + .should('contain', 'zsh: command not found: 12345', { timeout: 50000 }) .and('contain', '12345') }) it('Complete the Game(relating UI)', () => { @@ -187,9 +187,7 @@ describe('example helloworld app', () => { // Check survey dialog pop up cy.CheckTextElement('#QuestCompleted', '關卡完成!', 'Quest Completed!') cy.get('div[class="modal"]').find('p').should('be.visible') - cy.findByRole('link', { name: '回到地圖' }, { timeout: 30000 }).should( - 'be.visible' - ) + cy.get('#BacktoMap').should('contain', '回到地圖').and('be.visible') }) }) }) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index de19392..9edb868 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -9,13 +9,21 @@ Cypress.Commands.add('LoginWithPassword', (username, password) => { }) Cypress.Commands.add('PrepareForGame', () => { cy.visit('/') + // make sure the login page is loaded + cy.url().should('satisfy', (elements) => { + const text = elements + return text.includes('login') || text.includes('register') + }) cy.LoginWithPassword( Cypress.env('defaultAccount'), Cypress.env('defaultPassword') ) + // make sure the map page is loaded cy.url().should('include', '/map') cy.visit('/game/helloworld') - cy.get('.xterm-screen', { timeout: 10000 }) + // make sure the game page is loaded + cy.url().should('include', '/game/helloworld') + cy.get('.xterm-screen', { timeout: 30000 }) .as('Terminaltextbox') .should('be.visible') cy.CheckTextElement('#reset', '重來', 'Reset').click() @@ -24,10 +32,6 @@ Cypress.Commands.add('PrepareForGame', () => { 'contain', 'commander:~ $' ) - cy.get('@Terminaltextbox', { timeout: 150000 }).should( - 'contain', - 'commander:~ $' - ) }) Cypress.Commands.add('typeInCommand', (command) => { cy.get('.xterm-screen', { timeout: 150000 }).type(command)