Skip to content

Commit

Permalink
FHB-634: Finalise Find performance Tests (#228)
Browse files Browse the repository at this point in the history
* finalised find tests

* added sleep

* reverted vus change

* added data test ids for start now and search now

* commented out todo

---------

Co-authored-by: Tina Gohil <[email protected]>
  • Loading branch information
tgohil-hippo and Tina Gohil authored Nov 11, 2024
1 parent 4273e9c commit 274bb14
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
family services and activities in your local area, and are a great place to start looking.
</p>

<a asp-page="/PostcodeSearch/index" role="button" draggable="false" class="govuk-button govuk-button--start" data-module="govuk-button">
<a asp-page="/PostcodeSearch/index" data-testid="start-button" role="button" draggable="false" class="govuk-button govuk-button--start" data-module="govuk-button">
Start now
<svg class="govuk-button__start-icon" xmlns="http://www.w3.org/2000/svg" width="17.5" height="19" viewBox="0 0 33 40" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M0 0h13l20 20-20 20H0l20-20z" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</div>
}

<button class="govuk-button" data-module="govuk-button">Search</button>
<button class="govuk-button" data-testid="search-button" data-module="govuk-button">Search</button>

</form>
</div>
Expand Down
3 changes: 2 additions & 1 deletion test/k6/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Web Browser Performance Testing with K6

Here we have written performance tests for the three services in Family Hubs: Find, Connect, Manage.

# Prerequisites

- Install k6 locally
- Install k6 locally from https://grafana.com/docs/k6/latest/set-up/install-k6/
- Run data seed scripts
- Navigate to folder of service under test (i.e. find-tests, connect-tests, or manage-tests)
NOTE: Playwright is not required as we use K6 with playwright under the hood.
Expand Down
8 changes: 4 additions & 4 deletions test/k6/env/local/config.load.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"scenarios": {
"ui": {
"executor": "per-vu-iterations",
"vus": 1,
"vus": 400,

"iterations": 400,
"iterations": 1,
"options": {
"browser": {
"type": "chromium"
Expand All @@ -16,8 +16,8 @@
}
},
"thresholds": {
"http_req_failed": ["rate<0.01"],
"http_req_duration": ["p(95)<200"],
"http_req_failed": ["rate < 0.01"],
"http_req_duration": ["p(95) < 200"],

"browser_web_vital_lcp": ["p(90) < 1000"],
"browser_web_vital_inp": ["p(90) < 80"],
Expand Down
4 changes: 2 additions & 2 deletions test/k6/env/local/config.soak.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
}
},
"thresholds": {
"http_req_failed": ["rate<0.01"],
"http_req_duration": ["p(95)<200"],
"http_req_failed": ["rate < 0.01"],
"http_req_duration": ["p(95) < 200"],

"browser_web_vital_lcp": ["p(90) < 1000"],
"browser_web_vital_inp": ["p(90) < 80"],
Expand Down
4 changes: 2 additions & 2 deletions test/k6/env/local/config.stress.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
}
},
"thresholds": {
"http_req_failed": ["rate<0.01"],
"http_req_duration": ["p(95)<200"],
"http_req_failed": ["rate < 0.01"],
"http_req_duration": ["p(95) < 200"],

"browser_web_vital_lcp": ["p(90) < 1000"],
"browser_web_vital_inp": ["p(90) < 80"],
Expand Down
11 changes: 2 additions & 9 deletions test/k6/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ if (__ENV.OPTIONS_SET) {

// #region LOAD TESTS
// Import tests
import { searchResultsTest } from './tests/find-tests.js';
import { verifyStatusCodeTest } from './tests/find-tests.js';
import {searchResultsTest, serviceDetailsTest, verifyStatusCodeTest, filterSearchResultsTest } from './tests/find-tests.js';

let TESTS = [ searchResultsTest, verifyStatusCodeTest ];
let TESTS = [ searchResultsTest, verifyStatusCodeTest, filterSearchResultsTest, serviceDetailsTest];
// #endregion

// #region k6 OPTIONS
Expand Down Expand Up @@ -53,9 +52,3 @@ export function handleSummary(data) {
"testResults.json": JSON.stringify(data)
};
}

// TODO: data teardown step
//export function teardown(data) {
// teardown code
//}

92 changes: 74 additions & 18 deletions test/k6/tests/find-tests.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,94 @@
import http from 'k6/http';
import { browser } from 'k6/browser';
import { sleep } from 'k6';

import { check, sleep } from 'k6';
export async function searchResultsTest(data) {
const page = await browser.newPage();

try {
await page.goto(`${data.SETTINGS.baseUrl}`);
const startButton = await page.locator('[data-testid="start-button"]');

await Promise.all([startButton.click()]);
await page.locator('[name="postcode"]').type('E1 2EN');

const submitButton = await page.locator('[data-testid="search-button"]');

const startButton = await page.locator('input[class="govuk-button govuk-button--start"]').click();
await Promise.all([submitButton.click()]);

await Promise.all([page.waitForNavigation(), startButton.click()]);
const title = await page.locator('title').textContent();

await page.locator('input[name="postcode"]').type('E1 2EN');
//TODO: Update when data is seeded
await check(title, {
title: title === 'Services, groups and activities in this area (page 1 of 45) - Find support for your family - GOV.UK',
});

} finally {
await page.close();
}
sleep(1);
}

const submitButton = await page.locator('input[type="button"]');
export async function filterSearchResultsTest(data) {
const page = await browser.newPage();

await Promise.all([page.waitForNavigation(), submitButton.click()]);
try {
await page.goto(`${data.SETTINGS.baseUrl}`);
const startButton = await page.locator('[data-testid="start-button"]');

await Promise.all([startButton.click()]);
await page.locator('[name="postcode"]').type('E1 2EN');

const submitButton = await page.locator('[data-testid="search-button"]');

await Promise.all([submitButton.click()]);

const activitiesFilter = await page.locator('[id="activities-10"]');
const freeFilter = await page.locator('[id="cost-free"]');
const tenMileFilter = await page.locator('[id="search_within-1]');

await Promise.all([activitiesFilter.click()], [freeFilter.click()], [tenMileFilter.click()]);

sleep(1);

const headerText = await page.locator('h1').textContent();
check(headerText, {
header: headerText === 'Your local family hubs, services and activities',
}); //title attribute on the head rather than content body.

} finally {
await page.close();
}
sleep(1);
}

export function verifyStatusCodeTest(data) {
const res = http.get(`${data.SETTINGS.baseUrl}/ServiceFilter?postcode=E1%202EN&adminarea=E09000030&latitude=51.517612&longitude=-0.056838&frompostcodesearch=True')`);
export async function serviceDetailsTest(data) {
const page = await browser.newPage();

check(res, {
'status is 200': (r) => r.status === 200,
});
try {
await page.goto(`${data.SETTINGS.baseUrl}`);
const startButton = await page.locator('[data-testid="start-button"]');

await Promise.all([startButton.click()]);
await page.locator('[name="postcode"]').type('E1 2EN');

const submitButton = await page.locator('[data-testid="search-button"]');

await Promise.all([submitButton.click()]);

const firstSearchResult = await page.locator('//*[@id="results"]/div[1]/div');

await Promise.all([firstSearchResult.click()]);

} finally {
await page.close();
}
sleep(1);
}

export async function verifyStatusCodeTest(data) {
const page = await browser.newPage();
try {
const res = await page.goto(`${data.SETTINGS.baseUrl}/ServiceFilter?postcode=E1%202EN&adminarea=E09000030&latitude=51.517612&longitude=-0.056838&frompostcodesearch=True')`);

check(res, {
'status is 200': (r) => r.status === 200,
});
} finally {
await page.close();
}
sleep(1);
}

0 comments on commit 274bb14

Please sign in to comment.