Actions on Google Testing Library
This library allows developers to write automated testing for their actions in Node.js.
Examples can be found in the /examples
directory for two sample apps.
The Assistant SDK is used to give developers programmatic access to the Assistant and returns debug information about their actions that are in a test state.
Note: This library is currently in an alpha, experimental state. APIs may break between releases. Feedback and bugs can be provided by filing an issue in this repository.
How to get started
- Go to the Actions console
- Create a new project. This project can be independent of your other projects.
- You can use this project to test any of your actions that are in a test state
- For this new project, enable the Google Assistant API
- Go to the Device Registration section.
- Click REGISTER MODEL
- Fill out the product and manufacturer name
- Set the Device type to Light, although the choice does not matter
- Download the
credentials.json
file - Use this credentials file to generate test credentials:
node generate-credentials.js /path/to/credentials.json
- Copy and paste the URL and enter the authorization code. You will see a response similar to the following:
Saved user credentials in "test-credentials.json"
- Create a JavaScript file for your tests:
test.js
'use strict';const ActionsOnGoogleAva = ;const expect = ;// Library will try to obtain credentials from environment variables in case// credentials file is not specifiedconst action = ; // Start out with giving a name to this testaction;
- Run
yarn
- Update your
package.json
to add this test file to your test script.
"scripts": { "test": "./node_modules/.bin/ava -c 1 -s ./test.js"},
- Run
yarn test
. You should see your test be executed.
NOTE You can also alternatively set the following environment variables - ACTIONS_TESTING_CLIENT_ID
,ACTIONS_TESTING_CLIENT_SECRET
, ACTIONS_TESTING_REFRESH_TOKEN
- to authenticate your Actions project with the Assistant SDK.
Supported features
This library provides the following features to control your conversation:
action.start()
- Start your conversation with your action using "my test app".action.startWith()
- Start your conversation with your action using the specified action name.action.send()
- Send some phrase to your action.action.cancel()
- End your conversation. This library says "cancel".action.locale
- Set a locale for your conversation.action.location
- Set an array of a latitude and a longitude.
Possible responses
These responses will come from your fulfillment, and will consist of whatever objects that you return.
res
.micOpen - Boolean
.textToSpeech - String[]
.displayText - String[]
.ssml - String[]
.cards - Card[]
.title - String
.subtitle - String
.text - String
.imageUrl - String
.imageAltText - String
.buttons - Button[]
.title - String
.url - String
.carousel - Array for Browse Carousel or Selection Carousel
.title - String
.description - String,
.imageUrl - String,
.imageAltText - String,
.url - String
.list
.title - String
.items - Item[]
.title - String
.description - String
.imageUrl - String
.imageAltText - String
.mediaResponse
.type - String
.name - String
.description - String
.sourceUrl - String
.icon - String
.suggestions - String[]
.linkOutSuggestion
.url - String
.name - String
.table
.headers - String[]
.rows - Row[]
.cells - String[]
.divider - Boolean
Known Issues
- Testing transactions does not work
- Testing smart home fulfillment does not work
- Unable to set surface capabilities
- Selecting an item for a ListSelect and CarouselSelect do not work
License
See LICENSE