From dd9e4beed8af01fdf8e5a44a61e663cd9ee78e0e Mon Sep 17 00:00:00 2001 From: "andy.lee" Date: Tue, 7 May 2024 15:28:15 +0800 Subject: [PATCH 1/2] fix: the typo in test case description Signed-off-by: andy.lee --- cypress/testcases/backupAndSnapshot/vmBackup.spec.ts | 8 ++++---- cypress/testcases/backupAndSnapshot/vmSnapshot.spec.ts | 6 +++--- .../testcases/backupAndSnapshot/volumeSnapshot.spec.ts | 2 +- cypress/testcases/dashboard/0_FirstTimeLogin.spec.ts | 4 ++-- cypress/testcases/dashboard/support.spec.ts | 2 +- cypress/testcases/virtualmachines/virtual-machine.spec.ts | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cypress/testcases/backupAndSnapshot/vmBackup.spec.ts b/cypress/testcases/backupAndSnapshot/vmBackup.spec.ts index ff7ab9a77..5f98e34d6 100644 --- a/cypress/testcases/backupAndSnapshot/vmBackup.spec.ts +++ b/cypress/testcases/backupAndSnapshot/vmBackup.spec.ts @@ -49,7 +49,7 @@ describe('VM Backup Validation', () => { createVMBackupSuccess = true }) - it('Resotre New VM from vm backup', () => { + it('Restore new VM from vm backup', () => { onlyOn(createVMBackupSuccess); const newVMName = 'create-new-from-backup'; @@ -63,7 +63,7 @@ describe('VM Backup Validation', () => { vms.deleteVMFromStore(`default/${newVMName}`); }) - it('Resotre New VM in another namespace from vm backup', () => { + it('Restore New VM in another namespace from vm backup', () => { onlyOn(createVMBackupSuccess); const newVMName = 'create-new-from-backup'; @@ -77,7 +77,7 @@ describe('VM Backup Validation', () => { vms.deleteVMFromStore(`default/${newVMName}`); }) - it('Resotre Existing VM from vm backup', () => { + it('Restore Existing VM from vm backup', () => { onlyOn(createVMBackupSuccess); vms.goToList(); @@ -91,7 +91,7 @@ describe('VM Backup Validation', () => { vms.deleteVMFromStore(`default/test`); }) - it('delete backup', () => { + it('Delete backup', () => { onlyOn(createVMBackupSuccess); vmBackups.goToList(); diff --git a/cypress/testcases/backupAndSnapshot/vmSnapshot.spec.ts b/cypress/testcases/backupAndSnapshot/vmSnapshot.spec.ts index d400c6c40..d3e443ef5 100644 --- a/cypress/testcases/backupAndSnapshot/vmSnapshot.spec.ts +++ b/cypress/testcases/backupAndSnapshot/vmSnapshot.spec.ts @@ -15,7 +15,7 @@ describe('VM snapshot Form Validation', () => { cy.login({url: PageUrl.virtualMachine}); }); - it('Take a vm snaphost from vm', () => { + it('Take a vm snapshot from vm', () => { // Create a vm to test the snapshot operation const namespace = 'default'; @@ -47,7 +47,7 @@ describe('VM snapshot Form Validation', () => { createVMSnapshotSuccess = true }) - it('Resotre New VM from vm snapshot', () => { + it('Restore New VM from vm snapshot', () => { onlyOn(createVMSnapshotSuccess); const newVMName = 'create-new-from-snapshot'; @@ -61,7 +61,7 @@ describe('VM snapshot Form Validation', () => { vms.deleteVMFromStore(`default/${newVMName}`); }) - it('Resotre Existing VM from vm snapshot', () => { + it('Restore Existing VM from vm snapshot', () => { onlyOn(createVMSnapshotSuccess); vms.goToList(); diff --git a/cypress/testcases/backupAndSnapshot/volumeSnapshot.spec.ts b/cypress/testcases/backupAndSnapshot/volumeSnapshot.spec.ts index 19cf4bc26..dcc7136cd 100644 --- a/cypress/testcases/backupAndSnapshot/volumeSnapshot.spec.ts +++ b/cypress/testcases/backupAndSnapshot/volumeSnapshot.spec.ts @@ -43,7 +43,7 @@ describe('Validation volume snapshot', () => { createVolumeSnapshotSuccess = true }) - it('Resotre New volume from volume snapshot', () => { + it('Restore New volume from volume snapshot', () => { onlyOn(createVolumeSnapshotSuccess); const newName = 'create-new-from-snapshot'; diff --git a/cypress/testcases/dashboard/0_FirstTimeLogin.spec.ts b/cypress/testcases/dashboard/0_FirstTimeLogin.spec.ts index 07db03f89..819e32fa4 100644 --- a/cypress/testcases/dashboard/0_FirstTimeLogin.spec.ts +++ b/cypress/testcases/dashboard/0_FirstTimeLogin.spec.ts @@ -37,7 +37,7 @@ describe("First Time Login Page", () => { }); context("Set Password", () => { - specify("Password inconsistant", () => { + specify("Password inconsistent", () => { onlyOn(isFirstTimeLogin); const page = new LoginPage(); page.visit(); @@ -52,7 +52,7 @@ describe("First Time Login Page", () => { }); - specify("Password consistant", () => { + specify("Password consistent", () => { onlyOn(isFirstTimeLogin); const page = new LoginPage(); page.visit(); diff --git a/cypress/testcases/dashboard/support.spec.ts b/cypress/testcases/dashboard/support.spec.ts index 5d665633d..96b249647 100644 --- a/cypress/testcases/dashboard/support.spec.ts +++ b/cypress/testcases/dashboard/support.spec.ts @@ -38,7 +38,7 @@ describe("Support Page", () => { }) }) - context('Generate Support Bundle', () => { + context.only('Generate Support Bundle', () => { it('is required to input Description', () => { page.generateSupportBundleBtn.click() diff --git a/cypress/testcases/virtualmachines/virtual-machine.spec.ts b/cypress/testcases/virtualmachines/virtual-machine.spec.ts index bca05a256..b41148e26 100644 --- a/cypress/testcases/virtualmachines/virtual-machine.spec.ts +++ b/cypress/testcases/virtualmachines/virtual-machine.spec.ts @@ -166,7 +166,7 @@ describe('VM runStategy Validation (Halted)', () => { const namespace = 'default' - it('Craete VM use Halted (Run Strategy)', () => { + it('Create VM use Halted (Run Strategy)', () => { vms.goToCreate(); const imageEnv = Cypress.env('image'); From c8d2ea0786fc8c2e29bd26818cca21a3e3d54aa3 Mon Sep 17 00:00:00 2001 From: "andy.lee" Date: Wed, 8 May 2024 15:57:10 +0800 Subject: [PATCH 2/2] fix: use MutationObserver in generate support bundle test case Signed-off-by: andy.lee --- cypress/constants/constants.ts | 2 +- cypress/testcases/dashboard/support.spec.ts | 61 ++++++++++++--------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/cypress/constants/constants.ts b/cypress/constants/constants.ts index 033704e52..f82f9385c 100644 --- a/cypress/constants/constants.ts +++ b/cypress/constants/constants.ts @@ -1,5 +1,5 @@ export class Constants { - public timeout = { timeout: 10000, maxTimeout: 60000, uploadTimeout: 600000, downloadTimeout: 120000, provisionTimeout: 1500000}; + public timeout = { timeout: 10000, maxTimeout: 60000, uploadTimeout: 600000, downloadTimeout: 240000, provisionTimeout: 1500000}; public username = Cypress.env("username"); public password = Cypress.env("password"); public mockPassword = Cypress.env("mockPassword"); diff --git a/cypress/testcases/dashboard/support.spec.ts b/cypress/testcases/dashboard/support.spec.ts index 96b249647..244a55bb9 100644 --- a/cypress/testcases/dashboard/support.spec.ts +++ b/cypress/testcases/dashboard/support.spec.ts @@ -38,7 +38,7 @@ describe("Support Page", () => { }) }) - context.only('Generate Support Bundle', () => { + context('Generate Support Bundle', () => { it('is required to input Description', () => { page.generateSupportBundleBtn.click() @@ -62,60 +62,67 @@ describe("Support Page", () => { .should($el => expect($el).to.have.length(0)) }) - it('is should download', () => { + it('should download successfully', () => { let filename: string | undefined = undefined page.generateSupportBundleBtn.click() + page.inputSupportBundle('this is a test bundle') .get("@generateBtn").click() .intercept("/v1/harvester/*supportbundles/**/bundle*", req => req.continue(res => { - cy.log(res.body.status) - filename = res.body.status?.filename || undefined + filename = res.body?.metadata?.name }) ) - + cy.window().then(win => { - let timeout = {timeout: constants.timeout.downloadTimeout} - return cy.get("@generateView").then(timeout, $el => { + const timeout = {timeout: constants.timeout.downloadTimeout} + cy.log(`Wait for ${timeout.timeout} ms to generate and download support bundle`) + return cy.get("@generateView").then(timeout, ($el) => { return new Promise((resolve, reject) => { - // delay 3s to refresh page, this will fix page reload bug - // `DOMNodeRemoved` is deprecated, we probably need to use `MutationObserver` - // in the future - $el.one("DOMNodeRemoved", () => setTimeout(() => resolve(win.history.go(0)), 3000)) + const modalObserver = new MutationObserver((mutationList) => { + if(mutationList.length && mutationList[0]?.type === "childList") { + // page needs to reload after downloaded support bundle, delay 3s to refresh page + setTimeout(() => resolve(win.history.go(0)), 3000) + }else{ + reject('Error: monitoring generate modal closed, no childList mutation found'); + } + }); + modalObserver.observe($el[0], { childList: true, characterData: true }); }) }) }) .then(() => { // the scope will execute after page reloaded new Promise((resolve, reject) => { - if (filename !== undefined) { - cy.task("findFiles", {path: Cypress.config("downloadsFolder"), fileName: "supportbundle"}) - .then((files: any) => files.length == 1 ? resolve(files[0]) : reject(files)) + if(filename === undefined) { + reject('filename is undefined') } - resolve(filename) + const supportBundle = {path: Cypress.config("downloadsFolder"), fileName: "supportbundle"} + // resolve real bundle filename + cy.task("findFiles", supportBundle) + .then((files: any) => files.length === 1 ? resolve(files[0]) : reject(files)) }) .then(filename => { cy.log("Downloaded SupportBundle: ", filename) - let zipfilename = `${Cypress.config("downloadsFolder")}/${filename}` - return new Promise((resolve, reject) => { - cy.task("readZipFile", zipfilename) - .then(entries => resolve(entries)) + const zipFileName = `${Cypress.config("downloadsFolder")}/${filename}` + // resolve file entries in zip + return new Promise((resolve) => { + cy.task("readZipFile", zipFileName).then(entries => resolve(entries)) }) }) .then((items: any) => { - cy.log(`ZipFile entries: ${items.length}`) - let {dirs, files} = items.reduce((groups: any, e: any) => { + cy.log(`Total file entries in zip : ${items.length}`) + + const {dirs, files} = items.reduce((groups: any, e: any) => { e.isDirectory ? groups.dirs.push(e) : groups.files.push(e) return groups }, {dirs:[], files:[]}) - cy.log("Total Dirs:", dirs) - cy.log("Total Files:", files) - return {dirs, files} + cy.log("Total Dirs count :", dirs.length) + cy.log("Total Files count:", files.length) + expect(dirs.length).to.greaterThan(0) + expect(files.length).to.greaterThan(0) }) - // .then(({dirs, files}) => {}) // new verfiers here - }) }) - }) })