-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpagetest-chrome-recorder.js
67 lines (61 loc) · 1.63 KB
/
webpagetest-chrome-recorder.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
import WebPageTest from "webpagetest";
import { WPTStringifyChromeRecording } from "webpagetest-chrome-recorder";
//Recording generated using chrome recorder
const recordingContent = {
title: "Webpagetest Chrome Recorder",
steps: [
{
type: "setViewport",
width: 1263,
height: 600,
deviceScaleFactor: 1,
isMobile: false,
hasTouch: false,
isLandscape: false,
},
{
type: "navigate",
url: "https://blog.webpagetest.org/",
assertedEvents: [
{
type: "navigation",
url: "https://blog.webpagetest.org/",
title: "WebPageTest Blog",
},
],
},
{
type: "click",
target: "main",
selectors: [["header li:nth-of-type(2) > a"]],
offsetY: 27.802078247070312,
offsetX: 26.427078247070312,
assertedEvents: [
{
type: "navigation",
url: "https://blog.webpagetest.org/categories/webpagetest-news/",
title: "",
},
],
},
],
};
//Converting json recording to webpagetest script
const script = await WPTStringifyChromeRecording(recordingContent);
console.log("Stringified Webpagetest Recorder Script: \n\n" + script + "\n");
// Initializing webpagetest
const wptServer = "https://www.webpagetest.org";
const wpt = new WebPageTest(wptServer, "YOUR_API_KEY");
let options = {
firstViewOnly: true,
label: recordingContent.title,
};
console.log("Webpagetest Custom Script Test Result: \n");
// Run the test using webpagetest script
wpt.runTest(script, options, (err, result) => {
if (result) {
console.log(result);
} else {
console.log(err);
}
});