-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwoo-customer.js
145 lines (113 loc) · 4.06 KB
/
woo-customer.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import http from 'k6/http'
import { Rate, Trend } from 'k6/metrics'
import { check, group, fail, sleep } from 'k6'
import Metrics from './lib/metrics.js';
import { isOK, pageIsNotLogin } from './lib/checks.js'
import { rand, validateSiteUrl, responseWasCached, bypassPageCacheCookies } from './lib/helpers.js'
export const options = {
throw: true,
summaryTimeUnit: 'ms',
scenarios: {
ramping: {
executor: 'ramping-vus',
startVUs: 1,
gracefulStop: '10s',
gracefulRampDown: '10s',
stages: [
{ duration: '1m', target: 100 },
],
},
// constant: {
// executor: 'constant-vus',
// vus: 100,
// duration: '1m',
// gracefulStop: '10s',
// },
},
ext: {
loadimpact: {
name: 'WooCommerce account flow',
note: 'Loads the homepage, signs in, views at orders and then their account details.',
projectID: __ENV.PROJECT_ID || null
},
},
}
const errorRate = new Rate('errors')
const responseCacheRate = new Rate('response_cached')
// These metrics are provided by Object Cache Pro when `analytics.footnote` is enabled
const metrics = new Metrics();
export function setup () {
return {
startedAt: Date.now(),
}
}
export function teardown (data) {
const startedAt = new Date(data.startedAt)
const endedAt = new Date()
console.info(`Run started at ${startedAt.toJSON()}`)
console.info(`Run ended at ${endedAt.toJSON()}`)
}
export default function () {
const jar = new http.CookieJar()
const siteUrl = __ENV.SITE_URL
validateSiteUrl(siteUrl);
const pause = {
min: 3,
max: 8,
}
if (__ENV.BYPASS_CACHE) {
Object.entries(bypassPageCacheCookies()).forEach(([key, value]) => {
jar.set(siteUrl, key, value, { path: '/' })
})
}
group('Load homepage', function () {
const response = http.get(siteUrl, { jar })
check(response, isOK)
|| (errorRate.add(1) && fail('status code was *not* 200'))
metrics.addResponseMetrics(response)
responseCacheRate.add(responseWasCached(response))
})
sleep(rand(pause.min, pause.max))
group('Login', function () {
const response = http.get(`${siteUrl}/my-account/`, { jar })
check(response, isOK)
|| (errorRate.add(1) && fail('status code was *not* 200'))
metrics.addResponseMetrics(response)
responseCacheRate.add(responseWasCached(response))
const formResponse = response.submitForm({
formSelector: 'form.woocommerce-form-login',
params: { jar },
fields: {
username: `test${rand(1, 100)}`,
password: '3405691582',
rememberme: 'forever',
},
})
check(formResponse, isOK)
|| (errorRate.add(1) && fail('status code was *not* 200'))
check(formResponse, pageIsNotLogin)
|| fail('page *has* login form')
metrics.addResponseMetrics(formResponse)
responseCacheRate.add(responseWasCached(formResponse))
})
sleep(rand(pause.min, pause.max))
group('Load orders', function () {
const response = http.get(`${siteUrl}/my-account/orders/`, { jar })
check(response, isOK)
|| (errorRate.add(1) && fail('status code was *not* 200'))
check(response, pageIsNotLogin)
|| fail('page *has* login form')
metrics.addResponseMetrics(response)
responseCacheRate.add(responseWasCached(response))
})
sleep(rand(pause.min, pause.max))
group('Load orders', function () {
const response = http.get(`${siteUrl}/my-account/orders/`, { jar })
check(response, isOK)
|| (errorRate.add(1) && fail('status code was *not* 200'))
check(response, pageIsNotLogin)
|| fail('page *has* login form')
metrics.addResponseMetrics(response)
responseCacheRate.add(responseWasCached(response))
})
}