Skip to content

Commit

Permalink
E2E Tests - Organize test device configuration (#55701)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: David Calhoun <[email protected]>
  • Loading branch information
Gerardo Pacheco and dcalhoun authored Oct 31, 2023
1 parent 10187d3 commit c2717e1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
31 changes: 23 additions & 8 deletions packages/react-native-editor/__device-tests__/helpers/caps.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
10 changes: 10 additions & 0 deletions packages/react-native-editor/bin/build-e2e-wda.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion packages/react-native-editor/bin/build_e2e_ios_app
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c2717e1

Please sign in to comment.