Roku JavaScript Library
Keyword-driven testing library for automating app test cases on Roku devices
Roku's JavaScript Library enables keyword-driven testing of apps. The library resides in a JavaScript class that has methods that map directly to keyword names. The keywords take the same arguments as the methods implementing them. The keywords report failures with exceptions, create logs by writing to standard output, and return values using the return statement.
Instantiating the library
To create an instance of the Roku JavaScript Library, provide the following three arguments:
| Argument | Description |
|---|---|
| ip | The IP address of the device to be used for testing. |
| timeout | The amount of time (in milliseconds) that commands are allowed to run. |
| pressDelay | The amount of time (in milliseconds) between keypress commands. This argument works with the sendKeys command. |
The following example demonstrates how to instantiate the Roku JavaScript Library:
library = new rokuLibrary.Library("192.168.2.121", 20000, 2000);
The following example demonstrates how to instantiate the Roku JavaScript Library and runs test case with Mocha and Chai:
//import library
const rokuLibrary = require("../library/rokuLibrary");
const expect = require("chai").expect;
const {
spawn
} = require('child_process');
//start instance of webDriver
const childProcess = spawn('D:/projects/go/webDriver/src/main.exe');
let library;
//test suite
describe('test_3-Grid', () => {
//this method is executed before all test cases
before(() => {
//create instance of jsLibrary
library = new rokuLibrary.Library("192.168.2.121", 20000, 2000);
});
//test case
it('should launch the app', async function() {
this.timeout(25000);
await library.sideLoad("../channels/3_Grid.zip", "rokudev", "your_channel_password");
await library.verifyIsChannelLoaded('dev');
});
//this method executed after all tests
after(async () => {
//close session
await library.close();
//exit webDriver
childProcess.kill();
});
});
Keywords
The Roku's JavaScript Library includes the following keywords:
- Sideload (available since release 2.0)
- Launch the app
- Input deep linking data (available since release 2.0)
- Get apps
- Send key
- Send keys
- Send word
- Mark timer (available since release 2.0)
- Get timer (available since release 2.0)
- Verify is playback started
- Verify is screen loaded
- Get child nodes (available since release 2.1)
- Get element
- Get elements
- Get focused element
- Verify is app loaded
- Get current app info
- Get device info
- Get player info
- Verify is channel exist
- Set timeout
- Set press delay
- Get attribute
A keyword will fail if its respective WebDriver endpoint returns a 4xx or 500 error.
sideLoad
(available since release 2.0)
| Keyword | Argument | Description | Example |
|---|---|---|---|
| sideLoad |
|
Sideloads an app that has been packaged into a zip file. If the sideLoad command fails, [sideload](doc:developer-setup#sideloading-channels) the app to be tested and use the launchTheChannel command. |
await library.sideLoad("channel.zip", "rokudev", "your_device_password") |
launchTheChannel
| Keyword | Argument | Description | Example |
|---|---|---|---|
| launchTheChannel |
|
Launches the app corresponding to the specified app ID. | await library.launchTheChannel("dev", "myMovie123", "movie") |
inputDeepLinkingData
(available since release 2.0)
| Keyword | Argument | Description | Example |
|---|---|---|---|
| inputDeepLinkingData |
|
Launches the app corresponding to the specified app ID. | await library.inputDeepLinkingData("dev", "myMovie123", "movie") |
getApps
| Keyword | Description | Example |
|---|---|---|
| getApps | Returns a list of installed apps as an array of objects. Each app object contains the following fields:
|
|
sendKey
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| sendKey |
|
Simulates the press and release of the specified key. | await library.sendKey('select', 4) |
sendKeys
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| sendKeys |
|
Simulates the sequence of keypresses and releases. | await library.sendKeys(['down', 'down', 'down', 'down', 'select']) |
sendWord
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| sendWord |
|
Simulates the press and release of each letter in a word. | await library.sendWord('user') |
markTimer
(available since release 2.0)
| Keyword | Description | Example |
|---|---|---|
| markTimer | Starts the timer. | library.markTimer(); |
getTimer
(available since release 2.0)
| Keyword | Description | Example |
|---|---|---|
| getTimer | Returns the number of milliseconds elapsed since the timer was last started. | |
verifyIsPlaybackStarted
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| verifyIsPlaybackStarted |
|
Verify playback has started on the Roku media player. This keyword fails if player state is not "play". |
verifyIsPlaybackStarted(25, 2) |
verifyIsScreenLoaded
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| Verify is screen loaded |
|
Verify that the screen is loaded based on the provided element data. | verifyIsScreenLoaded({'{'}'elementData': [{'{'}'using': 'text', 'value': 'Barack Gates, Bill Obama'{'}'}]{'}'}) |
getChildNodes
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| getChildNodes |
|
Retrieves the child component of the specified node. | |
-
locator (optional): An array containing search criteria for the child nodes to be retrieved. The locator has the following syntax:
"using" ("attr", "tag", "text") : specify locator type "value": tag or attribute value "attribute"(only for "attr" type): specify attribute
getElement
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| Get element |
|
Searches for an element on the page based on the specified locator starting from the screen root. Returns information on the first matching element. | |
getElements
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| getElements |
|
Searches for elements on the page based on the specified locators starting from the screen root. Returns information on the matching elements. | |
getFocusedElement
| Keyword | Description | Example |
|---|---|---|
| getFocusedElement | Return the element on the screen that currently has focus. See the [WebDriver active element command](doc:web-driver#get-v1/session/:sessionId/element/active) for more information. | |
verifyIsChannelLoaded
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| verifyIsChannelLoaded |
|
Verify that the specified app has been launched. This keyword fails if the provided app ID does not match a valid app. |
await library.verifyIsChannelLoaded('dev') |
getCurrentChannelInfo
| Keyword | Description | Example | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getCurrentChannelInfo |
Returns an object containing information about the app currently loaded. This object has the following fields:
|
|
getDeviceInfo
| Keyword | Description | Example | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getDeviceInfo |
Returns an object containing the information about the device. This object has the following fields:
|
|
getPlayerInfo
| Keyword | Description | Example | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getPlayerInfo |
Returns an object containing information about the Roku media player. This object has the following fields:
|
|
verifyIsChannelExist
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| verifyIsChannelExist |
|
Verifies the specified app is installed on the device. This keyword fails if the apps array does not contain the app specified in the id argument. | |
setTimeout
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| setTimeout | timeout: The amount of time (in milliseconds) that Web driver client requests are allowed to run. |
Sets the timeout for Web driver client requests. | await library.setTimeout(10000) |
setDelay
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| setDelay | delay: The interval (in milliseconds) to be used between key presses. |
Sets the delay between key presses. This keyword works with the Send keys keyword. | await library.setDelay(1000) |
getAttribute
| Keyword | Arguments | Description | Example |
|---|---|---|---|
| getAttribute |
|
Get attribute value. This keyword fails if an element does not contain the specified attribute. | |
Sample test cases
The Roku automated app testing repository includes a set of sample JavaScript test cases that can be executed on their corresponding SceneGraph Developer Extensions (SGDEX) sample apps. For example, you can execute the SGDEX GridView test case (test_3_Grid.js), which will sideload the corresponding sample app (3_Grid) on your device, and then view the test output. You can reference these samples when developing test scripts for the automated testing of your development apps.
Before running a sample test case, you need to update the sideload command in the test case with the Roku device password.
The test_basic.js sample demonstrates how to create a simple test case that checks whether a user is authenticated before playing content using the Roku JavaScript Library:
const rokuLibrary = require("../library/rokuLibrary");
const expect = require("chai").expect;
const {
spawn
} = require('child_process');
const childProcess = spawn('D:/projects/go/webDriver/src/main.exe');
let library;
describe('App should be launched', () => {
before(() => {
library = newrokuLibrary.Library("192.168.1.64");
});
it('Check if app exists on the device', asyncfunction() {
this.timeout(5000);
const apps = await library.getApps();
const res = library.verifyIsChannelExist(apps, 'dev');
expect(res).equal(true);
});
it('should launch the app', asyncfunction() {
this.timeout(5000);
await library.launchTheChannel('dev');
await library.verifyIsChannelLoaded('dev');
});
after(async () => {
await library.close();
childProcess.kill();
});
});
Viewing the test case report and log
After you run a test case that uses the Roku JavaScript Library, you can view the generated report and log files in the specified output directory. The report summarizes the test case and provides statistics on the percentage of individual tests that passed/failed. The log details the success/failure of the individual keywords used in each test case.
Updated 5 days ago
