Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add new workflow to trigger Cypress tests from core #614

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
69ec080
Add new workflow to trigger Cypress tests from core
adeldhis2 Aug 19, 2024
7489a2b
fix
adeldhis2 Aug 19, 2024
f6445cc
fix
adeldhis2 Aug 19, 2024
4b5cc83
chore: update workflow to use workflow_dispatch
adeldhis2 Sep 12, 2024
b8faae3
chore: add debug logging for matrix output
adeldhis2 Sep 12, 2024
c8e8b20
chore: fix matrix parsing and sequence error
adeldhis2 Sep 12, 2024
2559a73
chore: fix test matrix output
adeldhis2 Sep 12, 2024
868d93b
chore: fix dhis2_version
adeldhis2 Sep 12, 2024
0142e58
chore: add logging to debug page state
adeldhis2 Sep 23, 2024
06fe62f
chore: fix logging
adeldhis2 Sep 23, 2024
a8c2ab1
chore: fix chaining issue
adeldhis2 Sep 23, 2024
0035109
chore: remove invalid .catch()
adeldhis2 Sep 23, 2024
c4e9c3c
chore: add cypress-multi-reporters
adeldhis2 Sep 23, 2024
9f563d4
chore: debug
adeldhis2 Oct 2, 2024
1fc63fd
chore: add cy.task for logging in setupNodeEvents
adeldhis2 Oct 3, 2024
158f67b
chore: add debug logging for login and session handling
adeldhis2 Oct 3, 2024
038493d
chore: fix async issue by moving cy.task to cy.then in login flow
adeldhis2 Oct 4, 2024
5d0374c
chore: fix session handling by moving cy.task to cy.then
adeldhis2 Oct 4, 2024
4180431
chore: increase pageLoadTimeout and add reload
adeldhis2 Oct 7, 2024
d931e2e
chore: disable Chrome Web Security to resolve potential CORS issues
adeldhis2 Oct 8, 2024
add4059
chore: intercept and log all network requests
adeldhis2 Oct 8, 2024
af08b56
chore: debug
adeldhis2 Oct 8, 2024
1932099
debug
adeldhis2 Oct 9, 2024
1d8cdad
chore: update line-listing url
adeldhis2 Oct 14, 2024
d24b04a
chore: refactor workflow for dynamic app and API URLs
adeldhis2 Oct 23, 2024
747711a
fix
adeldhis2 Nov 5, 2024
48f0b4c
chore: cleanup
adeldhis2 Nov 5, 2024
20903c1
debug: update cy.visit() to use baseUrl directly in goToStartPage
adeldhis2 Dec 3, 2024
2f50370
debug
adeldhis2 Dec 3, 2024
ba2fadf
debug: normalise base URL to fix trailing slash
adeldhis2 Dec 4, 2024
e0903ff
debug
adeldhis2 Dec 4, 2024
25677d0
debug
adeldhis2 Dec 4, 2024
4987f37
debug: test with a hardcodedUrl
adeldhis2 Dec 6, 2024
75932a4
debug
adeldhis2 Dec 9, 2024
60124d4
debug hardcodedUrl
adeldhis2 Dec 9, 2024
85f6475
debug use instance created 2.39
adeldhis2 Dec 9, 2024
0bf518a
Debug
adeldhis2 Dec 16, 2024
9c02217
cleanup
adeldhis2 Dec 25, 2024
8b6c5c2
cleanup
adeldhis2 Dec 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/e2e-test-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 'dhis2: e2e tests triggered by core'

on:
workflow_dispatch:
inputs:
dhis2_version:
description: 'DHIS2 core version'
required: true
instance_url:
description: 'Instance URL'
required: true

jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.specs }}
steps:
- uses: actions/checkout@v3

- name: Generate Test matrix
id: set-matrix
run: |
echo "Generating Test Matrix"
echo "::set-output name=specs::$(node src/generateTestMatrix.js)"

- name: Debug spec-group
run: |
echo "Matrix output: ${{ steps.set-matrix.outputs.specs }}"

call-workflow-e2e-prod:
needs: setup-matrix
uses: dhis2/workflows/.github/workflows/analytics-e2e-tests-triggered-by-core.yml@workflow-dispatch-cypress
with:
should_record: ${{ contains(github.event.head_commit.message, '[e2e record]') || contains(join(github.event.pull_request.labels.*.name), 'e2e record') }}
spec-group: ${{ needs.setup-matrix.outputs.matrix }}
api_base_url: ${{ github.event.inputs.instance_url }}
app_url: ${{ github.event.inputs.instance_url }}
dhis2_version: ${{ github.event.inputs.dhis2_version }}
secrets:
username: ${{ secrets.CYPRESS_DHIS2_USERNAME }}
password: ${{ secrets.CYPRESS_DHIS2_PASSWORD }}
recordkey: ${{ secrets.CYPRESS_RECORD_KEY }}
reportportal_api_key: ${{ secrets.REPORTPORTAL_API_KEY }}
reportportal_endpoint: ${{ vars.REPORTPORTAL_ENDPOINT }}
reportportal_project: ${{ vars.REPORTPORTAL_PROJECT }}
62 changes: 37 additions & 25 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ 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 @@ -42,42 +49,47 @@ async function setupNodeEvents(on, config) {

module.exports = defineConfig({
projectId: 'm5qvjx',
reporter: '@reportportal/agent-js-cypress',
reporter: 'cypress-multi-reporters',
reporterOptions: {
endpoint: process.env.REPORTPORTAL_ENDPOINT,
apiKey: process.env.REPORTPORTAL_API_KEY,
launch: 'line_listing_app',
project: process.env.REPORTPORTAL_PROJECT,
description: '',
autoMerge: true,
parallel: true,
debug: false,
restClientConfig: {
timeout: 660000,
},
attributes: [
{
key: 'dhis2_version',
value: process.env.DHIS2_VERSION,
reporterEnabled: ['@reportportal/agent-js-cypress', 'spec'],
reportportalAgentJsCypressReporterOptions: {
endpoint: process.env.REPORTPORTAL_ENDPOINT,
apiKey: process.env.REPORTPORTAL_API_KEY,
launch: 'line_listing_app',
project: process.env.REPORTPORTAL_PROJECT,
description: '',
autoMerge: true,
parallel: true,
debug: false,
restClientConfig: {
timeout: 660000,
},
{
key: 'app_name',
value: 'line-listing-app',
},
{
key: 'test_level',
value: 'e2e',
},
],
attributes: [
{
key: 'dhis2_version',
value: process.env.DHIS2_VERSION,
},
{
key: 'app_name',
value: 'line-listing-app',
},
{
key: 'test_level',
value: 'e2e',
},
],
},
},
e2e: {
setupNodeEvents,
baseUrl: 'http://localhost:3000',
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
44 changes: 38 additions & 6 deletions cypress/helpers/startScreen.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
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) => {
cy.visit('/', EXTENDED_TIMEOUT).log(Cypress.env('dhis2BaseUrl'))
if (!skipEval) {
expectStartScreenToBeVisible()
}
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')
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()
}
69 changes: 57 additions & 12 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ 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 @@ -46,37 +51,77 @@ before(() => {
j_password: password,
'2fa_code': '',
},
}).should((response) => {
}).then((response) => {
cy.task('log', `Login request returned status: ${response.status}`)
expect(response.status).to.eq(200)
})

cy.getAllCookies()
.should((cookies) => {
expect(cookies.length).to.be.at.least(1)
})
.then((cookies) => {
const sessionCookieForBaseUrl = findSessionCookieForBaseUrl(
baseUrl,
cookies
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
)}`
)
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 { name, value, ...options } = JSON.parse(Cypress.env(envVariableName))
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)

localStorage.setItem(LOCAL_STORAGE_KEY, baseUrl)
cy.setCookie(name, value, options)

cy.getAllCookies().should((cookies) => {
cy.getAllCookies().then((cookies) => {
cy.task('log', `Cookies in beforeEach: ${JSON.stringify(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()
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.1.4",
"cypress": "^13.10.0",
"cypress-multi-reporters": "^1.6.4",
"cypress-tags": "^1.2.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.8",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7007,6 +7007,14 @@ csstype@^3.0.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9"
integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==

cypress-multi-reporters@^1.6.4:
version "1.6.4"
resolved "https://registry.yarnpkg.com/cypress-multi-reporters/-/cypress-multi-reporters-1.6.4.tgz#6f9d25ed8a0d8d7fa5597977adcd2237d1249931"
integrity sha512-3xU2t6pZjZy/ORHaCvci5OT1DAboS4UuMMM8NBAizeb2C9qmHt+cgAjXgurazkwkPRdO7ccK39M5ZaPCju0r6A==
dependencies:
debug "^4.3.4"
lodash "^4.17.21"

cypress-tags@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/cypress-tags/-/cypress-tags-1.2.2.tgz#1d992a3eb7f5db9b8b87911cc82c94d7ee9dd217"
Expand Down