fix; cypress use 'get-started' as test quest

This commit is contained in:
Lin, Hung-Shin committed 2023-11-23 23:29:19 +08:00
1 parent 2cc8a98734
commit f03a544108
2 files changed
+17 -32

No files matched your search

+16 -31
View File
@@ -74,19 +74,18 @@ describe('example helloworld app', () => {
}) })
}) })
describe('Game Start Page UI', () => { describe('Game Start Page UI', () => {
const title = '終端機的基本知識'
beforeEach(() => { beforeEach(() => {
cy.PrepareForGame() cy.PrepareForGame()
}) })
it('Check Header', () => { it('Check Header', () => {
cy.get('#HeaderText') cy.get('#HeaderText').should('contain', title).and('be.visible')
.should('contain', 'Hello, Linux World!')
.and('be.visible')
cy.findByRole('link', { name: 'Bug Report' }).should('be.visible') cy.findByRole('link', { name: 'Bug Report' }).should('be.visible')
cy.findByRole('button', { name: 'Sign Out' }).should('be.visible') cy.findByRole('button', { name: 'Sign Out' }).should('be.visible')
}) })
it('Check QuestInfo', () => { it('Check QuestInfo', () => {
cy.get('#topic').should('contain', 'Hello, Linux World!') cy.get('#topic').should('contain', title)
cy.get('#quest').find('p.text-text').should('have.length', 3) cy.get('#quest').find('p.text-text').should('have.length', 4)
cy.CheckTextElement('#tasks', '任務', 'Tasks:') cy.CheckTextElement('#tasks', '任務', 'Tasks:')
cy.getQuestInfo('輸入 `echo help` 來朗誦咒語').should('be.visible') cy.getQuestInfo('輸入 `echo help` 來朗誦咒語').should('be.visible')
}) })
@@ -120,7 +119,6 @@ describe('example helloworld app', () => {
describe('Game Play', () => { describe('Game Play', () => {
beforeEach(() => { beforeEach(() => {
cy.PrepareForGame() cy.PrepareForGame()
cy.readFile('../quests/helloworld/answer.sh', 'utf-8').as('answers')
}) })
it('Typing in Terminal', () => { it('Typing in Terminal', () => {
cy.typeInCommand('12345{enter}') cy.typeInCommand('12345{enter}')
@@ -129,54 +127,41 @@ describe('example helloworld app', () => {
.and('contain', '12345') .and('contain', '12345')
}) })
it('Complete the Game(relating UI)', () => { it('Complete the Game(relating UI)', () => {
// get answersheet
cy.get('@answers').then((answers) => {
const answerarr = answers.split('\n')
// Stage1 // Stage1
cy.log('Stage1') cy.log('Stage1')
cy.typeInCommand(answerarr[0]) cy.typeInCommand('echo start{enter}')
cy.checkPending() cy.checkPending()
cy.waitUntilActive() cy.waitUntilActive()
cy.get('#Lbutton').should('be.visible').and('be.disabled') cy.get('#Lbutton').should('be.visible').and('be.disabled')
cy.get('#Rbutton').should('be.visible').and('be.disabled') cy.get('#Rbutton').should('be.visible').and('be.disabled')
cy.checkHint(1, 1) cy.checkHint(1, 1)
cy.getQuestInfo('✓ 輸入 `echo help` 來朗誦咒語').should('be.visible') cy.getQuestInfo('✓ 輸入 `echo start` 來開始教程').should('be.visible')
cy.getQuestInfo('搜索卷軸').should('be.visible') cy.getQuestInfo('➤ 在終端機輸入 `echo hello`').should('be.visible')
// Stage2 // Stage2
cy.log('Stage2') cy.log('Stage2')
cy.typeInCommand(answerarr[1]) cy.typeInCommand('echo hello{enter}')
cy.checkPending() cy.checkPending()
cy.waitUntilActive() cy.waitUntilActive()
cy.get('#tree') // cy.get('#tree')
.get('a') // .get('a')
.should('contain', 'forgotten_scroll.txt') // .should('contain', 'forgotten_scroll.txt')
.and('be.visible') // .and('be.visible')
cy.get('#Lbutton').should('be.visible').and('be.enabled') cy.get('#Lbutton').should('be.visible').and('be.enabled')
cy.get('#Rbutton').should('be.visible').and('be.disabled') cy.get('#Rbutton').should('be.visible').and('be.disabled')
cy.checkHint(2, 2) cy.checkHint(2, 2)
cy.get('#Lbutton').click() cy.get('#Lbutton').click()
cy.get('#Rbutton').should('be.enabled') cy.get('#Rbutton').should('be.enabled')
cy.getQuestInfo('✓ 搜索卷軸').should('be.visible') cy.getQuestInfo('✓ 在終端機輸入 `echo hello`').should('be.visible')
cy.getQuestInfo('查看卷軸').should('be.visible') cy.getQuestInfo('➤ 結束關卡').should('be.visible')
// Stage3 // Stage3
cy.log('Stage3') cy.log('Stage3')
cy.typeInCommand(answerarr[2]) cy.typeInCommand('echo finish{enter}')
cy.checkPending() cy.checkPending()
cy.waitUntilActive() cy.waitUntilActive()
cy.getQuestInfo('✓ 查看卷軸').should('be.visible') 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.CheckTextElement('#QuestCompleted', '關卡完成!', 'Quest Completed!')
cy.get('div[class="modal"]').find('p').should('be.visible') cy.get('div[class="modal"]').find('p').should('be.visible')
cy.findByRole('link', { name: '填寫問卷' }).should('be.visible') cy.findByRole('link', { name: '填寫問卷' }).should('be.visible')
}) })
}) })
})
}) })
+1 -1
View File
@@ -14,7 +14,7 @@ Cypress.Commands.add('PrepareForGame', () => {
Cypress.env('defaultPassword') Cypress.env('defaultPassword')
) )
cy.url().should('include', '/map') cy.url().should('include', '/map')
cy.visit('/game/helloworld') cy.visit('/game/get-started')
cy.get('.xterm-screen', { timeout: 10000 }) cy.get('.xterm-screen', { timeout: 10000 })
.as('Terminaltextbox') .as('Terminaltextbox')
.should('be.visible') .should('be.visible')