Run accessibility checks using the CLI
Use the Accessibility DevTools Command Line Interface (CLI) to automate accessibility checks in your development workflow.
The Accessibility DevTools CLI enables you to scan your codebase for accessibility issues directly from the terminal. This is useful for integrating accessibility testing into CI/CD pipelines or running checks locally without a UI.
With the CLI, you can scan multiple files or entire directories at once, and add accessibility as a quality check to your Git commits or CI/CD builds. This helps you catch issues early and maintain accessibility standards throughout your development workflow.
Install the CLI
Navigate to your project’s root directory and install the CLI using the following command:
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=macos&os_arch=arm64" | bsdtar -xvf- -O > browserstack-cli && chmod 0775 browserstack-cli
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=macos&os_arch=x64" | bsdtar -xvf- -O > browserstack-cli && chmod 0775 browserstack-cli
Navigate to your project’s root directory and install the CLI using the following command:
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=linux&os_arch=arm64" | tar -xz -O > browserstack-cli && chmod +x browserstack-cli
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=linux&os_arch=x64" | tar -xz -O > browserstack-cli && chmod +x browserstack-cli
curl -L "http://api.browserstack.com/sdk/v1/download_cli?os=alpine&os_arch=arm64" | tar -xz -O > browserstack-cli && chmod +x browserstack-cli
Navigate to your project’s root directory and install the CLI using the following command:
Invoke-WebRequest -Uri "http://api.browserstack.com/sdk/v1/download_cli?os=windows&os_arch=x64" -OutFile browserstack_cli.zip
Expand-Archive -Path browserstack_cli.zip -DestinationPath . -Force
Rename-Item -Path "binary-win-x64.exe" -NewName "browserstack-cli.exe"
Remove-Item browserstack_cli.zip # Cleanup
Authenticate with your BrowserStack account
- Log in to your BrowserStack account or sign up if you don’t have an account.
-
Obtain your Username and Access Key from the Account & Profile section section on the dashboard.
- Set the following environment variables using the Username and Access Key you obtained in step 2. This allows the CLI to authenticate with your BrowserStack account:
BROWSERSTACK_USERNAMEBROWSERSTACK_ACCESS_KEY
Add the export commands to the configuration file, depending on your shell:
-
Zsh: Add the following lines to your
~/.zshrcfile:export BROWSERSTACK_USERNAME="<your-username>" export BROWSERSTACK_ACCESS_KEY="<your-access-key>" -
Bash: Add the following lines to your
~/.bashrcor~/.bash_profilefile:export BROWSERSTACK_USERNAME="<your-username>" export BROWSERSTACK_ACCESS_KEY="<your-access-key>" -
Fish Shell: Add the following lines to your
~/.config/fish/config.fishfile:set -x BROWSERSTACK_USERNAME <your-username> set -x BROWSERSTACK_ACCESS_KEY <your-access-key>
After updating your configuration file, restart your terminal or run
sourceon the file to apply the changes.
Run accessibility checks
To scan your files or directories for accessibility issues, use the following command:
./browserstack-cli accessibility --include src/**.jsx
This command scans all .jsx files in the src directory and its subdirectories for accessibility issues.
CLI options
You can use the following options with the CLI:
| CLI command | Description |
|---|---|
--include or -i
|
Specify one or more glob patterns to include files to check. |
--exclude or -e
|
Specify one or more glob patterns to exclude files from checks. |
--browserstack-username or -u
|
Set your BrowserStack username. If you do not specify this option, the CLI uses the BROWSERSTACK_USERNAME environment variable. |
--browserstack-access-key or -k
|
Set your BrowserStack access key. If you do not specify this option, the CLI uses the BROWSERSTACK_ACCESS_KEY environment variable. |
--non-strict or -n
|
Run accessibility checks in non-strict mode. |
--help |
Display help and usage information. |
Exit codes
The CLI returns the following exit codes:
| Exit Code | Meaning |
|---|---|
| 0 | No accessibility issues. |
| 1 | Open accessibility issues. |
| 2 | BrowserStack connection issues. |
Sample pre-commit hook to run accessibility checks
You can use the following script to run accessibility checks automatically before each commit. Add this script to your repository’s .git/hooks/pre-commit file:
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!