Skip to content

Commit 0d4681e

Browse files
authored
Merge pull request #148 from abdulsuhail/issue-147-fix
added getTestBalance function
2 parents f40dfa2 + 7153f37 commit 0d4681e

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ $ webpagetest --help
5656
* **locations** _[options]_: list locations and the number of pending tests
5757
* **testers** _[options]_: list testers status and details
5858
* **test** _[options] \<url_or_script\>_: run test, _\<url_or_script\>_ can also be a path to a script file
59+
* **testBalance** _[options]_: get remaining tests for the account
5960
* **restart** _\<id\>_: restart test
6061
* **cancel** _\<id\>_: cancel running/pending test
6162
* **har** _\<id\>_: get the HTTP Archive (HAR) from test
@@ -159,7 +160,7 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
159160
* **--timeout** _\<seconds\>_: timeout for polling and waiting results [no timeout]
160161
* **--lighthouse**: perform lighthouse test (Chrome only, Linux agent only)
161162

162-
#### API Key (works for **test**, **restart**,**locations** and **cancel** commands)
163+
#### API Key (works for **test**, **restart**,**locations**, **testBalance** and **cancel** commands)
163164
* **-k, --key** _\<api_key\>_:API key (if assigned). Contact the WebPageTest server administrator for a key if required or request an API key for limited testing at [webpagetest.org/getkey.php](https://www.webpagetest.org/getkey.php)
164165

165166
#### Request (works for **status**, **results**, **locations**, **testers** and **test** commands)
@@ -351,6 +352,18 @@ $ webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri
351352
}
352353
```
353354

355+
#### 7. Get remaining tests count for the account
356+
```bash
357+
$ webpagetest testBalance --key 1F2A3K4E5
358+
```
359+
```javascript
360+
{
361+
"data": {
362+
"remaining": 1175
363+
}
364+
}
365+
```
366+
354367
#### Run test on https://docs.webpagetest.org/api/integrations/ and poll results every 5 seconds timing out in 60 seconds
355368
```bash
356369
$ webpagetest test https://docs.webpagetest.org/api/integrations/ --poll 5 --timeout 60
@@ -390,6 +403,7 @@ Methods and options (including the one letter shorthands) are the same when usin
390403
* `getTestResults(id, options, callback)`
391404
* `getLocations(options, callback)`
392405
* `getTesters(options, callback)`
406+
* `getTestBalance(options, callback)`
393407
* `runTest(url_or_script, options, callback)`
394408
* `restartTest(id, options, callback)`
395409
* `cancelTest(id, options, callback)`

lib/mapping.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@ var commands = {
782782
options: [options.request,options.apikey],
783783
info: 'list locations and the number of pending tests'
784784
},
785+
'testBalance': {
786+
name: 'getTestBalance',
787+
options: [options.apikey],
788+
info: 'get remaining tests for the account'
789+
},
785790
'testers': {
786791
name: 'getTesters',
787792
options: [options.request],

lib/webpagetest.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var paths = {
2424
testResults: 'jsonResult.php',
2525
locations: 'getLocations.php',
2626
testers: 'getTesters.php',
27+
testBalance: 'testBalance.php',
2728
test: 'runtest.php',
2829
gzip: 'getgzip.php',
2930
har: 'export.php',
@@ -315,6 +316,17 @@ function getTesters(options, callback) {
315316
return api.call(this, paths.testers, callback, query, options);
316317
}
317318

319+
function getTestBalance(options, callback) {
320+
callback = callback || options;
321+
options = options === callback ? undefined : options;
322+
323+
var query = helper.setQuery(mapping.commands.testBalance, options);
324+
if (!query.k && this.config.key) {
325+
query.k = this.config.key;
326+
}
327+
return api.call(this, paths.testBalance, callback, query, options);
328+
}
329+
318330
function runTest(what, options, callback) {
319331
var query = {};
320332

@@ -778,6 +790,7 @@ WebPageTest.prototype = {
778790
restartTest: restartTest,
779791
cancelTest: cancelTest,
780792
getPageSpeedData: getPageSpeedData,
793+
getTestBalance : getTestBalance,
781794
getHARData: getHARData,
782795
getUtilizationData: getUtilizationData,
783796
getRequestData: getRequestData,

test/command-line-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ describe('WebPageTest Command Line', function() {
327327
'', 'status', 'results', 'locations', 'testers', 'test', 'restart', 'cancel', 'har',
328328
'pagespeed', 'utilization', 'request', 'timeline', 'netlog', 'chrometrace',
329329
'console', 'testinfo', 'history', 'googlecsi', 'response', 'waterfall',
330-
'screenshot', 'video', 'player', 'listen', 'batch'
330+
'screenshot', 'video', 'player', 'listen', 'batch','testBalance'
331331
].forEach(function eachCmd(command) {
332332
it('gets a ' + command + ' help input and returns the help text', function(done) {
333333
exec(mock(command + ' --help'), function(err, data) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Usage: webpagetest testBalance [options]
2+
3+
get remaining tests for the account
4+
5+
Options:
6+
-k, --key <api_key> API key (if assigned). Contact the
7+
WebPageTest server administrator for a
8+
key if required
9+
-h, --help display help for command

test/fixtures/command-line/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Commands:
1414
results [options] <id> get test results
1515
locations [options] list locations and the number of pending
1616
tests
17+
testBalance [options] get remaining tests for the account
1718
testers [options] list testers status and details
1819
test [options] <url_or_script> run test
1920
restart [options] <id> restart test

0 commit comments

Comments
 (0)