From 6d07776c7ed208d408bc4aaedadaa6653c66c91f Mon Sep 17 00:00:00 2001 From: adeldhis2 Date: Mon, 30 Dec 2024 08:14:09 +0100 Subject: [PATCH] chore: remove debug + cleanup PR --- cypress.config.js | 9 ----- cypress/helpers/startScreen.js | 32 +--------------- cypress/support/e2e.js | 69 ++++++---------------------------- 3 files changed, 14 insertions(+), 96 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index 75f65a68e..be1d55643 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -9,13 +9,6 @@ async function setupNodeEvents(on, config) { chromeAllowXSiteCookies(on, config) excludeByVersionTags(on, config) - on('task', { - log(message) { - console.log(message) - return null - }, - }) - // Delete videos for passing tests on('after:spec', (spec, results) => { try { @@ -55,10 +48,8 @@ module.exports = defineConfig({ specPattern: 'cypress/integration/**/*.cy.js', viewportWidth: 1280, viewportHeight: 800, - pageLoadTimeout: 60000, // Record video video: true, - chromeWebSecurity: false, // Disable Chrome Web Security // Enabled to reduce the risk of out-of-memory issues experimentalMemoryManagement: true, /* When allowing 1 retry on CI, the test suite will pass if diff --git a/cypress/helpers/startScreen.js b/cypress/helpers/startScreen.js index 220c3171f..8f94b5f7c 100644 --- a/cypress/helpers/startScreen.js +++ b/cypress/helpers/startScreen.js @@ -1,43 +1,15 @@ import { EXTENDED_TIMEOUT } from '../support/util.js' -// Helper function to log page state and check if specific content is present -const logPageState = () => { - cy.url().then((url) => { - cy.log(`Current URL: ${url}`) - cy.task('log', `Current URL: ${url}`) - console.log(`Current URL: ${url}`) - }) - - cy.get('body').then((body) => { - const bodyText = body.text() - cy.log(`Page Body Content: ${bodyText.slice(0, 500)}...`) - cy.task('log', `Page Body Content: ${bodyText.slice(0, 500)}...`) - console.log(`Page Body Content: ${bodyText.slice(0, 500)}...`) - }) -} - export const goToStartPage = (skipEval) => { const appPath = '/api/apps/line-listing/index.html'; const baseUrl = Cypress.env('dhis2BaseUrl') + appPath; cy.visit(baseUrl, EXTENDED_TIMEOUT).then(() => { - cy.log(`Visiting the base URL: ${baseUrl}`) cy.task('log', `Visiting the base URL: ${baseUrl}`) - console.log(`Visiting the base URL: ${baseUrl}`) - logPageState() - if (!skipEval) { expectStartScreenToBeVisible() } }) } -export const expectStartScreenToBeVisible = () => { - cy.contains('Getting started', EXTENDED_TIMEOUT) - .should('be.visible') - .then(() => { - cy.log('Confirmed: "Getting started" is visible') - cy.task('log', 'Confirmed: "Getting started" is visible') - console.log('Confirmed: "Getting started" is visible') - }) - logPageState() -} +export const expectStartScreenToBeVisible = () => + cy.contains('Getting started', EXTENDED_TIMEOUT).should('be.visible') diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index a2dce0177..641209a96 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -36,11 +36,6 @@ before(() => { const baseUrl = Cypress.env('dhis2BaseUrl') const instanceVersion = Cypress.env('dhis2InstanceVersion') - cy.task( - 'log', - `Attempting to log in with user: ${username} on base URL: ${baseUrl}` - ) - cy.request({ url: `${baseUrl}/${LOGIN_ENDPOINT}`, method: 'POST', @@ -51,77 +46,37 @@ before(() => { j_password: password, '2fa_code': '', }, - }).then((response) => { - cy.task('log', `Login request returned status: ${response.status}`) + }).should((response) => { expect(response.status).to.eq(200) }) - cy.getAllCookies().then((cookies) => { - cy.task( - 'log', - `Cookies after login attempt: ${JSON.stringify(cookies)}` - ) - - const sessionCookieForBaseUrl = findSessionCookieForBaseUrl( - baseUrl, - cookies - ) - if (sessionCookieForBaseUrl) { - cy.task( - 'log', - `Found session cookie for base URL: ${JSON.stringify( - sessionCookieForBaseUrl - )}` + cy.getAllCookies() + .should((cookies) => { + expect(cookies.length).to.be.at.least(1) + }) + .then((cookies) => { + const sessionCookieForBaseUrl = findSessionCookieForBaseUrl( + baseUrl, + cookies ) Cypress.env( computeEnvVariableName(instanceVersion), JSON.stringify(sessionCookieForBaseUrl) ) - } else { - cy.task('log', `Session cookie not found for base URL: ${baseUrl}`) - } - }) + }) }) beforeEach(() => { const baseUrl = Cypress.env('dhis2BaseUrl') const instanceVersion = Cypress.env('dhis2InstanceVersion') const envVariableName = computeEnvVariableName(instanceVersion) - const sessionCookie = Cypress.env(envVariableName) - - cy.task( - 'log', - `Setting session cookie for base URL: ${baseUrl} with cookie data: ${sessionCookie}` - ) - - const { name, value, ...options } = JSON.parse(sessionCookie) + const { name, value, ...options } = JSON.parse(Cypress.env(envVariableName)) localStorage.setItem(LOCAL_STORAGE_KEY, baseUrl) cy.setCookie(name, value, options) - cy.getAllCookies().then((cookies) => { - cy.task('log', `Cookies in beforeEach: ${JSON.stringify(cookies)}`) + cy.getAllCookies().should((cookies) => { expect(findSessionCookieForBaseUrl(baseUrl, cookies)).to.exist expect(localStorage.getItem(LOCAL_STORAGE_KEY)).to.equal(baseUrl) }) - - // // Intercept and log api requests - // cy.intercept('/api/**').as('apiRequests') - // cy.wait('@apiRequests').then((interception) => { - // cy.task('log', `Intercepted request: ${JSON.stringify(interception)}`) - // }) - - // Log the current URL - cy.url().then((currentUrl) => { - cy.task( - 'log', - `Current URL after setting session cookie: ${currentUrl}` - ) - if (currentUrl.includes('login')) { - throw new Error('Still on login page after setting session cookie.') - } - }) - - // Force a reload to ensure all resources are loaded - // cy.reload() })