Skip to content

Commit

Permalink
feat(shaka-lab-node): Add support for Chromecast redirect mode (#52)
Browse files Browse the repository at this point in the history
Chromecast WebDriver Server v2 adds support for a redirect mode, where
it does not rely on an iframe. This has many advantages for Shaka Player
testing.

This adds support for this mode in shaka-lab-node, and enables it by
default in the Shaka lab.

To accomplish this for Chromecast, we add general support for optional
parameters with default values in the node template.
  • Loading branch information
joeyparrish authored May 19, 2024
1 parent 9da6f53 commit 62e75fa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion shaka-lab-node/node-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ xboxone:
Here, the template has parameters `hostname`, `username`, `password`, and
`msbuild`. The `?` in `?msbuild` indicates that it is an optional parameter.
The property definitions passed to Selenium then reference those as variables,
such as `$hostname`, `$username`, etc.
such as `$hostname`, `$username`, etc. An optional parameter can also have a
default value. For example, to have an optional parameter named `redirect`
that defaults to `true`, you would specify `?redirect=true`.


## Built-in Variables
Expand Down
3 changes: 3 additions & 0 deletions shaka-lab-node/node-templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ chromecast:
- version
- ?receiver-app-id # optional
- ?idle-timeout-seconds # optional
- ?connection-timeout-seconds # optional
- ?redirect=true # optional, default true
defs:
genericwebdriver.browser.name: chromecast
genericwebdriver.backend.exe: node_modules/.bin/chromecast-webdriver-server$cmd
genericwebdriver.backend.params.hostname: $hostname
genericwebdriver.backend.params.receiver-app-id: $receiver-app-id
genericwebdriver.backend.params.idle-timeout-seconds: $idle-timeout-seconds
genericwebdriver.backend.params.connection-timeout-seconds: $connection-timeout-seconds
genericwebdriver.backend.params.redirect: $redirect
capabilities:
browserName: chromecast
version: $version
Expand Down
2 changes: 1 addition & 1 deletion shaka-lab-node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"dependencies": {
"chromecast-webdriver-server": "^1",
"chromecast-webdriver-server": "^2",
"chromeos-webdriver-server": "^1",
"generic-webdriver-server": "^1",
"js-yaml": "^4",
Expand Down
26 changes: 22 additions & 4 deletions shaka-lab-node/start-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,32 @@ function requiredParam(nodeConfig, templateName, paramName) {
return nodeConfig.params[paramName];
}

/**
* @param {string} paramSpec
* @return {[string, string]}
*/
function parseOptionalParamSpec(paramSpec) {
// remove leading '?', split by optional '='
const paramSpecParts = paramSpec.substr(1).split('=');

const paramName = paramSpecParts.shift();
const defaultValue = paramSpecParts.length ? paramSpecParts.join('=') : '';
return [paramName, defaultValue];
}

/**
* Access an optional param from a node config, or return a blank default.
*
* @param {Object} nodeConfig
* @param {string} paramName
* @param {string} defaultValue
* @return {string}
*/
function optionalParam(nodeConfig, paramName) {
function optionalParam(nodeConfig, paramName, defaultValue) {
if (nodeConfig.params && paramName in nodeConfig.params) {
return nodeConfig.params[paramName];
}
return '';
return defaultValue;
}

/**
Expand Down Expand Up @@ -218,8 +232,11 @@ function main() {
const optional = paramName.startsWith('?');

if (optional) {
paramName = paramName.substr(1); // remove leading '?'
params[paramName] = optionalParam(nodeConfig, paramName);
let defaultValue;
[paramName, defaultValue] = parseOptionalParamSpec(paramName);

params[paramName] = optionalParam(
nodeConfig, paramName, defaultValue);
} else {
params[paramName] = requiredParam(
nodeConfig, templateName, paramName);
Expand Down Expand Up @@ -298,6 +315,7 @@ function main() {
for (const args of nodeCommands) {
const command = args.shift();

console.log('Spawning child process:', args);
const child = child_process.spawn(command, args, spawnOptions);

child.once('error', (event) => {
Expand Down

0 comments on commit 62e75fa

Please sign in to comment.