Skip to content

Commit

Permalink
chore: remove debug + cleanup PR
Browse files Browse the repository at this point in the history
  • Loading branch information
adeldhis2 committed Dec 30, 2024
1 parent 1a633f9 commit 6d07776
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 96 deletions.
9 changes: 0 additions & 9 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
32 changes: 2 additions & 30 deletions cypress/helpers/startScreen.js
Original file line number Diff line number Diff line change
@@ -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')
69 changes: 12 additions & 57 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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()
})

0 comments on commit 6d07776

Please sign in to comment.