Browse Source

(test) cypress: delete download folder/file after test

Signed-off-by: Raju Udava <sivadstala@gmail.com>
pull/743/head
Raju Udava 3 years ago
parent
commit
0d819816b4
  1. 21
      scripts/cypress/plugins/index.js
  2. 15
      scripts/cypress/support/page_objects/mainPage.js

21
scripts/cypress/plugins/index.js

@ -11,7 +11,7 @@
// This function is called when a project is opened or re-opened (e.g. due to // This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing) // the project's config changing)
const { rmdir } = require('fs')
/** /**
* @type {Cypress.PluginConfig} * @type {Cypress.PluginConfig}
*/ */
@ -19,5 +19,24 @@
module.exports = (on, config) => { module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits // `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config // `config` is the resolved Cypress config
// register utility tasks to read and parse Excel files
on('task', {
deleteFolder (folderName) {
console.log('deleting folder %s', folderName)
return new Promise((resolve, reject) => {
rmdir(folderName, { maxRetries: 10, recursive: true }, (err) => {
if (err) {
console.error(err)
return reject(err)
}
resolve(null)
})
})
},
})
} }

15
scripts/cypress/support/page_objects/mainPage.js

@ -1,6 +1,16 @@
const path = require("path"); const path = require("path");
/**
* Delete the downloads folder to make sure the test has "clean"
* slate before starting.
*/
export const deleteDownloadsFolder = () => {
const downloadsFolder = Cypress.config('downloadsFolder')
cy.task('deleteFolder', downloadsFolder)
}
// main page // main page
export class _mainPage { export class _mainPage {
@ -250,9 +260,10 @@ export class _mainPage {
// download folder path, read from config file // download folder path, read from config file
const downloadsFolder = Cypress.config("downloadsFolder") const downloadsFolder = Cypress.config("downloadsFolder")
let filePath = path.join(downloadsFolder, filename)
// append download folder path with filename to generate full file path, retrieve file // append download folder path with filename to generate full file path, retrieve file
cy.readFile(path.join(downloadsFolder, filename)) cy.readFile(filePath)
.then((fileData) => { .then((fileData) => {
// from CSV, split into records (rows) // from CSV, split into records (rows)
@ -263,6 +274,8 @@ export class _mainPage {
expect(rows[i]).to.be.equal(expectedRecords[i]) expect(rows[i]).to.be.equal(expectedRecords[i])
//cy.log(rows[i]) //cy.log(rows[i])
} }
deleteDownloadsFolder()
}) })
}) })
} }

Loading…
Cancel
Save