From c2717e157278f45638e22f01a74866ab9f3865a2 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Tue, 31 Oct 2023 15:44:46 +0100 Subject: [PATCH] E2E Tests - Organize test device configuration (#55701) * Adds Device config JSON file for E2E testing * Update build_e2e_ios_app script to use device-config.json * Update E2E capabilities config to use device-config.json * Move WDA build script to its own file and updates it to use device-config.json * Update device config with SauceLabs/Buildkite specific config * Update packages/react-native-editor/__device-tests__/helpers/caps.js Co-authored-by: David Calhoun --------- Co-authored-by: David Calhoun --- .../__device-tests__/helpers/caps.js | 31 ++++++++++++++----- .../helpers/device-config.json | 29 +++++++++++++++++ .../react-native-editor/bin/build-e2e-wda.sh | 10 ++++++ .../react-native-editor/bin/build_e2e_ios_app | 7 ++++- packages/react-native-editor/package.json | 2 +- 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 packages/react-native-editor/__device-tests__/helpers/device-config.json create mode 100755 packages/react-native-editor/bin/build-e2e-wda.sh diff --git a/packages/react-native-editor/__device-tests__/helpers/caps.js b/packages/react-native-editor/__device-tests__/helpers/caps.js index 30cdb5d8d4601c..fc73b1c1c878af 100644 --- a/packages/react-native-editor/__device-tests__/helpers/caps.js +++ b/packages/react-native-editor/__device-tests__/helpers/caps.js @@ -1,5 +1,12 @@ +/** + * Internal dependencies + */ +import { + ios as iOSConfig, + android as androidConfig, +} from './device-config.json'; + const ios = { - platformVersion: '16.2', // Supported Sauce Labs platforms can be found here: https://saucelabs.com/rest/v1/info/platforms/appium deviceOrientation: 'portrait', automationName: 'XCUITest', processArguments: { @@ -10,22 +17,30 @@ const ios = { exports.iosLocal = ( { iPadDevice = false } ) => ( { ...ios, - deviceName: ! iPadDevice ? 'iPhone 14' : 'iPad (10th generation)', - pixelRatio: ! iPadDevice ? 3 : 2, + deviceName: ! iPadDevice + ? iOSConfig.local.deviceName + : iOSConfig.local.deviceTabletName, + platformVersion: iOSConfig.local.platformVersion, + pixelRatio: ! iPadDevice + ? iOSConfig.pixelRatio.iPhone + : iOSConfig.pixelRatio.iPad, usePrebuiltWDA: true, } ); exports.iosServer = ( { iPadDevice = false } ) => ( { ...ios, deviceName: ! iPadDevice - ? 'iPhone 14 Simulator' - : 'iPad (10th generation) Simulator', - pixelRatio: ! iPadDevice ? 3 : 2, + ? iOSConfig.saucelabs.deviceName + : iOSConfig.saucelabs.deviceTabletName, + platformVersion: iOSConfig.local.platformVersion, + pixelRatio: ! iPadDevice + ? iOSConfig.pixelRatio.iPhone + : iOSConfig.pixelRatio.iPad, } ); exports.android = { - platformVersion: '11.0', - deviceName: 'Google Pixel 3 XL GoogleAPI Emulator', + platformVersion: androidConfig.local.platformVersion, + deviceName: androidConfig.saucelabs.deviceName, automationName: 'UiAutomator2', appPackage: 'com.gutenberg', appActivity: 'com.gutenberg.MainActivity', diff --git a/packages/react-native-editor/__device-tests__/helpers/device-config.json b/packages/react-native-editor/__device-tests__/helpers/device-config.json new file mode 100644 index 00000000000000..5f952099133dd8 --- /dev/null +++ b/packages/react-native-editor/__device-tests__/helpers/device-config.json @@ -0,0 +1,29 @@ +{ + "ios": { + "local": { + "deviceName": "iPhone 14", + "deviceTabletName": "iPad (10th generation)", + "platformVersion": "16.2" + }, + "saucelabs": { + "deviceName": "iPhone 14 Simulator", + "deviceTabletName": "iPad (10th generation) Simulator" + }, + "buildkite": { + "platformVersion": "16.4" + }, + "pixelRatio": { + "iPhone": 3, + "iPad": 2 + } + }, + "android": { + "local": { + "deviceName": "Pixel_3_XL_API_30", + "platformVersion": "11.0" + }, + "saucelabs": { + "deviceName": "Google Pixel 3 XL GoogleAPI Emulator" + } + } +} diff --git a/packages/react-native-editor/bin/build-e2e-wda.sh b/packages/react-native-editor/bin/build-e2e-wda.sh new file mode 100755 index 00000000000000..2b835fbd6e608f --- /dev/null +++ b/packages/react-native-editor/bin/build-e2e-wda.sh @@ -0,0 +1,10 @@ +#!/bin/bash -eu + +set -o pipefail + +# Load configurations from JSON file +CONFIG_FILE="$(pwd)/__device-tests__/helpers/device-config.json" +IOS_DEVICE_NAME=$(jq -r '.ios.local.deviceName' "$CONFIG_FILE") +IOS_PLATFORM_VERSION=$(jq -r '.ios.local.platformVersion' "$CONFIG_FILE") + +xcodebuild -project ~/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination "platform=iOS Simulator,name=$IOS_DEVICE_NAME,OS=$IOS_PLATFORM_VERSION" -derivedDataPath ios/build/WDA diff --git a/packages/react-native-editor/bin/build_e2e_ios_app b/packages/react-native-editor/bin/build_e2e_ios_app index 569a62db21097f..2a0a293adedcb9 100755 --- a/packages/react-native-editor/bin/build_e2e_ios_app +++ b/packages/react-native-editor/bin/build_e2e_ios_app @@ -2,7 +2,12 @@ set -o pipefail -DEFAULT_DESTINATION='platform=iOS Simulator,name=iPhone 14,OS=16.2' +# Load configurations from JSON file +CONFIG_FILE="$(pwd)/__device-tests__/helpers/device-config.json" +IOS_DEVICE_NAME=$(jq -r '.ios.local.deviceName' "$CONFIG_FILE") +IOS_PLATFORM_VERSION=$(jq -r '.ios.local.platformVersion' "$CONFIG_FILE") + +DEFAULT_DESTINATION="platform=iOS Simulator,name=$IOS_DEVICE_NAME,OS=$IOS_PLATFORM_VERSION" if [[ -z "${RN_EDITOR_E2E_IOS_DESTINATION-}" ]]; then DESTINATION="$DEFAULT_DESTINATION" else diff --git a/packages/react-native-editor/package.json b/packages/react-native-editor/package.json index 49d2db22233131..e538d532980ae3 100644 --- a/packages/react-native-editor/package.json +++ b/packages/react-native-editor/package.json @@ -115,7 +115,7 @@ "test:e2e:android:local": "npm run test:e2e:bundle:android && npm run test:e2e:build-app:android && TEST_RN_PLATFORM=android npm run device-tests:local", "test:e2e:bundle:ios": "mkdir -p ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator/GutenbergDemo.app && npm run bundle:ios && cp bundle/ios/App.js ./ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator/GutenbergDemo.app/main.jsbundle && cp -r bundle/ios/assets ./ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator/GutenbergDemo.app/", "test:e2e:build-app:ios": "npm run preios && ./bin/build_e2e_ios_app", - "test:e2e:build-wda": "xcodebuild -project ~/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS Simulator,name=iPhone 14,OS=16.2' -derivedDataPath ios/build/WDA", + "test:e2e:build-wda": "./bin/build-e2e-wda.sh", "test:e2e:ios:local": "npm run test:e2e:bundle:ios && npm run test:e2e:build-app:ios && npm run test:e2e:build-wda && TEST_RN_PLATFORM=ios npm run device-tests:local", "build:gutenberg": "cd gutenberg && npm ci && npm run build", "clean": "npm run clean:build-artifacts; npm run clean:aztec; npm run clean:haste; npm run clean:metro; npm run clean:watchman",