Cannot Upload File to Aws S3 Expo Sdk 28 React Native
What's React Native?
React Native is a framework for edifice native mobile apps for iOS and Android in one shared JavaScript or TypeScript codebase for which y'all volition need to take an agreement of JavaScript fundamentals. The underlying build system is a normal iOS and Android project, with a JavaScript execution environs and libraries to return your bundled JavaScript lawmaking into actual native components.
There are various ways to install and build your kickoff React Native app. If you are new to mobile development, the easiest style to get started is with Expo CLI. Expo is a prepare of tools built effectually React Native with many features, but if you lot are already familiar with mobile development, you may want to use React Native CLI. Information technology requires Xcode or Android Studio to go started.
What'southward cease-to-end testing?
End-to-end (E2E) testing is a technique used to exam whether the catamenia of an application right from start to terminate is behaving every bit expected. E2E tests simulate real user scenarios — essentially, testing how a real user would use the application.
The purpose of performing E2E testing is to identify system dependencies and to ensure that information integrity is maintained between diverse system components and systems. E2E tests are used to verify our system or the entire application is working correctly and preclude bugs and regression from happening.
What'southward Detox?
Detox is a gray box E2E testing automation framework for mobile apps (Android and iOS) adult by Wix and does not rely on Selenium WebDriver. It tests your mobile app while it'south running on real devices or simulators/emulators, interacting with it just like a real user. But currently, information technology offers more capabilities for iOS than Android.
Detox is built from the footing up to support React Native projects too equally pure native ones.
The most important features in Detox are:
- Cross-platform: Write cross-platform tests in JavaScript. For both Android and iOS.
- Runs on devices: Gain the conviction to ship by testing your app on a device only similar a real user.
- Detox helps us to avoid flakiness past monitoring asynchronous operations in mobile apps.
- Execute your E2E tests on CI platforms similar Bitrise hands.
- Detox uses Jest, Mocha, or any other JavaScript test runner you lot like.
Before you get started
To be able to build and test your React Native apps smoothly with Detox, you should have the following environment set up:
- macOS 10.xv (Catalina) or college
- XCode 11.0 or higher
- Installed Node and NPM
- Installed Watchman
- Installed Homebrew.
- Installed React Native CLI or Expo CLI as you preferred (I will employ React Native CLI in this demo)
- Installed CocoaPods
- Installed Java JDK +viii
- Installed Android Studio, Android SDK, and Virtual Device
Note: You can apply Windows and Linux but macOS is required to build projects with native code for iOS.
For more details on setting up the development environment, read this Getting Started guide. The code repository can be constitute here.
Let's get started!
(If you already take a React Native app, you tin scroll down to the 'Setting up Detox' section).
1. Use the post-obit control to create a new React Native app:
If the project is created successfully, you will find the instructions to build the Android and iOS apps:
2. inside the project folder yous can run the application using Metro, the JavaScript bundler that ships with React Native, with the following command:
3. To run the Android application, open the emulator, open up a new terminal inside your React Native project folder, and run the following command:
If everything is fix up correctly, you should see your new app running in your Android emulator successfully:
4. To run the iOS application, you demand to enter inside the ios folder and run the pod install control with the post-obit commands:
5. Inside your React Native project folder and run the following command:
If everything is prepare correctly, you lot should see your new app running in your iOS simulator successfully:
Congratulations! Y'all've successfully run your first React Native app.
Setting upwardly Detox
ane. Nosotros will get-go by installing the Detox requirements with the following commands:
2. Then install Detox CLI with the following command:
three. Inside your React Native projection folder, install Detox with the following command to add the Detox dependencies in our package.json file:
4. In the React Native projection folder initiate Detox in the project by the post-obit command:
5. It will create a new binder with the name e2e including unlike .js files for Detox like:
e2e/config.json: includes the configuration of the test runner, test environment, reports, and the maxWorkers
e2e/surround.js: includes the Detox custom configuration for the Detox Test Runner with jest-circus.
e2e/firstTest.e2e.js: a sample test case is written in Javascript and likewise you can use Typescript to write your tests with Detox
And in the project folder, Detox created a .detoxrc.json, which includes the Detox configuration for the apps, devices, and the other configuration that is required to run Detox for our iOS and Android apps.
We will demand to alter the configuration by calculation the binaryPath, devices that nosotros have, and the build variants to friction match with our app:
And a full example tin can be found here.
In the above Detox configuration file, we added ii product flavors (debug and release), and also we changed the iOS Simulator and the Android Emulator.
And for iOS, we are using Xcodebuild to build our iOS with the scheme and for Android, we are using Gradle to practise the same.
Annotation:The Detox team highly recommends using the AOSP Emulator for running automation/Detox tests.
Changes for Android app
In version 11, Detox switched to using Android Espresso of Android'southward new androidx.* back up libraries in order to stay up to appointment with Google'southward latest features and bug fixes.
Considering of that, you lot should make the following changes in your Android app to be able to examination it with Detox.
Add the Native Detox dependency
1. In your root android/build.gradle file add together Detox equally repository lookup points in all projects:
2. In your app build.gradle add together this in the dependencies section:
3. And add together this to the defaultConfig section:
iv. Add the file android/app/src/androidTest/java/com/[package name]/DetoxTest.java
The Detox test code running on the device must connect to the test-running host through its virtual localhost interface using simple HTTP traffic. Therefore, the following network-security exemption configuration must be applied In an XML resource file, android/app/src/master/res/xml/network_security_config.xml
And finally, in the app'southward AndroidManifest.xml add the following line
More details tin be found here.
Changes for E2E test
Every bit we mentioned, within the e2e binder you will find a unproblematic test just nosotros need to modify the steps to lucifer our app:
To know more about Detox, check the actions and the matchers docs.
Now it'due south time to build and test our React Native apps with Detox. Nosotros will start with the Android app. From the command line run the following command:
If the build is done successfully, you will detect the app.apk and testapp.apk in the output binder inside the Android project.
To run the tests with Detox utilize the following command:
Tip: If you tried to run the detox build or examination commands and found this error.
You need to install jest-circus runner with the following command:
Run it once again and cheque the test results. Congratulations, you have successfully set and run Detox for your React Native awarding! 🎉
And to run Detox with iOS, we run the following commands:
Taking screenshots, recording videos, and logs
Artifacts are disabled by default. To enable them, specify via launch arguments or a configuration object what artifacts you want to record.
- To record .log files, add --tape-logs all (or --tape-logs declining, if you want to keep logs only for failing tests).
- To record .mp4 exam run videos, add --record-videos all (or --record-videos failing, if you lot want to keep video recordings just for failing tests).
- To take .png screenshots before and subsequently each test, add together --take-screenshots all (or --have-screenshots failing, if y'all want to keep only screenshots of failing tests).
- To modify artifacts root directory location (by default information technology is ./artifacts), add together --artifacts-location <path>
Let's effort the artifacts
And the artifacts folder will include the logs, screenshots, and videos:
React Native, Detox, and Bitrise: putting it all together
At present information technology's time to integrate and run our tests with the CI server. Nosotros, of course, will use Bitrise.
First, yous need to create a free Bitrise account:
2. After logging in, you volition accept a blank dashboard and you lot can start adding your projects.
three. Click the Add your first app push.
four. Select your account and set the privacy for the App (Private or Public) and click Next.
5. Choose the repository but before that, you accept to give Bitrise access rights to your source code provider (east.g. GitHub).
half dozen. You need to set the repository access, so either auto-add an SSH central or manually add your ain SSH central.
vii. Choose the branch name (e.g. master branch) and click Side by side.
8. Next, Bitrise will run a validation with your repository and configuration.
9. Later validating, the project build configuration volition display successfully (due east.chiliad. React Native App). The scanner detected that the projection blazon is React Native.
And nosotros should configure the build configuration for both apps:
You tin can besides edit this configuration if you need to use a unlike Xcode stack.
TIP: Bitrise supports the latest Xcode versions within 48 hours of Apple's announcements to requite mobile engineers the opportunity to update their apps and use new features with the latest SDKs for iOS, iPad, watchOS, and the latest OS like macOS Large Sur. For more info read our commodity on Xcode availability benchmarks.
We highly recommend using the Gen2 machines to build and test both apps faster and non face instability issues. For further details on how Gen2 compares to Gen1 machines, please download the Gen2 criterion report.
x. Click the Ostend button later reviewing the workflow stack. You tin add the app icon too or you tin can skip it for now.
11. The last footstep is Webhook prepare upwards: y'all just demand to select Register a Webhook for me and you lot volition trigger your first iOS build for your project 🚀 🎉
12. Y'all will be redirected to the build log and yous tin can bank check the Steps and the build status.
thirteen. At the end, you will find a summary of all the tasks that you have run during the build with the fourth dimension and Footstep names. You tin too download logs or cheque the apps and artifacts.
NOTE: As you may have noticed, we didn't need to configure or install any prerequisites related to the infrastructure or the stack considering Bitrise is managing all of these things for us. For instance, installing and configuring NodeJS, NPM, or Git.
14. At present, let's open the Workflow Editor to start adding all the required steps to build and examination our React Native app with Detox.
xv. In the Workflow Editor, you lot will find that nosotros already have the predefined Steps added.
16. Select the Secrets tab if you want to add your Environs Variables such every bit:
- APP_IDENTIFIER
- APPLE_ID
- SLACK_URL
- ANDROID KEYSTORE FILE
17. Select the Env Vars tab to add whatsoever other Environment Variables you need in your application. Practice NOT add private data here, considering these Surroundings Variables volition likewise be available in builds triggered past pull requests and bitrise.yml.
19. We already take a Step for the Active SSH Fundamental and Git Clone Repository. Run npm commands including npm install and npm test commands to be able to access and clone the source code from GitHub or whatever other source code direction tool and install the requirements for our React Native app.
20. We will add together new steps to our Workflow to build, test, and deploy our Android and iOS apps past clicking the [+] button which will display all the integration Steps that we accept for React Native apps in Bitrise.
TIP: Y'all can select All to display all the Steps for all platforms.
TIP: Bitrise has 330+ integration Steps for all the mobile platforms with different categories.
21. Add together the script Step to install Detox prerequisites:
22. Add another script Step to install Detox CLI and React Native CLI:
23. Add a new script Step to run the pod install control:
24. Add a Footstep for the AVD Manager to create an Android Emulator:
25. Add together another Pace: Expect for Android Emulator. Nosotros usually use this Step to wait for the emulator until created and started:
26. Add new script Steps to run Detox Build and ane for Detox Examination for both iOS and Android:
27. And ane more script for copying the artifacts to the Bitrise Deploy folder to exist able to access them from the Artifacts tab:
28. Add the Transport a Slack message Step at the stop of the Workflow to send the final condition of the build:
TIP: For each footstep in the Bitrise Workflow we have an option to run the current Stride, whether the previous Pace failed or not. This volition assist us to arrest the build if any previous Steps failed and avoid wasting any time. (It'due south prepare to off by default)
29. You tin can now run your React Native CI/CD workflow manually past clicking Start/Schedule a Build or based on the trigger map with Bitrise. For example, you can specify a GitHub Tag or branch with a specific Workflow:
30. After the build is finished, if everything is ready up correctly, y'all should see the build succeeded:
31. To check the artifacts, including the videos and the screenshots, click on Artifacts Tab and you will find the deploy folder. Yous tin can download it or you tin can configure your build to upload it to whatsoever other 3rd political party tool or service like Amazon S3 bucket:
TIP: If you desire to schedule the build to run nightly you can likewise configure information technology easily by selecting the date/fourth dimension, branch proper noun, and Workflow proper noun.
TIP: You tin find the bitrise.yml file including all the Steps that we added in the Workflow editor and you tin can save it in your repository or store it on Bitrise.io.
Congratulations! 🎉 You have successfully migrated your iOS app from Jenkins and fastlane to Bitrise. You can now showtime building and releasing your applications seamlessly, with no extra endeavor.
Code Repository
https://github.com/moatazeldebsy/reactnative-detox-bitrise
Related Articles
- Getting started with React Native apps
- React Native Continuous Integration and Commitment
- React Native
- Getting started with Detox
- Detox Setup for Android
- Detox CLI
If yous have any questions, experience free to contact the states on our Twitter or via e-mail. If you'd like to find out more well-nigh how Bitrise can aid you release amend apps, faster, you lot tin can besides request a demo here.
Source: https://blog.bitrise.io/post/react-native-e2e-ui-testing-with-detox-and-bitrise
Post a Comment for "Cannot Upload File to Aws S3 Expo Sdk 28 React Native"