_RN App, fetchin and sending data with redux and RTK Query, added navigation and NativeBase UI library,react-navigation
- Conexión al endpoint
- Navegación entre pantallas
- Pruebas unitarias
uses a number of open source projects to work properly:
Name | Latest Version |
---|---|
@react-navigation/core | |
native-base | ^3.4.28 |
@reduxjs/toolkit | ^1.9.35 |
react-native | 0.71.4 |
- yarn
- yarn start
- yarn test
Requires Node.js to run.
Install the dependencies and devDependencies and start the server.
cd <ProjectFolder>
yarn
yarn start | yarn test
yarn android | yarn ios
This project can run Unit test using @testing-library/react-native
yarn run test
NOTE: check comments on jest.config.js and package.json how to switch beetwen unit test and e2e test
In this repo you will find a sample project to showcase how to do E2E testing with Jest + Appium + WebDriverIO for Android and iOS on react-native.
It's a bit janky but it serves the purpose of showcasing how to a basic setup needs to be correctly wired.
First off, install the needed tooling:
npm install appium@2.0.0-beta.53 -g
appium driver install uiautomator2
appium driver install xcuitest
After this, run the app on the Android emulator/ iOS simulator via yarn android
/yarn ios
- you need to do this at least once (for simplicity sake, we want the app to be already installed on the simulator/emulator before testing).
Once the app is on the emulator/simulator and Metro is running, you can open a new terminal window and start the Appium server via yarn appium
.
With the server is running, you can use the commands test:e2e:android
and test:e2e:ios
to try out the E2E loop, or use test:e2e:all
to run both one after the other.
Please make sure that your local emulator/simulator config matches the e2e-config.js
setup or it will fail 'cause it won't be able to connect to the platform.
The basic premise is that this is, from Appium's perspective, just a project like any other: the app it needs to test is a black box, and it gets to communicate with it via webdriverIO's client.
Via the command test:e2e:android
we start the testing, that starts up the basicE2E.test.js
script - this file gets via an helper script e2e-config.js
which platform to test (passed as an ENV variable, E2E_DEVICE
during the yarn command, check test:e2e:android
in package.json
) and goes into the package.json
, section e2e
, and uses those info the beforeAll
to stand up the webdriverIO client.
Then the actual testing is done by using as "communication point" to invoke the native components this following pattern client.$('~<string>')
(the ~ is intentional, and important!). The <string>
here is what we setup in App.js
, and it should be just the accessibilityID
option (that RN passes back to the native component) but actually we need to use a bit of a workaround script called testProps
(at the top of App.js
) to tailor this use for iOS/Android and for the Text
component. (huge props to Slav Kurochkin for finding this out and explaining it in this article)
This way we can interact with all the elements on screen that have their string setup as props via {...testProps(<string>)}
.
If this isn't clear enough or you'd like a blogpost on this subject, feel free to open an issue or talk to me over on Twitter.
Getting this together was quite a bit of work because there aren't many resources around that walk you through the entire setup for React Native Android/iOS - I pieced this sample app together by following and taking bit and pieces from multiple places. In no particular order:
- https://appium.io/docs/en/about-appium/intro/?lang=en
- https://github.com/kelset/react-native-e2e-jest-appium-webdriverio
The human-readable features are in tests/features/
in *.feature
files. Each step in the feature maps to a Python function in a *.py
file in tests/
.
npm install -g appium
npm install appium-doctor -g
# Run appium-doctor and see if everything is installed correctly
appium-doctor
pip3 install virtualenv
virtualenv workspace
source workspace/bin/activate
pip3 install pytest pytest-bdd appium-python-client pytest-parallel
- Run
react-native start
in one tab andappium
in another to start local servers. - Build the app for
both iOS andAndroid, producing simulator and emulator-ready files, and allowing the React Native server to complete bundlingindex.ios.js
andindex.android.js
. - Edit the
app
file locations for the webdrivers intests/test_android.py
andtests/test_ios.py
to find the.app
and.apk
files on your local system. - Run
py.test tests
MIT
Free Software, Hell Yeah!