Skip to content

Commit

Permalink
[Cypress] Fix screenshot can't see on multi level dir
Browse files Browse the repository at this point in the history
  • Loading branch information
n313893254 committed Aug 14, 2023
1 parent e0ba63f commit d790252
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cypress/pageobjects/volume.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class VolumePage extends CruResourcePo {

checkSnapshotCount(volumeName: string, count: number, namespace: string = 'default') {
this.goToList();
this.censorInColumn(volumeName, 3, namespace, 4, count, 7);
this.censorInColumn(volumeName, 3, namespace, 4, count, 8);
}

clickVolumeSnapshotAction(name: string, snapshotName: string) {
Expand Down
15 changes: 15 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require("fs");
const yaml = require('js-yaml');
const { isFileExist, findFiles } = require('cy-verify-downloads');
const AdmZip = require("adm-zip");
const path = require('path')

let globalVar = {};
// ***********************************************************
Expand Down Expand Up @@ -121,5 +122,19 @@ module.exports = (on, config) => {
return launchOptions;
});

// on('after:screenshot', (details) => {
// const fileName = path.basename(details.path)

// const newPath = `cypress/results/mochawesome-report/assets/${details.specName}-${fileName}`

// return new Promise((resolve, reject) => {
// fs.rename(details.path, newPath, (err) => {
// if (err) return reject(err)

// resolve({ path: newPath })
// })
// })
// })

return config;
}
28 changes: 26 additions & 2 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import cookie from 'cookie';
import addContext from "mochawesome/addContext";

import { Constants } from '../constants/constants'

const path = require('path')

const constants = new Constants();

require('cy-verify-downloads').addCustomCommand();
Expand Down Expand Up @@ -60,8 +63,29 @@ Cypress.on('uncaught:exception', (err, runable) => {
})

Cypress.on("test:after:run", (test, runnable) => {
if (test.state === "failed") {
const screenshot =`assets/${Cypress.spec.name}/${runnable.parent.title} -- ${test.title} (failed).png`;
if (test.state === "failed") {
const dir = Cypress.spec.relative
const specDir = dir.split('/').slice(1, -1).join('/')

let describe = ''
let context = ''
let it = test.title

let fileName = ''

if (runnable.parent?.parent?.title) {
describe = runnable.parent.parent.title
context = runnable.parent.title

fileName = `${describe} -- ${context} -- ${it} (failed).png`
} else {
describe = runnable.parent.title

fileName = `${runnable.parent.title} -- ${test.title} (failed).png`
}

const screenshot =`assets/${specDir}/${Cypress.spec.name}/${fileName}`;

addContext({ test }, screenshot);
}
});
27 changes: 14 additions & 13 deletions cypress/testcases/virtualmachines/advanced.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,20 @@ sshpwauth: True

vms.save()

cy.wait('@createVM').then(res => {
expect(res.response?.statusCode, 'Check create VM').to.equal(201);

expect(res.response?.body?.spec?.template?.spec?.domain?.resources?.limits?.cpu).to.equal('1')
expect(res.response?.body?.spec?.template?.spec?.domain?.resources?.limits?.memory).to.equal('1Gi')
})

cy.wait('@createSecret').then(res => {
expect(res.response?.statusCode, 'Check create secret').to.equal(201);

const userDataYAML = base64Decode(res.response?.body?.data?.userdata)
expect(userDataYAML, 'Check user data').to.equal(userData)
})
for( let i=0; i<3; i++) {
cy.wait('@createVM').then(res => {
expect(res.response?.statusCode, 'Check create VM').to.equal(201);

expect(res.response?.body?.spec?.template?.spec?.domain?.resources?.limits?.cpu).to.equal('1')
expect(res.response?.body?.spec?.template?.spec?.domain?.resources?.limits?.memory).to.equal('1Gi')
})
cy.wait('@createSecret').then(res => {
expect(res.response?.statusCode, 'Check create secret').to.equal(201);

const userDataYAML = base64Decode(res.response?.body?.data?.userdata)
expect(userDataYAML, 'Check user data').to.equal(userData)
})
}

vms.goToList()
cy.get('.search').type(namePrefix)
Expand Down

0 comments on commit d790252

Please sign in to comment.