React Native is an open-source framework, widely used for cross-platform mobile app development. For the testing of mobile applications developed using React Native, an open-source testing framework, Appium is quite famous. Here are some features of Appium:
- Appium is an open-source free framework.
- It provides an interface for automated testing of native, mobile, and hybrid applications.
- It supports multiple programming languages.
- Appium enables cross-platform testing on devices and emulators.
- It does not require re-compilation of apps.
This article covers the basics of Appium automation testing. Assume we have a basic React Native application with a login page and we have to test its elements. Let’s start.
Installing Appium in React Native
To install Appium, you can download and install Appium Desktop or install it using npm. We will use npm, so run the following:
npm install -g appium
Now install WD.js web driver to communicate with Appium server.
npm install wd
Now, create a test file and add the following code:
import wd from ‘wd’;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;
const PORT = 4723;
Make sure you enter the right options for your device. Here we are using the iOS device config. So we will add the following code:
const config = {
platformName: “iOS”,
platformVersion: “14.4”,
deviceName: “iPhone 11”,
app: “path/to/your/app.apk or app.ipa”,
automationName: “XCUITest”,
};
Here is the driver setup:
const driver = wd.promiseChainRemote(‘localhost’, PORT);
beforeAll(async () => {
await driver.init(config);
})
Now make sure that the accessibility label is set for the email and password fields.
test(‘Test Accessibility Id’, async () => {
expect(await driver.hasElementByAccessibilityId(’email’)).toBe(true);
expect(await driver.hasElementByAccessibilityId(‘password’)).toBe(true);
});
Running the Test in Appium
To run the test, we will start Appium server by running following command:
appium–app $ appium
[Appium] Welcome to Appium v1.20.2
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
Now, open another terminal and run the following command:
npm test login
Appium will check the app UI and test the labels. In our case, the results will be like:
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 1 total
Time: 5.775s, estimated 7s
Ran all test suites matching /login/i.
Conclusion:
Testing the React Native app can be time-consuming but it is a necessary step to make your project credible. This article explains that Appium is a robust and reliable framework for automation testing of React Native apps.