diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f8b08d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/e2e/.abort-run diff --git a/e2e/cypress.json b/e2e/cypress.json index 551db52..ffb9ccf 100644 --- a/e2e/cypress.json +++ b/e2e/cypress.json @@ -7,6 +7,7 @@ "supportFile": "support/e2e.js", "pluginsFile": "plugins/index.js", "env": { + "expectedServerVersion": "8.2.4", "apiBaseUrl": "http://localhost:7575/api/v8.0/", "REMOTE_BASE_URL": "https://devtest.onayanova.com/", "REMOTE_API_URL": "https://devtest.onayanova.com/api/v8.0/", diff --git a/e2e/notes.txt b/e2e/notes.txt index ad60830..c929c40 100644 --- a/e2e/notes.txt +++ b/e2e/notes.txt @@ -6,7 +6,6 @@ honestly though this may be enough to move to the next stage - also include the version to test against in the command line as well. Put it in the pre-data generation and erasure block so it just aborts right away without modifying anything. Maybe just looks at the login page itself - =-=-=-=-=-=-=-=-=-=-=-=- From the olden times years ago: diff --git a/e2e/plugins/index.js b/e2e/plugins/index.js index 54894b1..f4eae7b 100644 --- a/e2e/plugins/index.js +++ b/e2e/plugins/index.js @@ -1,66 +1,8 @@ -//my sample users use obvious passwords "service/service", "accounting/accounting" triggering annoying your password is used in a hack warning in chrome -//sample users are inteded to be this easy to guess for testing and trial evaluation purposes so not changing it -// /** -// * @type {Cypress.PluginConfig} -// */ -// module.exports = (on, config) => { -// on('before:browser:launch', (browser = {}, launchOptions) => { -// // Check if we are using Chrome or a Chromium-based browser -// if (browser.family === 'chromium' && browser.name !== 'electron') { - -// // 1. Disable the specific password leak detection feature -// launchOptions.args.push('--disable-features=PasswordLeakDetection'); - -// // 2. Disable the "Save Password" and "Check Passwords" prompts -// launchOptions.preferences.default['credentials_enable_service'] = false; -// launchOptions.preferences.default['profile.password_manager_enabled'] = false; - -// // 3. Specifically target the leak detection toggle in preferences -// launchOptions.preferences.default['profile.password_manager_leak_detection'] = false; +const fs = require('fs') +const path = require('path') -// return launchOptions; -// } -// }); -// }; +const ABORT_FLAG_PATH = path.join(__dirname, '..', '.abort-run') - - - -// module.exports = (on, config) => { -// on('before:browser:launch', (browser, launchOptions) => { -// if (browser.name === 'chrome') { -// launchOptions.args.push( -// '--disable-features=PasswordLeakDetection,PasswordManagerLeakDetection,PasswordCheck,InsecureCredentialsWarning' -// ); -// } -// return launchOptions; -// }); -// }; - - - -// /// -// // *********************************************************** -// // This example plugins/index.js can be used to load plugins -// // -// // You can change the location of this file or turn off loading -// // the plugins file with the 'pluginsFile' configuration option. -// // -// // You can read more here: -// // https://on.cypress.io/plugins-guide -// // *********************************************************** - -// // This function is called when a project is opened or re-opened (e.g. due to -// // the project's config changing) - -// /** -// * @type {Cypress.PluginConfig} -// */ -// // eslint-disable-next-line no-unused-vars -// module.exports = (on, config) => { -// // `on` is used to hook into various events Cypress emits -// // `config` is the resolved Cypress config -// } module.exports = (on, config) => { on('before:browser:launch', (browser, launchOptions) => { if (browser.name === 'chrome') { @@ -77,5 +19,27 @@ module.exports = (on, config) => { config.env.apiBaseUrl = config.env.REMOTE_API_URL } - return config // <-- critical, must return config + // Task to set abort flag + on('task', { + setAbortFlag() { + fs.writeFileSync(ABORT_FLAG_PATH, 'ABORTED') + return null + }, + checkAbortFlag() { + return fs.existsSync(ABORT_FLAG_PATH) + }, + clearAbortFlag() { + if (fs.existsSync(ABORT_FLAG_PATH)) { + fs.unlinkSync(ABORT_FLAG_PATH) + } + return null + } + }) + + // Clean up abort flag at start of run + if (fs.existsSync(ABORT_FLAG_PATH)) { + fs.unlinkSync(ABORT_FLAG_PATH) + } + + return config } \ No newline at end of file diff --git a/e2e/support/e2e.js b/e2e/support/e2e.js index 0b577dd..a44abcc 100644 --- a/e2e/support/e2e.js +++ b/e2e/support/e2e.js @@ -1,24 +1,15 @@ -// *********************************************************** -// This example support/index.js is processed and -// loaded automatically before your test files. -// -// This is a great place to put global configuration and -// behavior that modifies Cypress. -// -// You can change the location of this file or turn off -// automatically serving support files with the -// 'supportFile' configuration option. -// -// You can read more here: -// https://on.cypress.io/configuration -// *********************************************************** - // Import commands.js using ES2015 syntax: import "./commands"; -// Alternatively you can use CommonJS syntax: -// require('./commands') - //unique test run ID for all tests Cypress.config("cyid", `cy${new Date().getTime()}`); +// Global guard: halt all tests if abort flag exists +beforeEach(function () { + cy.task("checkAbortFlag").then(shouldAbort => { + if (shouldAbort) { + Cypress.runner.stop(); + this.skip(); + } + }); +}); diff --git a/e2e/tests/regression/0-setup/000-generate-test-db.cy.js b/e2e/tests/regression/0-setup/000-generate-test-db.cy.js index a62347f..93f4131 100644 --- a/e2e/tests/regression/0-setup/000-generate-test-db.cy.js +++ b/e2e/tests/regression/0-setup/000-generate-test-db.cy.js @@ -1,27 +1,46 @@ // Basic smoke test, visit every form to ensure they load - describe("SMOKE SETUP", () => { - before(() => { cy.request({ - url: `${Cypress.env("apiBaseUrl")}version`, - method: "GET" - }).then((resp) => { - const serverVersion = resp.body.data.version - if (serverVersion !== "8.0.0") { - Cypress.env("ABORT_RUN", true) - throw new Error(`Version mismatch: expected 8.0.0 but got ${serverVersion}`) + url: `${Cypress.env("apiBaseUrl")}auth`, + method: "POST", + body: { + login: Cypress.env("admin").login, + password: Cypress.env("admin").password } }) + .its("body") + .then((res) => { + cy.request({ + method: "GET", + url: `${Cypress.env("apiBaseUrl")}server-info`, + auth: { bearer: res.data.token } + }).then((resp) => { + const raw = resp.body.data.serverVersion + const match = raw.match(/(\d+\.\d+\.\d+)/) + + if (!match) { + cy.task('setAbortFlag').then(() => { + throw new Error(`Could not parse version from: "${raw}"`) + }) + return // prevent further execution + } + + const version = match[1] + const expected = Cypress.env("expectedServerVersion") + + if (version !== expected) { + cy.task('setAbortFlag').then(() => { + throw new Error(`❌ Version mismatch: server is ${version}, expected ${expected}. ABORTING ALL TESTS.`) + }) + return // prevent further execution + } + + cy.log(`✓ Server version confirmed: ${version}`) + }) + }) }) - after(() => { - if (Cypress.env("ABORT_RUN")) { - Cypress.runner.stop() - } - }) - - it("Generates test data without issue", () => { cy.request({ url: `${Cypress.env("apiBaseUrl")}auth`, @@ -32,7 +51,7 @@ describe("SMOKE SETUP", () => { } }) .its("body") - .then((res) => { + .then(res => { cy.request({ method: "POST", url: `${Cypress.env("apiBaseUrl")}license/permanently-erase-all-data`, @@ -57,7 +76,7 @@ describe("SMOKE SETUP", () => { } }) .its("body") - .then((resjob) => { + .then(resjob => { cy.log(`resjob is: ${JSON.stringify(resjob)}`); // expect(resjob.body).to.have.property('jobId'); confirmJobDone(resjob.jobId, res.data.token); @@ -74,7 +93,7 @@ function confirmJobDone(jobId, authToken) { auth: { bearer: authToken } - }).then((resp) => { + }).then(resp => { //3 means job done if (resp.body.data == 3) return; // else recurse @@ -83,8 +102,6 @@ function confirmJobDone(jobId, authToken) { }); } - - //=============================================== // describe("SMOKE SETUP", () => { // it("Generates test data without issue", () => {