Skip to content

Commit

Permalink
Refactor k6 test to check each page in trust results and add to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
cshnimble committed Aug 8, 2024
1 parent 59f3ede commit 348d2fc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/performance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Run k6 test
uses: grafana/[email protected]
with:
filename: suite.js
filename: trustOverview.js
env:
BASE_URL: ${{ secrets.TRAMS_API_BASE_URL }}
AUTHORIZATION_HEADER: ${{ secrets.TEST_OVERRIDE_CYPRESS_TEST_SECRET }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,43 @@ export default async function () {
'User-Agent': 'FindInformationAcademiesTrusts/1.0 k6-browser'
})

// Go through each page for the trust and capture the page load timings
try {
await page.goto(`${baseUrl}/trusts/details?uid=5143`)
await page.waitForLoadState('domcontentloaded')
await page.evaluate(() => window.performance.mark('page_load_time'));
await checkPageLoadTiming(page, `${baseUrl}/trusts/details?uid=5143`)

const totalActionTime = await page.evaluate(
() =>
JSON.parse(JSON.stringify(window.performance.getEntriesByName('page_load_time')))[0]
.startTime
)
await checkPageLoadTiming(page, `${baseUrl}/trusts/contacts?uid=5143`)

trend.add(totalActionTime)
await checkPageLoadTiming(page, `${baseUrl}/trusts/overview?uid=5143`)

await checkPageLoadTiming(page, `${baseUrl}/trusts/academies/details?uid=5143`)

await checkPageLoadTiming(page, `${baseUrl}/trusts/academies/ofsted-ratings?uid=5143`)

await checkPageLoadTiming(page, `${baseUrl}/trusts/academies/pupil-numbers?uid=5143`)
}
finally {
await page.close()
}
}

async function checkPageLoadTiming(page, url) {
await page.goto(url)
await page.evaluate(() => window.performance.mark('page_load_time'));

let totalActionTime = await page.evaluate(
() =>
JSON.parse(JSON.stringify(window.performance.getEntriesByName('page_load_time')))[0]
.startTime
)

trend.add(totalActionTime)

Promise.resolve()
}

export function handleSummary(data) {
return {
'summary.html': htmlReport(data),
stdout: textSummary(data, { indent: ' ', enableColors: true }),
}
}
}

0 comments on commit 348d2fc

Please sign in to comment.