This guide aims to share how TestCafe is being used in Plio for performing End-to-End (E2E) and integration tests.
End-to-End testing sits on top of integration testing. While integration testing is limited to check integration between two functional components, end-to-end testing is more focused on the whole application and integration of several components together in an end-to-end workflow. End-to-End testing generally mimics the user behavior on an actual browser and the actions they may take while using the application.
Plio uses BrowserStack to enable automated End-to-End cross-browser and cross-OS testing. BrowserStack is a cloud-based service that provides a virtual browser for testing web application. It is a free service that allows you to test your web application on a variety of devices and browsers. Plio's Continuous Integration workflow runs the E2E tests on the following operating systems and browsers using BrowserStack:
- Chrome v96 (Windows 10, OSX Big Sur, OSX Catalina)
- Firefox v95 (Windows 10, OSX Big Sur, OSX Catalina)
- Edge v96 (Windows 10)
- Safari v14.1 (OSX Big Sur)
- Safari v13.1 (OSX Catalina)
For login, Plio uses Google OAuth Playground Authentication to mimic the exact user behavior on Google Login functionality. Google OAuth credentials will be required to run the test cases that require login.
Follow the links below one-by-one to retrieve required information from Google:
- Google Project and Application Setup
- Using the Google OAuth 2.0 Playground to Create Testing Credentials
-
Install TestCafe for BrowserStack globally:
npm i -g testcafe testcafe-browser-provider-browserstack
-
Add the following env variables to your
~/.bash_profile
or~/.zshrc
file:export BROWSERSTACK_BASE_URL="http://localhost:8080" export BROWSERSTACK_USERNAME="" # Your BrowserStack username export BROWSERSTACK_ACCESS_KEY="" # Your BrowserStack access key export BROWSERSTACK_PROJECT_NAME="plio"
-
Once the env variables are added, restart your terminal or run one of the following command:
source ~/.bash_profile # or source ~/.zshrc
- To run a test case locally, execute the following command from the project root folder:
# syntax testcafe browser ./path/to/test.spec.js # example - run tests on a specific browser testcafe chrome ./tests/integration/pages/login.spec.js # example - run tests on multiple browsers testcafe 'browserstack:[email protected]:OS X Big Sur','browserstack:[email protected]:OS X Big Sur','browserstack:[email protected]:OS X Big Sur' ./tests/integration --skip-js-errors
- To list all the browsers available, run the following command:
# command to see local browsers testcafe --list-browsers # command to see BrowserStack browsers testcafe -b browserstack
Setup the following environment variables in your ~/.bash_profile
or ~/.zshrc
file if you're trying to run testcafe locally with BrowserStack. Also, set them up on the Continuous Integration environment using GitHub secrets.
The base url of the application registered with BrowserStack. Should be the frontend application URL.
Required to connect to your BrowserStack account. Get this information from your BrowserStack account settings.
Required to connect to your BrowserStack account. Get this information from your BrowserStack account settings.
Name of the BrowserStack project. Set to plio
. It allows to name the build, which is useful for keeping track of test runs on the BrowserStack dashboard.
Google refresh token retrieved in the pre-requisites.
Google client ID retrieved in the pre-requisites.
Google client secret retrieved in the pre-requisites.
The convert token URL in the Plio backend repo that converts the Social Auth Token and returns a valid Auth Token. By default, the value is http://0.0.0.0:8001/auth/convert-token.
The client id for Plio backend application. More details in Plio Backend ENV.md.
The client secret for Plio backend application. More details in Plio Backend ENV.md.
The secret key for the backend application. More details in Plio Backend ENV.md.