forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run Maestro tests also in debug mode (facebook#46573)
Summary: This change runs Maestro tests also in Debug mode, by starting Metro in background. ## Changelog: [Internal] - Add E2E tests in Debug mode too Pull Request resolved: facebook#46573 Test Plan: GHA must be green. Successful run: https://github.com/facebook/react-native/actions/runs/11033322135?pr=46573 Reviewed By: cortinico Differential Revision: D63452169 Pulled By: cipolleschi fbshipit-source-id: e04b87f6a3e7aca8519dc2cb37c982dff3c20100
- Loading branch information
1 parent
19d468f
commit 94b7793
Showing
5 changed files
with
209 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
const childProcess = require('child_process'); | ||
|
||
const usage = ` | ||
=== Usage === | ||
node maestro-android.js <path to app> <app_id> <maestro_flow> <flavor> <working_directory> | ||
@param {string} appPath - Path to the app APK | ||
@param {string} appId - App ID that needs to be launched | ||
@param {string} maestroFlow - Path to the maestro flow to be executed | ||
@param {string} flavor - Flavor of the app to be launched. Can be 'release' or 'debug' | ||
@param {string} workingDirectory - Working directory from where to run Metro | ||
============== | ||
`; | ||
|
||
const args = process.argv.slice(2); | ||
|
||
if (args.length !== 5) { | ||
throw new Error(`Invalid number of arguments.\n${usage}`); | ||
} | ||
|
||
const APP_PATH = args[0]; | ||
const APP_ID = args[1]; | ||
const MAESTRO_FLOW = args[2]; | ||
const IS_DEBUG = args[3] === 'debug'; | ||
const WORKING_DIRECTORY = args[4]; | ||
|
||
async function main() { | ||
console.info('\n=============================='); | ||
console.info('Running tests for Android with the following parameters:'); | ||
console.info(`APP_PATH: ${APP_PATH}`); | ||
console.info(`APP_ID: ${APP_ID}`); | ||
console.info(`MAESTRO_FLOW: ${MAESTRO_FLOW}`); | ||
console.info(`IS_DEBUG: ${IS_DEBUG}`); | ||
console.info(`WORKING_DIRECTORY: ${WORKING_DIRECTORY}`); | ||
console.info('==============================\n'); | ||
|
||
console.info('Install app'); | ||
childProcess.execSync(`adb install ${APP_PATH}`, {stdio: 'ignore'}); | ||
|
||
let metroProcess = null; | ||
if (IS_DEBUG) { | ||
console.info('Start Metro'); | ||
childProcess.execSync(`cd ${WORKING_DIRECTORY}`, {stdio: 'ignore'}); | ||
metroProcess = childProcess.spawn('yarn', ['start', '&'], { | ||
cwd: WORKING_DIRECTORY, | ||
stdio: 'ignore', | ||
detached: true, | ||
}); | ||
console.info(`- Metro PID: ${metroProcess.pid}`); | ||
} | ||
|
||
console.info('Wait For Metro to Start'); | ||
await sleep(5000); | ||
|
||
console.info('Start the app'); | ||
childProcess.execSync(`adb shell monkey -p ${APP_ID} 1`, {stdio: 'ignore'}); | ||
|
||
console.info('Start recording to /sdcard/screen.mp4'); | ||
childProcess | ||
.exec('adb shell screenrecord /sdcard/screen.mp4', { | ||
stdio: 'ignore', | ||
detached: true, | ||
}) | ||
.unref(); | ||
|
||
console.info(`Start testing ${MAESTRO_FLOW}`); | ||
let error = null; | ||
try { | ||
childProcess.execSync( | ||
`MAESTRO_DRIVER_STARTUP_TIMEOUT=120000 $HOME/.maestro/bin/maestro test ${MAESTRO_FLOW} --format junit -e APP_ID=${APP_ID} --debug-output /tmp/MaestroLogs`, | ||
{stdio: 'inherit'}, | ||
); | ||
} catch (err) { | ||
error = err; | ||
} finally { | ||
console.info('Stop recording'); | ||
childProcess.execSync('adb pull /sdcard/screen.mp4', {stdio: 'ignore'}); | ||
|
||
if (IS_DEBUG && metroProcess != null) { | ||
const pid = metroProcess.pid; | ||
console.info(`Kill Metro. PID: ${pid}`); | ||
process.kill(-pid); | ||
console.info(`Metro Killed`); | ||
process.exit(); | ||
} | ||
} | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
} | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} | ||
|
||
main(); |
Oops, something went wrong.