This page describes how to write and run End-to-End (E2E) testing for Mobile Apps for both iOS and Android. Mobile products use Detox, which is a “gray box end-to-end testing and automation library for mobile apps.” See its documentation to learn more.
The folder structure is as follows:
|-- detox
|-- e2e
|-- support
|-- test
|-- config.json
|-- environment.js
|-- init.js
|-- .babelrc
|-- .detoxrc.json
|-- package-lock.json
|-- package.json
/detox/e2e/support
is the support folder, which is a place to put reusable behavior such as Server API and UI commands, or global overrides that should be available to all test files./detox/e2e/test
: To start writing tests, create a new file (e.g. login.e2e.js
) in the /detox/e2e/test
folder.
/detox/e2e/test/messaging/
for “Messaging”)./detox/e2e/test/enterprise/
. This is to easily identify license requirements, both during local development and production testing for Enterprise features./detox/.detoxrc.json
: for Detox configuration./detox/package.json
: for all dependencies related to Detox end-to-end testing.This process has many similarities to writing an E2E test for the mattermost-webapp project. Before writing a script, ensure that it has a corresponding test case in Zephyr. All test cases may be found in this link. If test case is not available, feel free to prompt the QA team who will either search from an existing Zephyr entry or if it’s a new one, it will be created for you.
Create a test file based on the file structure aforementioned above.
Include Zephyr identification (ID) and title in the test description, following the format of it('[Zephyr_id] [title]')
or it('[Zephyr_id]_[step] [title]')
if the test case has multiple steps. For test case “MM-T109 RN apps: User can't send the same message repeatedly”, it should be:
describe('Messaging', () => {
it('MM-T109 User can\'t send the same message repeatedly', () => {
// Test steps and assertion here
}
}
Target an element using available matchers. For best results, it is recommended to match elements by unique identifiers using testID
. The identifier should follow the following format to avoid duplication, <location>.<modifier>.<element>.<identifier>
, where:
location
- can be a parent component, a main section, or a UI screen.modifier
- adds meaning to the element
.element
- common terms like button
, text_input
, image
, and the like.identifier
- could be unique ID of a post, channel, team or user, or a number to represent order.Prefix each comment line with appropriate indicator. Each line in a multi-line comment should be prefixed accordingly. Separate and group test step comments and assertion comments for better readability.
#
indicates a test step (e.g. // # Go to a screen
)*
indicates an assertion (e.g. // * Check the title
)Simulate user interaction using available actions, and verify user interface (UI) expectations using expect
. When using action
, match
, or another API specific to a particular platform, verify that the equivalent logic is applied so that the API does not impact other platforms. Always run tests in applicable platforms.
Install the latest Android SDK:
sdkmanager "system-images;android-30;google_apis;x86"
sdkmanager --licenses
Create the emulator using npm run e2e:android-create-emulator
from the /detox
folder. Android testing requires an emulator named detox_pixel_4_xl_api_30
and the script helps to create it automatically.
This is the typical flow for local development and test writing:
npm install && npm start
from the root folder./detox
folder.npm install
.npm run e2e:android-build
.npm run e2e:android-test
.npm run e2e:android-test -- connect_to_server.e2e.ts
.This is the typical flow for CI test run:
npm install && npm run e2e:android-build-release
from the /detox
folder.npm run e2e:android-test-release
from the /detox
folder.brew tap wix/brew
brew install applesimutils
npm run ios
from the root folder.npm i
then npm run e2e:ios-test
from the /detox
folder.
npm run e2e:ios-test -- connect_to_server.e2e.ts
.npm run build:ios-sim
from the root folder or npm run e2e:ios-build-release
from within the /detox
folder.npm run e2e:ios-test-release
from the /detox
folder.Test configurations are defined at test_config.js and environment variables are used to override default values. In most cases you don’t need to change the values, because it makes use of the default local developer setup. If you do need to make changes, you may override by exporting, e.g. export SITE_URL=<site_url>
.
Variable | Description |
---|---|
SITE_URL | Host of test server. Default: http://localhost:8065 for iOS or http://10.0.2.2:8065 for Android. |
ADMIN_USERNAME | Admin’s username for the test server. Default: sysadmin when server is seeded by make test-data . |
ADMIN_PASSWORD | Admin’s password for the test server. Default: Sys@dmin-sample1 when server is seeded by make test-data . |
LDAP_SERVER | Host of LDAP server. Default: localhost |
LDAP_PORT | Port of LDAP server. Default: 389 |