Skip to content

Commit ec894f1

Browse files
committed
starting point
small tweaks testProps example test to see if we still need the workaround checkpoint post-rebase cleanup
1 parent 130a951 commit ec894f1

19 files changed

+8811
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,6 @@ package-lock.json
144144

145145
# Temporary files created by Metro to check the health of the file watcher
146146
.metro-health-check*
147+
148+
# E2E files
149+
/packages/rn-tester-e2e/apps

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"align-package-versions": "node -e \"require('./scripts/monorepo/align-package-versions')()\""
4545
},
4646
"workspaces": [
47-
"packages/*"
47+
"packages/!(rn-tester-e2e)/**"
4848
],
4949
"peerDependencies": {
5050
"react": "18.2.0"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# How to add a test
2+
3+
1. Create a test file `(rn-tester-e2e/test/spec)` - simple jest spec files
4+
2. **OPTIONAL -** Create a screen object or extend the existing one (depends on the test scope) - `rn-tester-e2e/test/screenObjects` - map screen elements for iOS and Android and add needed functions
5+
6+
# How to execute a test
7+
1. Open new Terminal -> navigate to the react-native path -> open Metro by typing
8+
9+
10+
```bash
11+
yarn start
12+
```
13+
14+
or
15+
16+
```bash
17+
npm start
18+
```
19+
20+
21+
2. Open second terminal -> navigate to the react-native/packages/rn-tester-e2e -> MAKE SURE YOUR APPIUM HAS UIAUTOMATOR2 AND XCUITEST INSTALLED! type
22+
```bash
23+
npm install [email protected] -g
24+
appium driver install uiautomator2
25+
appium driver install xcuitest
26+
appium --base-path /wd/hub # this is the run command
27+
```
28+
> More details about drivers in appium [here](https://appium.github.io/appium/docs/en/2.0/guides/managing-exts/) and [here](https://appium.github.io/appium/docs/en/2.0/quickstart/uiauto2-driver/)
29+
30+
31+
3. Open third terminal -> navigate to the react-native/packages/rn-tester-e2e -> run all tests by typing
32+
33+
```bash
34+
npm run ios
35+
```
36+
or
37+
38+
```bash
39+
npm run android
40+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Description of all folders and files in rn-tester-e2e
2+
3+
# folders
4+
5+
## helpers
6+
utils file with generic, simple steps
7+
8+
## screenObjects
9+
Screen object files based on Page Object Pattern. One file defines all neccessary elements to interact with. These elements are defined as screen class variables, they are used by the steps file
10+
11+
## specs
12+
Spec files. One file per screen/functionality
13+
14+
# root files
15+
## e2e-config.js
16+
android and iOS physical device configuration, process.env.E2E_device global variable is defined there - it can be used across the whole rn-tester-e2e directory
17+
18+
## jest.config.js
19+
global jest config setup - such as timeout, test runner path
20+
21+
## jest.setup.js
22+
jest and wdio setup file
23+
24+
## package.json
25+
all external dependecies and project parameters

packages/rn-tester-e2e/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# RNTester E2E folder
2+
3+
In this folder we have a local setup for doing E2E testing over RNTester via the usage of Appium and WebDriverIO and Jest.
4+
5+
## Setting up
6+
7+
### (one-off) Setting up Appium
8+
9+
The first step you need to do is to ensure to install the tooling:
10+
11+
```bash
12+
npm install [email protected] -g
13+
appium driver install uiautomator2
14+
appium driver install xcuitest
15+
```
16+
17+
> More details about drivers in Appium [here](https://appium.github.io/appium/docs/en/2.0/guides/managing-exts/) and [here](https://appium.github.io/appium/docs/en/2.0/quickstart/uiauto2-driver/)
18+
19+
You should not need to run install commands for drivers separately more than once, even if you bump the dep in package.json.
20+
21+
### Building RNTester app
22+
23+
Building manually *.app* and *.apk* is required to run automation tests on local environment.
24+
25+
0. *(optional)* If you previously built RNTester, you may need to clean up build files and Pods:
26+
27+
```bash
28+
npm run test-e2e-local-clean
29+
```
30+
31+
1. Step 1: install node modules for the repository, then navigate in the rn-tester folder
32+
33+
```bash
34+
cd react-native
35+
npm run install
36+
cd packages/rn-tester
37+
```
38+
39+
Now, depending on the platform, there are some specific steps
40+
41+
#### Building for iOS
42+
43+
0. Make sure you have Bundler `gem install bundler` - we use it ensure installing the right version of CocoaPods locally.
44+
1. Install Bundler and CocoaPods dependencies: `bundle install` then `bundle exec pod install` or `npm run setup-ios-hermes` for RNTester with Hermes. In order to use JSC instead of Hermes engine, run: `USE_HERMES=0 bundle exec pod install` or `setup-ios-jsc` instead.
45+
2. Open the generated `RNTesterPods.xcworkspace`.
46+
3. Build the app via XCode.
47+
4. Find the **RNTester.app** in `~/Library/Developer/Xcode/DerivedData/RNTesterPods-{id}/Build/Products/Debug-iphonesimulator`
48+
5. Copy the app to the following directory `/react-native/packages/rn-tester-e2e/apps`.
49+
6. change its name name to: `rn-tester.app`
50+
51+
#### Building for Android
52+
53+
0. You'll need to have all the [prerequisites](https://reactnative.dev/contributing/how-to-build-from-source#prerequisites) (SDK, NDK) for Building React Native installed.
54+
1. Start an Android emulator.
55+
2. Build the app via
56+
57+
```bash
58+
# In order to not use Hermes engine, run `npm run install-android-jsc` instead.
59+
npm run install-android-hermes
60+
npm run start
61+
```
62+
63+
*Note: Building for the first time can take a while.*
64+
65+
3. Find the **RNTester.app** in `~/react-native/packages/rn-tester/android/app/build/outputs/apk/hermes/debug`
66+
4. copy the app `app-*-x86_64-debug.apk` to the following directory `/react-native/packages/rn-tester-e2e/apps`
67+
5. change its name name to: `rn-tester.apk`
68+
69+
### Setting up the RNTester E2E folder
70+
71+
In `react-native/packages/rn-tester-e2e` install the needed dependencies via:
72+
73+
```bash
74+
npm install
75+
```
76+
77+
We need to do this step because the folder is not part of the npm run workspace by design.
78+
79+
Then open the following file
80+
81+
```bash
82+
/react-native/packages/rn-tester-e2e/e2e-config.js
83+
```
84+
85+
And modify lines L14->L29 to reflect your local setup configuration (ex. `platformVersion`, `deviceName`).
86+
87+
## Testing the RNTester app E2E
88+
89+
After you have done all the above correctly, and you have the Android/iOS apps in the `rn-tester-e2e/apps` folder, in a dedicated terminal window, run:
90+
91+
```bash
92+
appium --base-path /wd/hub
93+
```
94+
95+
This will start the Appium server - you will need this to keep running.
96+
97+
Then open a second terminal window and start the Metro terminal from the `packages/rn-tester` folder, via `npm run start --reset-cache`. This terminal window also needs to keep running.
98+
99+
Now, make sure that the iOS simulator/the Android emulator is up and running.
100+
101+
Finally, you can open a third terminal window and run:
102+
103+
```bash
104+
npm run test-android-e2e # for android
105+
npm run test-ios-e2e # for ios
106+
```
107+
108+
Now you should see the RNTester app being open, and the defined test being run.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
module.exports = {
12+
presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
13+
};

packages/rn-tester-e2e/e2e-config.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
const path = require('path');
12+
let capabilities;
13+
14+
const android = {
15+
platformName: 'Android',
16+
'appium:platformVersion': '13.0',
17+
'appium:deviceName': 'Android Emulator',
18+
'appium:app': path.join(process.cwd(), '/apps/rn-tester.apk'),
19+
'appium:automationName': 'UiAutomator2',
20+
'appium:newCommandTimeout': 240,
21+
};
22+
23+
const ios = {
24+
platformName: 'iOS',
25+
'appium:platformVersion': '16.2',
26+
'appium:deviceName': 'iPhone 14',
27+
'appium:automationName': 'XCUITest',
28+
'appium:app': path.join(process.cwd(), '/apps/rn-tester.app'),
29+
};
30+
31+
if (!process.env.E2E_DEVICE) {
32+
throw new Error('E2E_DEVICE environment variable is not defined');
33+
}
34+
35+
if (
36+
!(
37+
process.env.E2E_DEVICE.includes('android') ||
38+
process.env.E2E_DEVICE.includes('ios')
39+
)
40+
) {
41+
throw new Error('No e2e device configuration found');
42+
}
43+
44+
if (process.env.E2E_DEVICE === 'android') {
45+
capabilities = android;
46+
}
47+
48+
if (process.env.E2E_DEVICE === 'ios') {
49+
capabilities = ios;
50+
}
51+
52+
export default capabilities;

packages/rn-tester-e2e/jest.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
module.exports = {
12+
testTimeout: 60000,
13+
bail: 0,
14+
setupFilesAfterEnv: ['./jest.setup.js'],
15+
testMatch: ['**/specs/*.js'],
16+
};

packages/rn-tester-e2e/jest.setup.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
const wdio = require('webdriverio');
12+
import capabilities from './e2e-config.js';
13+
import {beforeEach, afterEach, jest} from '@jest/globals';
14+
jest.retryTimes(3);
15+
16+
let driver;
17+
const config = {
18+
path: '/wd/hub',
19+
host: 'localhost',
20+
port: 4723,
21+
waitforTimeout: 60000,
22+
logLevel: 'error',
23+
capabilities: {
24+
...capabilities,
25+
},
26+
};
27+
28+
beforeEach(async () => {
29+
driver = await wdio.remote(config);
30+
});
31+
32+
afterEach(async () => {
33+
console.info('[afterAll] Done with testing!');
34+
await driver.deleteSession();
35+
});
36+
37+
export {driver};

packages/rn-tester-e2e/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@react-native/tester-e2e",
3+
"private": true,
4+
"version": "0.0.1",
5+
"license": "MIT",
6+
"description": "React Native E2E tester app.",
7+
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/rn-tester-e2e",
8+
"repository": {
9+
"type": "git",
10+
"url": "[email protected]:facebook/react-native.git",
11+
"directory": "packages/rn-tester-e2e"
12+
},
13+
"devDependencies": {
14+
"appium": "^2.0.0-beta.57",
15+
"appium-uiautomator2-driver": "^2.12.6",
16+
"appium-xcuitest-driver": "^4.19.1",
17+
"eslint": "^8.19.0",
18+
"jest": "^29.2.1",
19+
"webdriverio": "^7.25.4"
20+
},
21+
"scripts": {
22+
"test": "jest --runInBand",
23+
"test-android-e2e": "E2E_DEVICE=\"android\" npm run test",
24+
"test-ios-e2e": "E2E_DEVICE=\"ios\" npm run test"
25+
},
26+
"dependencies": {
27+
"@babel/core": "^7.20.0",
28+
"@babel/preset-env": "^7.20.0",
29+
"@types/jest": "^29.2.1"
30+
}
31+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
import {driver} from '../../jest.setup';
12+
13+
class Utils {
14+
async checkElementExistence(locator) {
15+
await driver.$(locator).waitForDisplayed();
16+
return driver.$(locator).isDisplayed();
17+
}
18+
19+
async clickElement(locator) {
20+
await driver.$(locator).waitForDisplayed();
21+
await driver.$(locator).click();
22+
}
23+
24+
async getElementText(locator) {
25+
await driver.$(locator).waitForDisplayed();
26+
return driver.$(locator).getText();
27+
}
28+
29+
platformSelect(platforms) {
30+
return platforms[process.env.E2E_DEVICE];
31+
}
32+
}
33+
module.exports = new Utils();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
* @format
9+
*/
10+
11+
class ApisScreen {}
12+
module.exports = new ApisScreen();

0 commit comments

Comments
 (0)