webpagetest-api container
193
WebPageTest API Wrapper is a NPM package that wraps WebPageTest API for NodeJS as a module and a command-line tool.
$ npm install webpagetest -g
$ webpagetest test https://twitter.com/marcelduran
$ docker build -t webpagetest-api .
$ docker run -it --rm webpagetest-api -k YOURAPIKEY test https://twitter.com/marcelduran
const WebPageTest = require('webpagetest');
const wpt = new WebPageTest('www.webpagetest.org');
wpt.runTest('https://twitter.com/marcelduran', (err, data) => {
console.log(err || data);
});
marcelduran.com/webpagetest-api
$ webpagetest --help
The default WPT server can also be specified via environment variable WEBPAGETEST_SERVER
$ webpagetest locations
{
"response": {
"statusCode": 200, "statusText": "Ok",
"data": {
"location": [
...
{
"id": "SanJose_IE9",
"Label": "San Jose, CA USA (IE 9,Chrome,Firefox)",
"location": "SanJose_IE9",
"Browser": "IE 9",
"PendingTests": {
"p1": 0, "p2": 0, "p3": 0, "p4": 0, "p5": 2, "p6": 2, "p7": 0,
"p8": 0, "p9": 0, "Total": 7, "HighPriority": 2, "LowPriority": 4,
"Testing": 1, "Idle": 0
}
},
...
]
}
}
}
$ webpagetest test https://twitter.com/marcelduran --key 1F2A3K4E5 --location SanJose_IE9
{
"statusCode": 200,
"statusText": "Ok",
"data": {
"testId": "121025_PT_N8K",
"ownerKey": "868cb2813a0f376a977dd1a24ab041b4f12361b3",
"jsonUrl": "https://www.webpagetest.org/results.php?test=121025_PT_N8K&f=json",
"xmlUrl": "https://www.webpagetest.org/xmlResult.php?test=121025_PT_N8K",
"userUrl": "https://www.webpagetest.org/results.php?test=121025_PT_N8K",
"summaryCSV": "https://www.webpagetest.org/csv.php?test=121025_PT_N8K",
"detailCSV": "https://www.webpagetest.org/csv.php?test=121025_PT_N8K&requests=1"
}
}
$ webpagetest status 121025_PT_N8K
{
"statusCode": 101,
"statusText": "Test Pending",
"data": {
"statusCode": 101,
"statusText": "Test Pending",
"testId": "121025_PT_N8K",
"runs": 1,
"fvonly": 0,
"location": "SanJose_IE9"
}
}
$ webpagetest results 121025_PT_N8K
{
"response": {
"statusCode": 200, "statusText": "Ok",
"data": {
"testId": "121025_PT_N8K",
"summary": "https://www.webpagetest.org/result/121025_PT_N8K/",
"testUrl": "https://twitter.com/marcelduran",
"location": "SanJose_IE9",
"connectivity": "DSL",
"bwDown": 1500, "bwUp": 384, "latency": 50, "plr": 0,
"completed": "Thu, 25 Oct 2012 23:42:11 +0000",
"runs": 1, "successfulFVRuns": 1,
"average": {
"firstView": {
"loadTime": 3942, "TTFB": 1518,
"bytesIn": 963405, "bytesInDoc": 431612,
"requests": 32, "requestsDoc": 19,
"render": 2509, "fullyLoaded": 7765,
"docTime": 3942, "domTime": 0,
"titleTime": 1641, "avgRun": 1
}
},
...
}
}
}
$ webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri
{
"type": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgA...RK5CYII="
}
$ webpagetest test https://twitter.com/marcelduran --poll 5 --timeout 60
$ webpagetest test https://twitter.com/marcelduran --wait 8000
{
"response": {
"statusCode": 200, "statusText": "Ok",
"data": {
"testId": "121025_PT_N8K",
"testUrl": "https://twitter.com/marcelduran",
...
"median": {
"firstView": {
"loadTime": 3942, "TTFB": 1518,
"render": 2509, "fullyLoaded": 7765,
...
}
},
...
}
}
}
* hostname and port are optional, defaults to <system hostname>:<8000> ** localhost and port must be reacheable from WebPageTest server
Methods and options (including the one letter shorthands) are the same when using as a Node module, however a more verbose version of both commands (methods) and options (parameters) are available and encouraged to use for code clarity.
getTestStatus(id, options, callback)getTestResults(id, options, callback)getLocations(options, callback)getTesters(options, callback)runTest(url_or_script, options, callback)restartTest(id, options, callback)cancelTest(id, options, callback)getHARData(id, options, callback)getPageSpeedData(id, options, callback)getUtilizationData(id, options, callback)getRequestData(id, options, callback)getTimelineData(id, options, callback)getNetLogData(id, options, callback)getChromeTraceData(id, options, callback)getConsoleLogData(id, options, callback)getTestInfo(id, options, callback)getHistory(days, options, callback)getGoogleCsiData(id, options, callback)getResponseBody(id, options, callback)getWaterfallImage(id, options, callback)getScreenshotImage(id, options, callback)createVideo(tests, options, callback)getEmbedVideoPlayer(id, options, callback)listen(port, options, callback)scriptToString(script)(error, data) _optional=> _[
{command1: 'value1'},
{command2: 123},
{command3: ['value1', 'value2', ... , 'valueN']},
...
'commandN'}
]
getWaterfallImage and getScreenshotImage callback function has a third parameter info which is an object with {type: 'image/jpeg or png', encoding: 'utf8 or binary'}scriptToString script array values 1-N are optional. e.g:const script = wpt.scriptToString([
{logData: 0},
{navigate: 'http://foo.com/login'},
{logData: 1},
{setValue: ['name=username', 'johndoe']},
{setValue: ['name=password', '12345']},
{submitForm: 'action=http://foo.com/main'},
'waitForComplete'
]);
wpt.runTest(script, (err, data) => {
console.log(err || data);
});
options parameter)true, method does not make an actual request to the API Server but rather returns an object with url which contains the actual URL to make the GET request to WebPageTest API ServerrunTest method only)runTest, restartTest and cancelTest methods)getTestStatus getResults getLocations getTesters and runTest methoContent type
Image
Digest
Size
26.3 MB
Last updated
almost 8 years ago
docker pull hidgweb/docker-webpagetest-api