Skip to content

Instantly share code, notes, and snippets.

@justinph
Last active March 29, 2018 17:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinph/8ca5c4f5e248180e29a5858d5c71c5e8 to your computer and use it in GitHub Desktop.
Save justinph/8ca5c4f5e248180e29a5858d5c71c5e8 to your computer and use it in GitHub Desktop.
Webpage performance testing with nightmare.js
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);
});
{
"name": "performance-testing-nightmare",
"version": "1.0.0",
"description": "browser perfromance test validation",
"dependencies": {
"nightmare": "^2.9.0",
"nightmare-har-plugin": "^0.9.0"
}
}
#!/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
@IronistM
Copy link

IronistM commented Feb 8, 2017

Really cool! I forked it on this repository. For some reason the loop structure was failing to my 4.3 bash, btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment