Integrate Nightwatch test suite with App Accessibility testing
Learn how to add accessibility checks to your existing functional tests and generate comprehensive reports of accessibility issues.
BrowserStack supports out of the box integration with Nightwatch. You can integrate your existing functional test suites with App Accessibility testing to run accessibility checks on your mobile apps. You can access the generated accessibility violation reports on the App Accessibility dashboard.
Prerequisites
- Ensure you have a BrowserStack Username and Access Key. You can obtain your
userNameandaccessKeyfrom the Account & Profile section on the dashboard.
If you have not yet created an account, sign up for a free trial. - Ensure you have a functional Nightwatch test suite. To set one up, see Run accessibility checks on a sample repo.
- Node.js 14+ installed on your system. You can download the updated Node version from nodejs.org.
Integrate App Accessibility Automate to run accessibility checks
Set your BrowserStack credentials
Save your BrowserStack credentials as environment variables to make it easier to run your test suite from your local or CI environment.
# Set these values in your ~/.zprofile (zsh) or ~/.profile (bash)
export BROWSERSTACK_USERNAME=YOUR_USERNAME
export BROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY
setx BROWSERSTACK_USERNAME "YOUR_USERNAME"
setx BROWSERSTACK_ACCESS_KEY "YOUR_ACCESS_KEY"
set BROWSERSTACK_USERNAME=YOUR_USERNAME
set BROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY
Update and install dependencies
- Update package versions in the
package.jsonfile. For App Accessibility testing, the minimum supported Nightwatch plugin version is3.8.0and the Nightwatch core version is3.13.0.... "dependencies": { "browserstack-local": "^1.4.8", "nightwatch": "3.13.0" }, "license": "MIT", "devDependencies": { "@nightwatch/browserstack": "3.8.0" } ... - Install the packages:
npm install
Navigate to the configuration folder
Navigate to the configuration folder of your Nightwatch test suite.
cd resources/config
Modify the configuration file
The nightwatch.conf.js file contains the necessary capabilities to run your tests on BrowserStack. Modify the file to include the App Accessibility testing options:
- Open the
nightwatch.conf.jsfile in an editor. - Add the
projectNameandbuildName. - Add an
accessibilityflag underbstack:optionsand set it totrue. - Configure the
accessibilityOptionsproperty to set various accessibility testing options. For details, see Configuration options. - Specify all the device, OS, and OS version combinations that you want to test in the
test_settingssection. - Save the file.
The projectName and buildName config must be static and not change across different runs of the same build. This is a deviation in approach as specified by BrowserStack App Automate since Automated tests will automatically identify different build runs.
const additonalEnvironments = require("./environments");
if(!additonalEnvironments.test_settings)
additonalEnvironments.test_settings = {};
const browserStack = {
webdriver: {
start_process: false
},
selenium: {
host: 'hub.browserstack.com',
port: 443
},
desiredCapabilities: {
'bstack:options': {
userName: process.env.BROWSERSTACK_USERNAME,
accessKey: process.env.BROWSERSTACK_ACCESS_KEY,
appiumVersion: '1.22.0',
accessibility: true,
}
},
}
const nightwatchConfigs = {
src_folders: [],
live_output: true,
plugins: ['@nightwatch/browserstack'],
// browserstack plugin settings...
'@nightwatch/browserstack': {
browserstackLocal: false, // set true to manage browserstack local tunnel. Defaults to false.
test_observability: {
enabled: true,
user: process.env.BROWSERSTACK_USERNAME,
key: process.env.BROWSERSTACK_ACCESS_KEY,
projectName: "browserstack-appium-nightwatch-example-project2",
buildName: "browserstack-appium-nightwatch-example-build",
}
},
test_settings: {
default: {
launch_url: 'https://nightwatchjs.org'
},
browserstack: {
...browserStack
},
"browserstack.android_01": {
extends: 'browserstack',
'desiredCapabilities': {
browserName: null,
'appium:options': {
automationName: 'UiAutomator2',
// custom id for the uploaded app: https://www.browserstack.com/docs/app-automate/appium/upload-app-define-custom-id
app: 'bs_sample_android_app',
platformVersion: '11.0',
deviceName: 'Google Pixel 5'
},
appUploadPath: 'apps/android_app.apk'
}
},
"browserstack.ios_01": {
extends: 'browserstack',
'desiredCapabilities': {
browserName: null,
'appium:options': {
automationName: 'XCUITest',
// custom id for the uploaded app: https://www.browserstack.com/docs/app-automate/appium/upload-app-define-custom-id
app: 'bs_sample_ios_app',
platformVersion: '16',
deviceName: 'iPhone 14'
},
appUploadPath: 'apps/ios_app.ipa'
}
},
}
}
for(let key in additonalEnvironments.test_settings) {
nightwatchConfigs.test_settings[key] = {
...browserStack,
...additonalEnvironments.test_settings[key]
};
}
module.exports = nightwatchConfigs;
Run the automated test
Run the test using one of the following commands based on your testing platform:
npm run single-android
npm run single-ios
View the Accessibility test report
After the test completes, access the report in your project folder on the App Accessibility dashboard.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!