From f03a544108da8335c999e452228999f73a2f40f5 Mon Sep 17 00:00:00 2001 From: "Lin, Hung-Shin" Date: Thu, 23 Nov 2023 23:29:19 +0800 Subject: [PATCH] fix; cypress use 'get-started' as test quest --- tests/cypress/e2e/helloworld.cy.js | 93 +++++++++++++----------------- tests/cypress/support/commands.js | 2 +- 2 files changed, 40 insertions(+), 55 deletions(-) diff --git a/tests/cypress/e2e/helloworld.cy.js b/tests/cypress/e2e/helloworld.cy.js index 91c4e07..e6e11f2 100644 --- a/tests/cypress/e2e/helloworld.cy.js +++ b/tests/cypress/e2e/helloworld.cy.js @@ -74,19 +74,18 @@ describe('example helloworld app', () => { }) }) describe('Game Start Page UI', () => { + const title = '終端機的基本知識' beforeEach(() => { cy.PrepareForGame() }) it('Check Header', () => { - cy.get('#HeaderText') - .should('contain', 'Hello, Linux World!') - .and('be.visible') + cy.get('#HeaderText').should('contain', title).and('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!') - cy.get('#quest').find('p.text-text').should('have.length', 3) + cy.get('#topic').should('contain', title) + cy.get('#quest').find('p.text-text').should('have.length', 4) cy.CheckTextElement('#tasks', '任務', 'Tasks:') cy.getQuestInfo('輸入 `echo help` 來朗誦咒語').should('be.visible') }) @@ -120,7 +119,6 @@ describe('example helloworld app', () => { describe('Game Play', () => { beforeEach(() => { cy.PrepareForGame() - cy.readFile('../quests/helloworld/answer.sh', 'utf-8').as('answers') }) it('Typing in Terminal', () => { cy.typeInCommand('12345{enter}') @@ -129,54 +127,41 @@ describe('example helloworld app', () => { .and('contain', '12345') }) it('Complete the Game(relating UI)', () => { - // get answersheet - cy.get('@answers').then((answers) => { - const answerarr = answers.split('\n') - // Stage1 - cy.log('Stage1') - cy.typeInCommand(answerarr[0]) - 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) - cy.getQuestInfo('✓ 輸入 `echo help` 來朗誦咒語').should('be.visible') - cy.getQuestInfo('搜索卷軸').should('be.visible') - // Stage2 - cy.log('Stage2') - cy.typeInCommand(answerarr[1]) - cy.checkPending() - cy.waitUntilActive() - cy.get('#tree') - .get('a') - .should('contain', 'forgotten_scroll.txt') - .and('be.visible') - cy.get('#Lbutton').should('be.visible').and('be.enabled') - cy.get('#Rbutton').should('be.visible').and('be.disabled') - cy.checkHint(2, 2) - cy.get('#Lbutton').click() - cy.get('#Rbutton').should('be.enabled') - cy.getQuestInfo('✓ 搜索卷軸').should('be.visible') - cy.getQuestInfo('查看卷軸').should('be.visible') - // Stage3 - cy.log('Stage3') - cy.typeInCommand(answerarr[2]) - 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.checkPending() - cy.waitUntilActive() - cy.getQuestInfo('✓ 解除封印').should('be.visible') - // Check survey dialog pop up - cy.CheckTextElement('#QuestCompleted', '關卡完成!', 'Quest Completed!') - cy.get('div[class="modal"]').find('p').should('be.visible') - cy.findByRole('link', { name: '填寫問卷' }).should('be.visible') - }) + // Stage1 + cy.log('Stage1') + cy.typeInCommand('echo start{enter}') + 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) + cy.getQuestInfo('✓ 輸入 `echo start` 來開始教程').should('be.visible') + cy.getQuestInfo('➤ 在終端機輸入 `echo hello`').should('be.visible') + // Stage2 + cy.log('Stage2') + cy.typeInCommand('echo hello{enter}') + cy.checkPending() + cy.waitUntilActive() + // cy.get('#tree') + // .get('a') + // .should('contain', 'forgotten_scroll.txt') + // .and('be.visible') + cy.get('#Lbutton').should('be.visible').and('be.enabled') + cy.get('#Rbutton').should('be.visible').and('be.disabled') + cy.checkHint(2, 2) + cy.get('#Lbutton').click() + cy.get('#Rbutton').should('be.enabled') + cy.getQuestInfo('✓ 在終端機輸入 `echo hello`').should('be.visible') + cy.getQuestInfo('➤ 結束關卡').should('be.visible') + // Stage3 + cy.log('Stage3') + cy.typeInCommand('echo finish{enter}') + cy.checkPending() + cy.waitUntilActive() + cy.getQuestInfo('✓ 結束關卡').should('be.visible') + cy.CheckTextElement('#QuestCompleted', '關卡完成!', 'Quest Completed!') + cy.get('div[class="modal"]').find('p').should('be.visible') + cy.findByRole('link', { name: '填寫問卷' }).should('be.visible') }) }) }) diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index de19392..a084dd9 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -14,7 +14,7 @@ Cypress.Commands.add('PrepareForGame', () => { Cypress.env('defaultPassword') ) cy.url().should('include', '/map') - cy.visit('/game/helloworld') + cy.visit('/game/get-started') cy.get('.xterm-screen', { timeout: 10000 }) .as('Terminaltextbox') .should('be.visible')