diff --git a/packages/react-native-editor/__device-tests__/helpers/caps.js b/packages/react-native-editor/__device-tests__/helpers/caps.js index fc73b1c1c878af..02945c43de0400 100644 --- a/packages/react-native-editor/__device-tests__/helpers/caps.js +++ b/packages/react-native-editor/__device-tests__/helpers/caps.js @@ -13,6 +13,9 @@ const ios = { args: [ 'uitesting' ], }, autoLaunch: false, + usePrebuiltWDA: true, + simulatorStartupTimeout: 240, + reduceMotion: true, }; exports.iosLocal = ( { iPadDevice = false } ) => ( { @@ -24,15 +27,14 @@ exports.iosLocal = ( { iPadDevice = false } ) => ( { pixelRatio: ! iPadDevice ? iOSConfig.pixelRatio.iPhone : iOSConfig.pixelRatio.iPad, - usePrebuiltWDA: true, } ); exports.iosServer = ( { iPadDevice = false } ) => ( { ...ios, deviceName: ! iPadDevice - ? iOSConfig.saucelabs.deviceName - : iOSConfig.saucelabs.deviceTabletName, - platformVersion: iOSConfig.local.platformVersion, + ? iOSConfig.local.deviceName + : iOSConfig.local.deviceTabletName, + platformVersion: iOSConfig.buildkite.platformVersion, pixelRatio: ! iPadDevice ? iOSConfig.pixelRatio.iPhone : iOSConfig.pixelRatio.iPad, @@ -40,7 +42,7 @@ exports.iosServer = ( { iPadDevice = false } ) => ( { exports.android = { platformVersion: androidConfig.local.platformVersion, - deviceName: androidConfig.saucelabs.deviceName, + deviceName: androidConfig.local.deviceName, automationName: 'UiAutomator2', appPackage: 'com.gutenberg', appActivity: 'com.gutenberg.MainActivity', @@ -49,11 +51,6 @@ exports.android = { autoLaunch: false, }; -// SauceLabs config -exports.sauceOptions = { - appiumVersion: '2.0.0', -}; - exports.prefixKeysWithAppium = ( obj ) => { return Object.fromEntries( Object.entries( obj ).map( ( [ key, value ] ) => [ diff --git a/packages/react-native-editor/__device-tests__/helpers/device-config.json b/packages/react-native-editor/__device-tests__/helpers/device-config.json index 5f952099133dd8..8538e0bb9740b4 100644 --- a/packages/react-native-editor/__device-tests__/helpers/device-config.json +++ b/packages/react-native-editor/__device-tests__/helpers/device-config.json @@ -5,10 +5,6 @@ "deviceTabletName": "iPad (10th generation)", "platformVersion": "16.2" }, - "saucelabs": { - "deviceName": "iPhone 14 Simulator", - "deviceTabletName": "iPad (10th generation) Simulator" - }, "buildkite": { "platformVersion": "16.4" }, @@ -21,9 +17,6 @@ "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/__device-tests__/helpers/serverConfigs.js b/packages/react-native-editor/__device-tests__/helpers/serverConfigs.js index 7bfefd45b01843..62d5faa2b80702 100644 --- a/packages/react-native-editor/__device-tests__/helpers/serverConfigs.js +++ b/packages/react-native-editor/__device-tests__/helpers/serverConfigs.js @@ -2,11 +2,3 @@ exports.local = { host: '127.0.0.1', port: 4723, // Port for local Appium runs. }; - -exports.sauce = { - user: process.env.SAUCE_USERNAME, - key: process.env.SAUCE_ACCESS_KEY, - hostname: 'ondemand.us-west-1.saucelabs.com', - port: 443, - baseUrl: 'wd/hub', -}; diff --git a/packages/react-native-editor/__device-tests__/helpers/utils.js b/packages/react-native-editor/__device-tests__/helpers/utils.js index 8af4a0b1a60d71..e56983c11f3af4 100644 --- a/packages/react-native-editor/__device-tests__/helpers/utils.js +++ b/packages/react-native-editor/__device-tests__/helpers/utils.js @@ -5,7 +5,6 @@ const childProcess = require( 'child_process' ); // eslint-disable-next-line import/no-extraneous-dependencies, import/named import { remote, Key } from 'webdriverio'; -const crypto = require( 'crypto' ); const path = require( 'path' ); /** * Internal dependencies @@ -15,7 +14,6 @@ const { iosServer, iosLocal, android, - sauceOptions, prefixKeysWithAppium, } = require( './caps' ); const AppiumLocal = require( './appium-local' ); @@ -26,7 +24,7 @@ const defaultPlatform = 'android'; const rnPlatform = process.env.TEST_RN_PLATFORM || defaultPlatform; const iPadDevice = process.env.IPAD; -// Environment setup, local environment or Sauce Labs. +// Environment setup, local environment or server. const defaultEnvironment = 'local'; const testEnvironment = process.env.TEST_ENV || defaultEnvironment; @@ -48,7 +46,6 @@ const backspace = '\u0008'; const IOS_BUNDLE_ID = 'org.wordpress.gutenberg.development'; const ANDROID_COMPONENT_NAME = 'com.gutenberg/.MainActivity'; -const SAUCE_LABS_TIMEOUT = 240; const timer = ( ms ) => new Promise( ( res ) => setTimeout( res, ms ) ); @@ -80,29 +77,22 @@ const PLATFORM_NAME = isAndroid() ? 'Android' : 'iOS'; // Initialises the driver and desired capabilities for appium. const setupDriver = async () => { - const branch = process.env.CIRCLE_BRANCH || ''; - const safeBranchName = branch.replace( /\//g, '-' ); - if ( isLocalEnvironment() ) { - try { - appiumProcess = await AppiumLocal.start( { - port: localAppiumPort, - } ); - } catch ( err ) { - // Ignore error here, Appium is probably already running (Appium Inspector has its own server for instance) - // eslint-disable-next-line no-console - await console.log( - 'Could not start Appium server', - err.toString() - ); - } + try { + appiumProcess = await AppiumLocal.start( { + port: localAppiumPort, + } ); + } catch ( err ) { + // Ignore error here, Appium is probably already running (Appium Inspector has its own server for instance) + // eslint-disable-next-line no-console + await console.log( 'Could not start Appium server', err.toString() ); } let desiredCaps; if ( isAndroid() ) { desiredCaps = { ...android }; + desiredCaps.app = path.resolve( localAndroidAppPath ); if ( isLocalEnvironment() ) { const androidDeviceID = getAndroidEmulatorID(); - desiredCaps.app = path.resolve( localAndroidAppPath ); desiredCaps.udid = androidDeviceID; try { const androidVersion = childProcess @@ -121,14 +111,9 @@ const setupDriver = async () => { } catch ( error ) { // Ignore error. } - } else { - desiredCaps.app = `storage:filename=Gutenberg-${ safeBranchName }.apk`; // App should be preloaded to sauce storage, this can also be a URL. - desiredCaps.newCommandTimeout = SAUCE_LABS_TIMEOUT; } } else { desiredCaps = iosServer( { iPadDevice } ); - desiredCaps.newCommandTimeout = SAUCE_LABS_TIMEOUT; - desiredCaps.app = `storage:filename=Gutenberg-${ safeBranchName }.app.zip`; // App should be preloaded to sauce storage, this can also be a URL. if ( isLocalEnvironment() ) { desiredCaps = iosLocal( { iPadDevice } ); @@ -154,32 +139,17 @@ const setupDriver = async () => { `Using iOS ${ desiredCaps.platformVersion } platform version` ); } - - desiredCaps.app = path.resolve( localIOSAppPath ); - desiredCaps.derivedDataPath = path.resolve( webDriverAgentPath ); } + desiredCaps.app = path.resolve( localIOSAppPath ); + desiredCaps.derivedDataPath = path.resolve( webDriverAgentPath ); } - const sauceOptionsConfig = ! isLocalEnvironment() - ? { - 'sauce:options': { - ...sauceOptions, - name: `Gutenberg Editor Tests[${ rnPlatform }]-${ branch }`, - tags: [ 'Gutenberg', branch ], - }, - } - : {}; - const serverConfig = isLocalEnvironment() - ? serverConfigs.local - : serverConfigs.sauce; - const driver = await remote( { - ...serverConfig, + ...serverConfigs.local, logLevel: 'error', capabilities: { platformName: PLATFORM_NAME, ...prefixKeysWithAppium( desiredCaps ), - ...sauceOptionsConfig, }, } ); @@ -189,16 +159,10 @@ const setupDriver = async () => { const stopDriver = async ( driver ) => { if ( ! isLocalEnvironment() ) { - const sessionId = driver.sessionId; - - const secret = `${ serverConfigs.sauce.user }:${ serverConfigs.sauce.key }`; - const token = crypto - .createHmac( 'md5', secret ) - .update( sessionId ) - .digest( 'hex' ); - const jobURL = `https://app.saucelabs.com/tests/${ sessionId }?auth=${ token }`; // eslint-disable-next-line no-console - console.log( `You can view the video of this test run at ${ jobURL }` ); + console.log( + `You can view the video of this test run in the artifacts tab` + ); } if ( driver === undefined ) { return; @@ -394,7 +358,7 @@ const selectTextFromElement = async ( driver, element ) => { const selectAllElement = await driver.$( '//XCUIElementTypeMenuItem[@name="Select All"]' ); - await selectAllElement.waitForDisplayed( { timeout } ); + await selectAllElement.waitForDisplayed( { timeout: 3000 } ); await selectAllElement.click(); } }; diff --git a/packages/react-native-editor/bin/build-e2e-wda.sh b/packages/react-native-editor/bin/build-e2e-wda.sh index 2b835fbd6e608f..7ba785714d4785 100755 --- a/packages/react-native-editor/bin/build-e2e-wda.sh +++ b/packages/react-native-editor/bin/build-e2e-wda.sh @@ -5,6 +5,7 @@ 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") +# Use the value from the environment variable if set, otherwise use the value from the JSON file +IOS_PLATFORM_VERSION="${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