forked from CMU-313/cmu-313-f24-nodebb-f24-NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k6-test.js
110 lines (100 loc) · 3.55 KB
/
k6-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import http from 'k6/http';
import { browser } from 'k6/browser';
import { check, sleep } from 'k6';
export const options = {
thresholds: {
http_req_failed: [
{
threshold: 'rate<0.20', // http errors should be less than 10%
abortOnFail: true,
delayAbortEval: '10s',
},
],
http_req_duration: [
{
threshold: 'p(95) < 3000',// 95% of requests should be below 2s
abortOnFail: true,
delayAbortEval: '10s',
},
],
},
scenarios: {
performance: {
executor: 'ramping-vus',
stages : [
{ duration: '10s', target: 10 },
{ duration: '30s', target: 20 },
{ duration: '30s', target: 40 },
{ duration: '30s', target: 80 },
{ duration: '30s', target: 160 },
]
},
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
exec: 'ui_test',
}
}
};
// The function that defines VU logic.
//
// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more
// about authoring k6 scripts.
//
export default function() {
const res = http.get('https://nodebb-team-bulbasaur1.azurewebsites.net/');
sleep(1);
};
export async function ui_test(){
const page = await browser.newPage();
try {
//login as admin
await page.goto('https://nodebb-team-bulbasaur1.azurewebsites.net/login');
await page.locator('input[name="username"]').fill('admin');
await page.locator('input[name="password"]').fill('bulbasaur');
const submitButton = page.locator('button[type="submit"]');
await Promise.all([
page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: 60000 }),
submitButton.click()
]);
// go to testing topic
await page.goto("https://nodebb-team-bulbasaur1.azurewebsites.net/topic/5/do-not-post-here", { waitUntil: 'networkidle' });
// test for solve/unsolve in topic
await page.waitForSelector('div[component="topic/solve"]');
const solveButton = page.locator('div[component="topic/solve"]');
const solveButtonStatus = await solveButton.textContent();
console.log('solveButtonStatus:', solveButtonStatus);
const newSolveButton = page.locator('div[component="topic/solve"]');
if (solveButtonStatus && solveButtonStatus.includes('Unsolved')) {
console.log('Clicking the solve button because status is Unsolved...');
await solveButton.click();
await page.waitForTimeout(2000); // Wait for the button state to change after clicking
// Verify the button has changed to 'Solved'
const newSolveButtonText = await solveButton.textContent();
const solvedStatusCheck = newSolveButtonText.includes('Solved');
console.log(`New solve button status: ${newSolveButtonText}`);
check(solvedStatusCheck, {
'is status Solved': (status) => status === true,
});
} else {
console.log('Clicking the solve button because status is Unsolved...');
await solveButton.click();
await page.waitForTimeout(2000); // Wait for the button state to change after clicking
// Verify the button has changed to 'Unsolved'
const newSolveButtonText = await solveButton.textContent();
const solvedStatusCheck = newSolveButtonText.includes('Unsolved');
console.log(`New solve button status: ${newSolveButtonText}`);
check(solvedStatusCheck, {
'is status Unsolved': (status) => status === true,
});
}
//reset solve button status
await solveButton.click();
} finally{
await page.close();
}
}