Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
test-runner: preflight/test-runner@1.0.9
Use test-runner
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Run a test, take screenshot of each step and wait result.
1
2
3
4
5
6
7
8
9
10
11
12
13
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: <test-id>
environmentId: ''
platforms: ''
sizes: ''
captureScreenshots: true
waitResults: true
Run a group of tests, take screenshot of each step and wait results.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-group-test:
jobs:
- preflight/run_group_test:
groupId: <group-id>
environmentId: ''
platforms: ''
sizes: ''
tags: ''
captureScreenshots: true
waitResults: true
Run all your PreFlight tests. While running tests take a screenshot of each step and wait for each result.
1
2
3
4
5
6
7
8
9
10
11
12
13
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-all-tests:
jobs:
- preflight/run_all_tests:
environmentId: ''
platforms: ''
sizes: ''
tags: ''
captureScreenshots: true
waitResults: true
Run tests that are tagged with the given tags
1
2
3
4
5
6
7
8
9
10
11
12
13
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-all-tests:
jobs:
- preflight/run_all_tests:
environmentId: ''
platforms: ''
sizes: ''
tags: smoke tests,critical tests
captureScreenshots: true
waitResults: true
Run a test across your development environments.
1
2
3
4
5
6
7
8
9
10
11
12
13
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: <test-id>
environmentId: <environment-id>
platforms: ''
sizes: ''
captureScreenshots: true
waitResults: true
Run a test across different browsers.
1
2
3
4
5
6
7
8
9
10
11
12
13
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: <test-id>
environmentId: ''
platforms: win-ie,win-firefox
sizes: ''
captureScreenshots: true
waitResults: true
Run a test at different screen sizes.
1
2
3
4
5
6
7
8
9
10
11
12
13
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: <test-id>
environmentId: ''
platforms: ''
sizes: 1920x1080,1440x900
captureScreenshots: true
waitResults: true
Run a test.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
clientIdKey | Variable name of PreFlight Client Id. | No | PF_CLIENT_ID | env_var_name |
clientSecretKey | Variable name of PreFlight Client Secret. | No | PF_CLIENT_SECRET | env_var_name |
testId | PreFlight test id. | Yes | - | string |
environmentId | (optional) PreFlight environment id | No | '' | string |
platforms | (optional) Platform(s) and browser(s) you want to run your PreFlight test(s) | No | '' | string |
sizes | (optional) Size(s) you want to run your PreFlight test(s) | No | '' | string |
captureScreenshots | (optional) Capture screenshots enables taking screenhots of the each step. | No | true | boolean |
waitResults | (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s). | No | true | boolean |
Run group test.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
clientIdKey | Variable name of PreFlight Client Id. | No | PF_CLIENT_ID | env_var_name |
clientSecretKey | Variable name of PreFlight Client Secret. | No | PF_CLIENT_SECRET | env_var_name |
groupId | PreFlight group id. | Yes | - | string |
environmentId | (optional) PreFlight environment id | No | '' | string |
platforms | (optional) Platform(s) and browser(s) you want to run your PreFlight test(s) | No | '' | string |
sizes | (optional) Size(s) you want to run your PreFlight test(s) | No | '' | string |
tags | (optional) Run tests that are tagged with the given tags | No | '' | string |
captureScreenshots | (optional) Capture screenshots enables taking screenhots of the each step. | No | true | boolean |
waitResults | (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s). | No | true | boolean |
Run all tests.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
clientIdKey | Variable name of PreFlight Client Id. | No | PF_CLIENT_ID | env_var_name |
clientSecretKey | Variable name of PreFlight Client Secret. | No | PF_CLIENT_SECRET | env_var_name |
environmentId | (optional) PreFlight environment id | No | '' | string |
platforms | (optional) Platform(s) and browser(s) you want to run your PreFlight test(s) | No | '' | string |
sizes | (optional) Size(s) you want to run your PreFlight test(s) | No | '' | string |
tags | (optional) Run tests that are tagged with the given tags | No | '' | string |
captureScreenshots | (optional) Capture screenshots enables taking screenhots of the each step. | No | true | boolean |
waitResults | (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s). | No | true | boolean |
Trigger your PreFlight tests with given paramaters.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
clientIdKey | Variable name of PreFlight Client Id. | No | PF_CLIENT_ID | env_var_name |
clientSecretKey | Variable name of PreFlight Client Secret. | No | PF_CLIENT_SECRET | env_var_name |
testId | (optional) PreFlight test id. | No | '' | string |
groupId | (optional) PreFlight test group id. | No | '' | string |
environmentId | (optional) PreFlight environment id | No | '' | string |
platforms | (optional) Platform(s) and browser(s) you want to run your PreFlight test(s) | No | '' | string |
sizes | (optional) Size(s) you want to run your PreFlight test(s) | No | '' | string |
tags | (optional) Run tests that are tagged with the given tags | No | '' | string |
captureScreenshots | (optional) Capture screenshots enables taking screenhots of the each step. | No | true | boolean |
waitResults | (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s). | No | true | boolean |
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
# This code is licensed from CircleCI to the user under the MIT license. See
# https://circleci.com/orbs/registry/licensing for details.
version: 2.1
description: |
Execute your PreFlight tests within your CircleCI build.
display:
home_url: https://preflight.com/
source_url: https://github.com/Preflight-HQ/PreFlight.CircleCI
examples:
run_a_test:
description: Run a test, take screenshot of each step and wait result.
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: "<test-id>"
environmentId: ""
platforms: ""
sizes: ""
captureScreenshots: true
waitResults: true
run_group_test:
description: Run a group of tests, take screenshot of each step and wait results.
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-group-test:
jobs:
- preflight/run_group_test:
groupId: "<group-id>"
environmentId: ""
platforms: ""
sizes: ""
tags: ""
captureScreenshots: true
waitResults: true
run_all_tests:
description: Run all your PreFlight tests. While running tests take a screenshot of each step and wait for each result.
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-all-tests:
jobs:
- preflight/run_all_tests:
environmentId: ""
platforms: ""
sizes: ""
tags: ""
captureScreenshots: true
waitResults: true
filter_tests_with_tags:
description: Run tests that are tagged with the given tags
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-all-tests:
jobs:
- preflight/run_all_tests:
environmentId: ""
platforms: ""
sizes: ""
tags: "smoke tests,critical tests"
captureScreenshots: true
waitResults: true
across_different_environments:
description: Run a test across your development environments.
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: "<test-id>"
environmentId: "<environment-id>"
platforms: ""
sizes: ""
captureScreenshots: true
waitResults: true
across_different_browsers:
description: Run a test across different browsers.
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: "<test-id>"
environmentId: ""
platforms: "win-ie,win-firefox"
sizes: ""
captureScreenshots: true
waitResults: true
different_screen_sizes:
description: Run a test at different screen sizes.
usage:
version: 2.1
orbs:
preflight: preflight/test-runner@1.0
workflows:
run-a-test:
jobs:
- preflight/run_a_test:
testId: "<test-id>"
environmentId: ""
platforms: ""
sizes: "1920x1080,1440x900"
captureScreenshots: true
waitResults: true
commands:
run_test:
description: Trigger your PreFlight tests with given paramaters.
parameters:
clientIdKey:
type: env_var_name
description: Variable name of PreFlight Client Id.
default: PF_CLIENT_ID
clientSecretKey:
type: env_var_name
description: Variable name of PreFlight Client Secret.
default: PF_CLIENT_SECRET
testId:
type: string
description: (optional) PreFlight test id.
default: ""
groupId:
type: string
description: (optional) PreFlight test group id.
default: ""
environmentId:
type: string
description: (optional) PreFlight environment id
default: ""
platforms:
type: string
description: (optional) Platform(s) and browser(s) you want to run your PreFlight test(s)
default: ""
sizes:
type: string
description: (optional) Size(s) you want to run your PreFlight test(s)
default: ""
tags:
type: string
description: (optional) Run tests that are tagged with the given tags
default: ""
captureScreenshots:
type: boolean
description: (optional) Capture screenshots enables taking screenhots of the each step.
default: true
waitResults:
type: boolean
description: (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s).
default: true
steps:
- run:
name: Run tests
command: |
function GetPlatformAndBrowser(){
PLATFORM_JSON=""
PLATFORM="$(echo $1 | cut -d "-" -f 1)"
PLATFORM_LOWERCASE=$(echo ${PLATFORM,,})
PLATFORM_NO_WHITESPACE=$(echo -e "${PLATFORM_LOWERCASE}" | tr -d '[:space:]')
case $PLATFORM_NO_WHITESPACE in
win)
PLATFORM_JSON="windows" ;;
*)
echo "Invalid platform."
exit 1 ;;
esac
BROWSER_JSON=""
BROWSER="$(echo $1 | cut -d "-" -f 2)"
BROWSER_LOWERCASE=$(echo ${BROWSER,,})
BROWSER_NO_WHITESPACE=$(echo -e "${BROWSER_LOWERCASE}" | tr -d '[:space:]')
case $BROWSER_NO_WHITESPACE in
ie)
BROWSER_JSON="internetexplorer" ;;
edge | firefox | chrome )
BROWSER_JSON=$BROWSER_NO_WHITESPACE ;;
*)
echo "Invalid browser."
exit 1 ;;
esac
local JSON_STRING=$( jq -r -n --arg pl "$PLATFORM_JSON" --arg br "$BROWSER_JSON" '{"platform": $pl, "browser": $br}' )
echo $JSON_STRING
}
function GetSize(){
WIDTH="$(echo $1 | cut -d "x" -f 1)"
WIDTH_NO_WHITESPACE="$(echo -e "${WIDTH}" | tr -d '[:space:]')"
HEIGHT="$(echo $1 | cut -d "x" -f 2)"
HEIGHT_NO_WHITESPACE="$(echo -e "${HEIGHT}" | tr -d '[:space:]')"
local JSON_STRING=$( jq -n --arg wdth "$WIDTH_NO_WHITESPACE" --arg hght "$HEIGHT_NO_WHITESPACE" '{"width": $wdth, "height": $hght}' );
echo $JSON_STRING
}
function WaitResults(){
echo "Waiting for test result(s)"
WAIT=true
MAXRETRY=10
TRIED=0
while [ "$WAIT" = true ]
do
TEST_RUN_RESULT=$(curl -s -H"Authorization: bearer $ACCESS_TOKEN" "$API_URL/run/$TEST_RUN_ID")
if [ "$TEST_RUN_RESULT" = "Not found" ]
then
if [ $TRIED -lt $MAXRETRY ]
then
sleep 5
((TRIED++))
continue
else
echo "Test(s) could not be found."
exit 1
fi
fi
echo "$TEST_RUN_RESULT"
FAILED=$( echo "$TEST_RUN_RESULT" | jq -r '.results[] | select(.status == "Failed")')
if [ -n "$FAILED" ]
then
echo "Below test(s) failed."
echo "$FAILED"
exit 1
fi
WAITING=$( echo "$TEST_RUN_RESULT" | jq -r '.results[] | select(.status == ("Queued","Running"))')
if [ -n "$WAITING" ]
then
echo "Waiting for all the tests to be completed."
else
echo "All test(s) successfully completed."
exit 0
fi
sleep 5
done
}
CLIENT_ID=${<< parameters.clientIdKey >>}
CLIENT_SECRET=${<< parameters.clientSecretKey >>}
TEST_ID="<< parameters.testId >>"
GROUP_ID="<< parameters.groupId >>"
ENVIRONMENT_ID="<< parameters.environmentId >>"
PLATFORMS="<< parameters.platforms >>"
SIZES="<< parameters.sizes >>"
TAGS="<< parameters.tags >>"
WAIT_RESULTS="<< parameters.waitResults >>"
CAPTURE_SCREENSHOTS="<< parameters.captureScreenshots >>"
API_URL="https://api.preflight.com/v1/tests"
TOKEN_URL="https://auth.preflight.com/connect/token"
TOKEN_REQUEST_BODY="client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=client_credentials&scope=tests_run"
TOKEN_RESULT=$(curl -k -s -XPOST -H"Content-Type: application/x-www-form-urlencoded" -d"$TOKEN_REQUEST_BODY" "$TOKEN_URL")
ACCESS_TOKEN=$(echo $TOKEN_RESULT | jq -r '.access_token')
echo "Access Token : $ACCESS_TOKEN"
RUN_REQUEST_BODY='{
"platforms":[],
"sizes":[],
"tags":[],
"captureScreenshots":'"$CAPTURE_SCREENSHOTS"'
}'
PLATFORM_BROWSER_LIST=()
if [ -n "$PLATFORMS" ]
then
for PLATFORM_BROWSER in $(echo $PLATFORMS | tr "," "\n")
do
RES=$(GetPlatformAndBrowser "$PLATFORM_BROWSER")
RUN_REQUEST_BODY=$(echo $RUN_REQUEST_BODY | jq --argjson RES "$RES" '.platforms |= .+ [$RES]' )
done
fi
SIZES_ARRAY=()
if [ -n "$SIZES" ]
then
for SIZE in $(echo $SIZES | tr "," "\n")
do
RES=$(GetSize "$SIZE")
RUN_REQUEST_BODY=$(echo $RUN_REQUEST_BODY | jq --argjson RES "$RES" '.sizes |= .+ [$RES]' )
done
fi
TAGS_ARRAY=()
if [ -n "$TAGS" ]
then
for TAG in $(echo $TAGS | tr "," "\n")
do
RUN_REQUEST_BODY=$(echo $RUN_REQUEST_BODY | jq --arg TAG "$TAG" '.tags |= .+ [$TAG]' )
done
fi
REQUEST_PATH="Run"
if [ -n "$TEST_ID" ]
then
REQUEST_PATH=$TEST_ID"/Run"
elif [ -n "$GROUP_ID" ]
then
RUN_REQUEST_BODY=$(echo $RUN_REQUEST_BODY | jq -r --arg GRPID $GROUP_ID '. += {groupId: $GRPID}')
fi
if [ -n "$ENVIRONMENT_ID" ]
then
RUN_REQUEST_BODY=$(echo $RUN_REQUEST_BODY | jq -r --arg ENVID $ENVIRONMENT_ID '. += {environmentId: $ENVID}')
fi
echo "$RUN_REQUEST_BODY"
TEST_RESULT=$(curl -s -XPOST -H"Content-Type: application/json" -H"Authorization: bearer $ACCESS_TOKEN" -d"$RUN_REQUEST_BODY" "$API_URL/$REQUEST_PATH")
echo "$TEST_RESULT"
TEST_RUN_ID=$(echo $TEST_RESULT | jq -r '.testRunId')
if [ -z "$TEST_RUN_ID" ]
then
echo "The test run has been failed."
exit 1
fi
echo "The test(s) has been successfully queued.TestRunId : $TEST_RUN_ID"
if [ "$WAIT_RESULTS" = true ]
then
n=0
until [ "$n" -ge 5 ]
do
WaitResults && break
n=$((n+1))
sleep 10
done
else
exit 0
fi
jobs:
run_a_test:
description: Run a test.
parameters:
clientIdKey:
type: env_var_name
description: Variable name of PreFlight Client Id.
default: PF_CLIENT_ID
clientSecretKey:
type: env_var_name
description: Variable name of PreFlight Client Secret.
default: PF_CLIENT_SECRET
testId:
type: string
description: PreFlight test id.
environmentId:
type: string
description: (optional) PreFlight environment id
default: ""
platforms:
type: string
description: (optional) Platform(s) and browser(s) you want to run your PreFlight test(s)
default: ""
sizes:
type: string
description: (optional) Size(s) you want to run your PreFlight test(s)
default: ""
captureScreenshots:
type: boolean
description: (optional) Capture screenshots enables taking screenhots of the each step.
default: true
waitResults:
type: boolean
description: (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s).
default: true
docker:
- image: cimg/node:lts
steps:
- run_test:
clientIdKey: << parameters.clientIdKey >>
clientSecretKey: << parameters.clientSecretKey >>
testId: << parameters.testId >>
environmentId: << parameters.environmentId >>
platforms: << parameters.platforms >>
sizes: << parameters.sizes >>
captureScreenshots: << parameters.captureScreenshots >>
waitResults: << parameters.waitResults >>
run_group_test:
description: Run group test.
parameters:
clientIdKey:
type: env_var_name
description: Variable name of PreFlight Client Id.
default: PF_CLIENT_ID
clientSecretKey:
type: env_var_name
description: Variable name of PreFlight Client Secret.
default: PF_CLIENT_SECRET
groupId:
type: string
description: PreFlight group id.
environmentId:
type: string
description: (optional) PreFlight environment id
default: ""
platforms:
type: string
description: (optional) Platform(s) and browser(s) you want to run your PreFlight test(s)
default: ""
sizes:
type: string
description: (optional) Size(s) you want to run your PreFlight test(s)
default: ""
tags:
type: string
description: (optional) Run tests that are tagged with the given tags
default: ""
captureScreenshots:
type: boolean
description: (optional) Capture screenshots enables taking screenhots of the each step.
default: true
waitResults:
type: boolean
description: (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s).
default: true
docker:
- image: cimg/node:lts
steps:
- run_test:
clientIdKey: << parameters.clientIdKey >>
clientSecretKey: << parameters.clientSecretKey >>
groupId: << parameters.groupId >>
environmentId: << parameters.environmentId >>
platforms: << parameters.platforms >>
sizes: << parameters.sizes >>
tags: << parameters.tags >>
captureScreenshots: << parameters.captureScreenshots >>
waitResults: << parameters.waitResults >>
run_all_tests:
description: Run all tests.
parameters:
clientIdKey:
type: env_var_name
description: Variable name of PreFlight Client Id.
default: PF_CLIENT_ID
clientSecretKey:
type: env_var_name
description: Variable name of PreFlight Client Secret.
default: PF_CLIENT_SECRET
environmentId:
type: string
description: (optional) PreFlight environment id
default: ""
platforms:
type: string
description: (optional) Platform(s) and browser(s) you want to run your PreFlight test(s)
default: ""
sizes:
type: string
description: (optional) Size(s) you want to run your PreFlight test(s)
default: ""
tags:
type: string
description: (optional) Run tests that are tagged with the given tags
default: ""
captureScreenshots:
type: boolean
description: (optional) Capture screenshots enables taking screenhots of the each step.
default: true
waitResults:
type: boolean
description: (optional) Wait PreFlight test result(s). If you set it as true, your CircleCI build waits your PreFlight test result(s).
default: true
docker:
- image: cimg/node:lts
steps:
- run_test:
clientIdKey: << parameters.clientIdKey >>
clientSecretKey: << parameters.clientSecretKey >>
environmentId: << parameters.environmentId >>
platforms: << parameters.platforms >>
sizes: << parameters.sizes >>
tags: << parameters.tags >>
captureScreenshots: << parameters.captureScreenshots >>
waitResults: << parameters.waitResults >>