diff --git a/tests/cypress/e2e/UItests.cy.ts b/tests/cypress/e2e/UItests.cy.ts index 1ea8646..031e104 100644 --- a/tests/cypress/e2e/UItests.cy.ts +++ b/tests/cypress/e2e/UItests.cy.ts @@ -75,7 +75,7 @@ describe('example helloworld app', () => { describe('Game Start Page UI', () => { const title = '終端機的基本知識' beforeEach(() => { - cy.PrepareForGame() + cy.PrepareForGame('get-started') }) it('Check Header', () => { cy.get('#GameTitle').should('contain', 'Linux Odyssey').and('be.visible') @@ -124,7 +124,7 @@ describe('example helloworld app', () => { }) describe('Game Play', () => { beforeEach(() => { - cy.PrepareForGame() + cy.PrepareForGame('get-started') }) it('Typing in Terminal', () => { cy.typeInCommand('12345{enter}') @@ -136,7 +136,7 @@ describe('example helloworld app', () => { cy.checkTaskInit() cy.InitTerminal() cy.typeInCommand('echo start{enter}') - cy.checkPending() + // cy.checkPending() cy.waitUntilActive() cy.get('#Lbutton').should('be.visible').and('be.disabled') cy.get('#Rbutton').should('be.visible').and('be.disabled') @@ -144,7 +144,7 @@ describe('example helloworld app', () => { cy.getQuestInfo('✓ 輸入 echo start 來開始教程').should('be.visible') cy.getQuestInfo('➤ 在終端機輸入 echo hello').should('be.visible') cy.typeInCommand('echo hello{enter}') - cy.checkPending() + // cy.checkPending() cy.waitUntilActive() cy.get('#Lbutton').should('be.visible').and('be.enabled') cy.get('#Rbutton').should('be.visible').and('be.disabled') diff --git a/tests/cypress/e2e/completeQuests.cy.ts b/tests/cypress/e2e/completeQuests.cy.ts index 57ba8e2..dbd9de8 100644 --- a/tests/cypress/e2e/completeQuests.cy.ts +++ b/tests/cypress/e2e/completeQuests.cy.ts @@ -1,7 +1,4 @@ describe('Complete quests with only commands', () => { - beforeEach(() => { - cy.PrepareForGame() - }) it('Complete quest : get-started', () => { cy.CompleteStageWithCommands('get-started') }) diff --git a/tests/cypress/support/commands.ts b/tests/cypress/support/commands.ts index b77cd88..23d6484 100644 --- a/tests/cypress/support/commands.ts +++ b/tests/cypress/support/commands.ts @@ -38,7 +38,7 @@ Cypress.Commands.add('LoginWithPassword', (username, password) => { cy.get('#password').type(password) cy.get('#LogInOrSignUp').click() }) -Cypress.Commands.add('PrepareForGame', () => { +Cypress.Commands.add('PrepareForGame', (questId) => { cy.visit('/') // make sure the login page is loaded cy.url().should('satisfy', (elements: string) => { @@ -51,8 +51,9 @@ Cypress.Commands.add('PrepareForGame', () => { ) // make sure the map page is loaded cy.url().should('include', '/map') - cy.visit('/game/get-started') - cy.url().should('include', '/game/get-started') + const url = `/game/${questId}` + cy.visit(url) + cy.url().should('include', url) // check task first so the terminal has better possibility loaded cy.checkTaskInit() cy.get('.xterm-screen', { timeout: 10000 }) @@ -114,8 +115,7 @@ Cypress.Commands.add('checkPending', () => { ) }) Cypress.Commands.add('CompleteStageWithCommands', (stagename) => { - cy.visit(`/game/${stagename}`) - cy.url().should('include', `/game/${stagename}`, { timeout: 50000 }) + cy.PrepareForGame(stagename) cy.log(`Completing stage :${stagename}`) cy.checkTaskInit() cy.CheckTextElement('#reset', '重來', 'Reset').click() @@ -123,19 +123,22 @@ Cypress.Commands.add('CompleteStageWithCommands', (stagename) => { cy.InitTerminal() cy.readFile(`../quests/${stagename}/answer.sh`, 'utf-8').then((answers) => { const answerarr = answers.split('\n') - for (const element of answerarr) { + answerarr.forEach((element, index) => { cy.typeInCommand(`${element}{enter}`) - if (answerarr.indexOf(element) + 1 !== answerarr.length) { - cy.checkPending() + if (index < answerarr.length - 1) { cy.waitUntilActive() + } else { + cy.waitUntilActive(true).then(() => { + cy.CheckTextElement( + '#QuestCompleted', + '關卡完成!', + 'Quest Completed!' + ) + cy.get('div[class="modal"]').find('p').should('be.visible') + cy.get('#BacktoMap').should('be.visible').and('contain', '回到地圖') + }) } - if (answerarr.indexOf(element) + 1 === answerarr.length) { - cy.waitUntilActive(true) - cy.CheckTextElement('#QuestCompleted', '關卡完成!', 'Quest Completed!') - cy.get('div[class="modal"]').find('p').should('be.visible') - cy.get('#BacktoMap').should('be.visible').and('contain', '回到地圖') - } - } + }) }) }) Cypress.Commands.add('CheckTextElement', (id, chText, enText) => {