Last active
March 29, 2018 17:57
-
-
Save justinph/8ca5c4f5e248180e29a5858d5c71c5e8 to your computer and use it in GitHub Desktop.
Webpage performance testing with nightmare.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Nightmare = require('nightmare'); | |
let harPlugin = require('nightmare-har-plugin'); | |
let options = { | |
waitTimeout: 1000 | |
}; | |
harPlugin.install(Nightmare); | |
let nightmare = Nightmare(Object.assign(harPlugin.getDevtoolsOptions(), options)); | |
// expects URL passed in as arg | |
let url = process.argv[2]; | |
if (!url) { | |
process.exit(1); | |
} | |
nightmare | |
.viewport(1024, 768) | |
.waitForDevtools() | |
.goto(url) | |
.wait('body') | |
.getHAR() | |
.end() | |
.then((result) => { | |
let onLoad = result.pages[0].pageTimings.onLoad; | |
console.log(onLoad); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "performance-testing-nightmare", | |
"version": "1.0.0", | |
"description": "browser perfromance test validation", | |
"dependencies": { | |
"nightmare": "^2.9.0", | |
"nightmare-har-plugin": "^0.9.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for run in {1..40} | |
do | |
baseline=$(node nightmare.js 'http://www.nytimes.com/2016/test-page-1.html') | |
secondary=$(node nightmare.js 'http://www.nytimes.com/2016/test-page-2.html') | |
echo $baseline, $secondary | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Really cool! I forked it on this repository. For some reason the loop structure was failing to my 4.3 bash, btw.