Skip to content

Instantly share code, notes, and snippets.

@axemclion
Created September 19, 2015 04:06
Show Gist options
  • Save axemclion/38265a963f5a863f7a53 to your computer and use it in GitHub Desktop.
Save axemclion/38265a963f5a863f7a53 to your computer and use it in GitHub Desktop.
Getting Chrome timeline from Selenium Log
var wd = require('wd');
// This is for Chromedriver directly.
// If you are using Selenium, use http://localhost:4444/wd/hub
var browser = wd.promiseRemote('http://localhost:9515');
var URL = 'http://islreview.com/'; // Change this to a custom URL
var config = {
"browserName": "chrome",
"chromeOptions": {
"perfLoggingPrefs": {
"traceCategories": ",blink.console,disabled-by-default-devtools.timeline,benchmark"
},
"args": ["--enable-gpu-benchmarking", "--enable-thread-composting"]
},
"loggingPrefs": {
"performance": "ALL"
}
};
browser.init(config).then(function() {
console.log('Fetching URL', URL);
return browser.get(URL);
}).then(function() {
console.log('Flushing timeline data before we start collecting it for real');
return browser.log('performance');
}).then(function() {
console.log('Sending the scroll function to the browser and executing it');
return browser.execute('(' + scroll.toString() + ')()');
}).then(function() {
console.log('Wait for scroll to finish. When it finishes, it sets the __scrollComplete__ to true');
return browser.waitFor({
asserter: wd.asserters.jsCondition('(window.__scrollComplete__ === true)', false),
timeout: 1000 * 60 * 10,
pollFreq: 2000
});
}).then(function() {
console.log('Getting actual timeline data - this will take a while');
return browser.log('performance');
}).then(function(data) {
console.log('Saving timeline data to a file _perflog.json');
require('fs').writeFileSync('_perflog.json', JSON.stringify(data.map(function(record) {
return JSON.parse(record.message).message;
})), null, 4);
}).fin(function() {
// Disable the following statement if you want to keep the browser open
return browser.quit();
}).done();
// This function scrolls the page. Calling this function from the browser dev tools console should also scroll the pgae
var scroll = function() {
window.chrome.gpuBenchmarking.smoothScrollBy(5000, function() {
window.__scrollComplete__ = true;
}, 0, 0, chrome.gpuBenchmarking.DEFAULT_INPUT, 'down', 800);
}
@peagey
Copy link

peagey commented May 16, 2016

Hi,
Sounds interesting.
The output file doesn't seem to be a HAR type file.
So how do you analyze the results?
Regards,

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