Add webpagetest.file to replace direct input via .script (#1445)
This commit is contained in:
parent
a063a46449
commit
d60b6682a9
|
|
@ -85,7 +85,8 @@ WebPageTest
|
|||
--webpagetest.connectivity The connectivity for the test. [default: "Cable"]
|
||||
--webpagetest.runs The number of runs per URL. [default: 3]
|
||||
--webpagetest.custom Execute arbitrary Javascript at the end of a test to collect custom metrics.
|
||||
--webpagetest.script Path to a script file
|
||||
--webpagetest.script Direct WebPageTest script as a string [String]
|
||||
--webpagetest.file Path to a WebPageTest script file
|
||||
|
||||
gpsi
|
||||
--gpsi.key The key to use Google Page Speed Insight
|
||||
|
|
|
|||
|
|
@ -26,13 +26,14 @@ Internally sitespeed.io uses the [WebPageTest API](https://github.com/marceldura
|
|||
By default we have the following configuration options:
|
||||
|
||||
~~~ bash
|
||||
--webpagetest.host The domain of your WebPageTest instance.
|
||||
--webpagetest.host The domain of your WebPageTest instance.
|
||||
--webpagetest.key The API key for you WebPageTest instance.
|
||||
--webpagetest.location The location for the test
|
||||
--webpagetest.connectivity The connectivity for the test.
|
||||
--webpagetest.runs The number of runs per URL.
|
||||
--webpagetest.location The location for the test
|
||||
--webpagetest.connectivity The connectivity for the test.
|
||||
--webpagetest.runs The number of runs per URL.
|
||||
--webpagetest.custom Execute arbitrary Javascript at the end of a test to collect custom metrics.
|
||||
--webpagetest.script Path to a script file
|
||||
--webpagetest.script Direct WebPageTest script as a string
|
||||
--webpagetest.file Path to a script file
|
||||
~~~
|
||||
|
||||
If you need anything else adding your own CLI parameter will propagate to the WebPageTest API. Checkout the different [options](https://github.com/marcelduran/webpagetest-api#test-works-for-test-command-only) for the API.
|
||||
|
|
@ -66,7 +67,7 @@ You can override these with parameters. If you want to change the location, just
|
|||
|
||||
WebPageTest has scripting capability where you can automate a multi-step test (login as a user and do some interaction). That is supported by sitespeed.io by supplying the script. You can do so like this:
|
||||
|
||||
Create your script file (checkout [WebPageTest documentation](https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting) for what you can do). It can look something like this (wptScript.txt):
|
||||
You can create your script file (checkout [WebPageTest documentation](https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/scripting) for what you can do). It can look something like this (wptScript.txt):
|
||||
|
||||
~~~ bash
|
||||
logData 0
|
||||
|
|
@ -84,7 +85,13 @@ navigate news.aol.com/world
|
|||
Then change your URL you want test (probably the last one) to \{\{\{URL\}\}\} and then all occurrences of \{\{\{URL\}\}\} will then be replaced with the current URL that should be tested. Then run sitespeed.io (and add the parameters as you usually do):
|
||||
|
||||
~~~ bash
|
||||
sitespeed.io --webpagetest.script wptScript.txt --webpagetest.host my.wpt.host.com http://example.org
|
||||
sitespeed.io --webpagetest.file wptScript.txt --webpagetest.host my.wpt.host.com http://example.org
|
||||
~~~
|
||||
|
||||
It is also possible to pass the WebPageTest script as a string into the `--webpagetest.script` flag. You can use the `scriptToString()` method provided in [webpagetest-api](https://github.com/marcelduran/webpagetest-api/#module-1) to create a string from a JSON object.
|
||||
|
||||
~~~ bash
|
||||
sitespeed.io --webpagetest.script "navigate \t www.aol.com \n navigate \t {{{url}}}" --webpagetest.host my.wpt.host.com http://example.org
|
||||
~~~
|
||||
|
||||
### Custom metrics
|
||||
|
|
|
|||
|
|
@ -286,10 +286,14 @@ module.exports.parseCommandLine = function parseCommandLine() {
|
|||
describe: 'Execute arbitrary Javascript at the end of a test to collect custom metrics.',
|
||||
group: 'WebPageTest'
|
||||
})
|
||||
.option('webpagetest.script', {
|
||||
.option('webpagetest.file', {
|
||||
describe: 'Path to a script file',
|
||||
group: 'WebPageTest'
|
||||
})
|
||||
.option('webpagetest.script', {
|
||||
describe: 'The WebPageTest script as a string.',
|
||||
group: 'WebPageTest'
|
||||
})
|
||||
/** Google Page Speed Insights */
|
||||
.option('gpsi.key', {
|
||||
describe: 'The key to use Google Page Speed Insight',
|
||||
|
|
@ -407,9 +411,27 @@ module.exports.parseCommandLine = function parseCommandLine() {
|
|||
}
|
||||
return arg;
|
||||
} else {
|
||||
throw new Error('Something looks wrong with your budget configuration. Since sitespeed.io 4.4 you should pass the path to your budget file through the --budget.file flag instead of directly through the --budget flag.');
|
||||
throw new Error('[ERROR] Something looks wrong with your budget configuration. Since sitespeed.io 4.4 you should pass the path to your budget file through the --budget.file flag instead of directly through the --budget flag.');
|
||||
}
|
||||
})
|
||||
.coerce('webpagetest', function(arg) {
|
||||
// for backwards compatible reasons we check if the passed parameters is a path to a script, if so just us it (PR #1445)
|
||||
if (arg.script && fs.existsSync(arg.script)) {
|
||||
arg.script = fs.readFileSync(path.resolve(arg.script), 'utf8');
|
||||
/* eslint no-console: off */
|
||||
console.log('[WARNING] Since sitespeed.io 4.4 you should pass the path to the script file through the --webpagetest.file flag (https://github.com/sitespeedio/sitespeed.io/pull/1445).');
|
||||
return arg;
|
||||
}
|
||||
|
||||
if (arg.file) {
|
||||
arg.script = fs.readFileSync(path.resolve(arg.file), 'utf8');
|
||||
} else if (arg.script) {
|
||||
// because the escaped characters are passed re-escaped from the console
|
||||
arg.script = arg.script.split('\\t').join('\t');
|
||||
arg.script = arg.script.split('\\n').join('\n');
|
||||
}
|
||||
return arg;
|
||||
})
|
||||
// .describe('browser', 'Specify browser')
|
||||
.wrap(yargs.terminalWidth())
|
||||
// .check(validateInput)
|
||||
|
|
@ -445,11 +467,6 @@ module.exports.parseCommandLine = function parseCommandLine() {
|
|||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
if (argv.webpagetest.script) {
|
||||
argv.webpagetest.script = fs.readFileSync(path.resolve(argv.webpagetest.script), {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
|
||||
if (argv.summaryDetail) argv.summary = true;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue