Maestro Setup for app (#407)

Implementing Maestro tests against onboarding process
This commit is contained in:
Ritesh Shukla
2025-06-05 02:14:52 +05:30
committed by GitHub
parent 1c069fe0bd
commit ecbbabcf4d
15 changed files with 273 additions and 8 deletions

View File

@@ -0,0 +1,66 @@
const { execSync, exec, spawn } = require('child_process')
const path = require('path')
// Read arguments from CLI
const [, , serverAddress, username, password] = process.argv
if (!serverAddress || !username || !password) {
console.error('Usage: node runMaestro.js <server_address> <username> <password>')
process.exit(1)
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
async function stopRecording(pid) {
try {
// Kill the adb screenrecord process
process.kill(pid, 'SIGINT')
// Wait 3 seconds for file to finalize
await sleep(3000)
// Pull the recorded file
execSync('adb pull /sdcard/screen.mp4 video.mp4', { stdio: 'inherit' })
// Optionally delete the file on device
execSync('adb shell rm /sdcard/screen.mp4')
console.log('✅ Recording pulled and cleaned up')
} catch (err) {
console.error('❌ Failed to stop or pull recording:', err.message)
}
}
;(async () => {
execSync('adb install ./artifacts/app-x86-release.apk', { stdio: 'inherit', env: process.env })
execSync(`adb shell monkey -p com.jellify 1`, { stdio: 'inherit' })
const recording = spawn('adb', ['shell', 'screenrecord', '/sdcard/screen.mp4'], {
stdio: 'ignore',
detached: true,
})
const pid = recording.pid
try {
const MAESTRO_PATH = path.join(process.env.HOME, '.maestro', 'bin', 'maestro')
const FLOW_PATH = './maestro-tests/flow.yaml'
const command = `${MAESTRO_PATH} test ${FLOW_PATH} \
--env server_address=${serverAddress} \
--env username=${username} \
--env password=${password}`
const output = execSync(command, { stdio: 'inherit', env: process.env })
console.log('✅ Maestro test completed')
console.log(output)
await stopRecording(pid)
process.exit(0)
} catch (error) {
await stopRecording(pid)
execSync('pwd', { stdio: 'inherit' })
console.error(`❌ Error: ${error.message}`)
process.exit(1)
}
})()

66
scripts/updateEnv.js Normal file
View File

@@ -0,0 +1,66 @@
const fs = require('fs')
const path = require('path')
function parseArgs(args) {
const updates = {}
args.forEach((arg) => {
const [key, value] = arg.split('=')
if (key && value !== undefined) {
updates[key.trim()] = value.trim()
}
})
return updates
}
function updateEnvFile(filePath, updates) {
let envContent = ''
try {
envContent = fs.readFileSync(filePath, 'utf8')
} catch (err) {
console.error(`❌ Failed to read .env file at ${filePath}`, err.message)
return
}
const lines = envContent.split(/\r?\n/)
const seenKeys = new Set()
const updatedLines = lines.map((line) => {
if (!line.trim() || line.trim().startsWith('#')) return line
const [key, ...rest] = line.split('=')
const trimmedKey = key.trim()
if (updates.hasOwnProperty(trimmedKey)) {
seenKeys.add(trimmedKey)
return `${trimmedKey}=${updates[trimmedKey]}`
}
return line
})
// Add any new keys not already in the file
Object.entries(updates).forEach(([key, value]) => {
if (!seenKeys.has(key)) {
updatedLines.push(`${key}=${value}`)
}
})
try {
fs.writeFileSync(filePath, updatedLines.join('\n'), 'utf8')
console.log('✅ .env file updated successfully')
} catch (err) {
console.error(`❌ Failed to write .env file:`, err.message)
}
}
// Get CLI args (excluding node and script path)
const args = process.argv.slice(2)
if (args.length === 0) {
console.error('❗ Usage: node updateEnv.js KEY1=value1 KEY2=value2')
process.exit(1)
}
const updates = parseArgs(args)
const envPath = path.resolve(__dirname, '../.env')
updateEnvFile(envPath, updates)