-
Notifications
You must be signed in to change notification settings - Fork 8
Polaris: As a developer I want an automated way to create and run e2e tests #3
Comments
I've done some researches to see how to integrate Detox with Expo. Short answer: it's not possible to use Detox with an Expo project. DetailsDetox does not officially support Expo, as written in their documentation:
I've searched online for tutorials or examples, but they are all outdated. All the examples I've found use a couple of Expo helpers:
But,
And
This is a list of tutorial/example I tried, but they didn't work:
ConclusionTo make Detox work with Polaris, we should:
|
The official Expo documentation does not mention any solution to provide e2e tests. The documentation only describes: |
Another thing to note is that Detox is a:
It does not support e2e testing for web apps. So we should configure an alternative tool to run e2e tests on web. In addition to that, even though Detox uses Jest to run the tests, I'm not so sure we can use the same test and run it on both mobile and web environment. Detox, in fact, provides its own matchers, actions and expectations. So we could end up writing the same test two times: one version for mobile and the other for the web. |
Mobile e2e tests with AppiumIn this post, I want to summarise my experience with Appium, what I've done and what still needs to be done. All the code I developed so far is in the draft PR: #59 These are the two steps required to run the mobile e2e test with Appium in Polaris:
Build the appsAppium installs the app inside the emulator/simulator before running the tests, so it needs an Android To build the apps locally, you have to:
Publish the resourcesExpo officially provides support to build apps locally, please check the official documentation: Building Standalone Apps on Your CI. The first step to build an app locally is to publish the static resources. This step requires an Expo account, so, if you don't have one, go to https://expo.io/signup. Then, you can run: npm run publish This command publishes the resources in a private URL (something like: // app.json
"privacy": "unlisted", In this way, only who knows the URL can load the app using the QRCode and the Expo client on his phone. Please note: there is even a safer option, as described in Hosting Updates on Your Servers, but requires to set-up a private server where publish the updated resources. Build the appsIf it's the first time building the app, follow the installation steps in Building Standalone Apps on Your CI. Please, remember to set-up the two environment variables To build the Android app, run: npm run build:local:android This command generates the following file: For the iOS app, run: npm run build:local:ios This command generates the following files: Run the testsBefore running the test, follow the "Introduction to Appium" and "Getting Started" tutorials and install:
After that, you are ready to run the tests. First, run the Appium server (a possible improvement could be to set-up the Appium Service that runs the server automatically before the tests): appium And in another terminal, run the Android test: node e2e/index.js Or the iOS one: node e2e/index.js ios As you can see, there isn't a package.json script in place yet. The test ( The main idea is to write a single test that can run on both platforms. I'm close to this objective but not there yet, let's dive into the code. Test internalsAll the code for the mobile e2e tests is located insider the
The testThe test is the same implemented for the web ( As you can see, the test does not use any testing library (no Jest, or Mocha, etc.), it simply uses the Still missing: configure a testing framework to run the test. Polaris is using Jest for unit tests, so we should try to use that for this e2e test. How to identify and select an element in the appAs you can see from the code, const settingsButton = await client.$('~go-to-settings'); Here, Next question/step is: how do I define an ID in the app's code so that we can reference it in the test? Well, in iOS we can use the So, if you set Unfortunately, the use of This issue is clear when you try to inspect the iOS app using the Appium's Desktop application. When This element (the more internal one) is the one that must be clicked to open the new screen. At the contrary, if both To solve this issue, the <Component
style={style}
title={titleAsProp ? title : null}
onPress={() => navigate(path, params)}
testID={testID}
accessibilityLabel={Platform.OS === 'android' ? testID : null}
> This solve the issue to identify all (almost) elements in the app to interact with. Unfortunately, there is still an issue on Android: find a way to locate and click the "Italian" item in the Android's picker. In iOS the following lines of code work correctly: const italianLanguage = await client.$('~Italiano');
await italianLanguage.click(); But on Android, no item is found with that selector. I tried to add an The Appium configuration files for iOS and AndroidThe two files // e2e/config.ios.js
const configuration = {
path: '/wd/hub',
port: 4723,
capabilities: {
platformName: 'iOS',
automationName: 'XCUITest',
deviceName: 'iPhone 11',
app: path.normalize(`${__dirname}/../build/polaris.app`)
}
};
// e2e/config.android.js
const configuration = {
path: '/wd/hub',
port: 4723,
capabilities: {
platformName: 'Android',
automationName: 'UiAutomator2',
deviceName: 'Android Emulator',
app: path.normalize(`${__dirname}/../build/polaris.apk`),
avd: 'Nexus_5_API_29'
}
}; In both configurations, is the
Please note, you can use the capabilities above to run the inspector provided by the Appium Desktop Application:
|
Adding another one to the list: https://cavy.app/ |
Current status is:
|
This week I worked on Simone's PR about "e2e web tests via appium", and this is what I've found:
const welcomeMessageText = await client.$(selector)
await welcomeMessageText.waitForDisplayed({ timeout: 10 * 1000 })
|
Create e2e test automation using https://github.com/wix/detox
The text was updated successfully, but these errors were encountered: