Automation tests for the PayPal JS SDK
This library uses WebDriver.io and BrowserStack to run end-to-end tests against websites using the JS SDK.
npm install
npm test
There are two different ways to run the test suite:
npm test
- local runner that uses Chromenpm run test-browserstack
- uses BrowserStack and requires a username and access key
BrowserStack requires a username and access key to run tests. Find your credentials using BrowserStack.com.
In addition to BrowserStack credentials, you will need PayPal login credentials for the buttons tests to work in your script environment. For example, you will need BUYER_EMAIL=<stage email>
and BUYER_PASSWORD=<stage password>
for use with a stage script.
When you have your credentials ready, run the following command:
npm run save-credentials
This will save your credentials to a local .env file, which is ignored by git. This .env file gets loaded by the app and will use the credentials in it to connect to BrowserStack. This is designed for local development. CI tools like GitHub Actions should directly set the BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY, BUYER_EMAIL, and BUYER_PASSWORD environment variables.
By default, these commands run all the tests in the test suite. To run a single test, pass the test name as an argument like so:
npm test -- --spec paylater-button-click.test.ts
The tests run against the following default urls:
- buttons: https://paypal.github.io/paypal-sdk-e2e-tests/components/buttons/buttons.html
- messages: https://paypal.github.io/paypal-sdk-e2e-tests/components/messages/messages.html
These urls can be overriden using the BUTTONS_URL
and MESSAGES_URL
environment variables to test the JS SDK on different websites. For example, the button tests can be run against the react-paypal-js storybook demo:
BUTTONS_URL="https://paypal.github.io/react-paypal-js/iframe.html?id=example-paypalbuttons--default&args=&viewMode=story" npm test -- --spec button
BrowserStack local testing can be enabled from the command line by adding LOCAL_TESTING=true
to npm run test-browserstack
or npm run test-browserstack-german
:
LOCAL_TESTING=true npm run test-browserstack
This is useful for running tests using localhost
and/or a test page that uses a custom JS SDK test environment:
BUTTONS_URL="https://paypal.github.io/paypal-sdk-e2e-tests/components/buttons/buttons.html?client-id=<client-id>&sdkBaseURL=<js-sdk-test-env-url>" LOCAL_TESTING=true npm run test-browserstack