Skip to content

Commit

Permalink
Merge pull request #1 from dojo-engineering/task/VIS-4480-build-maest…
Browse files Browse the repository at this point in the history
…ro-from-fork-and-deploy-binary-for-use-by-bitrise

🚀 [VIS-4480] Get maestro working on android api level 24 and above and build and deploy to github releases
  • Loading branch information
testifyqa authored Nov 28, 2023
2 parents d11bfad + 441e6bd commit b5261b7
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build Maestro for Dojo

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'

- name: Assemble APKs
run: ./gradlew :maestro-android:assembleAndroidTest :maestro-android:assemble

- name: Install maestro-cli
run: ./gradlew :maestro-cli:installDist -q

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: release-${{ github.run_id }}
release_name: Release ${{ github.run_id }}
draft: false
prerelease: false

- name: Upload maestro-cli asset to GitHub release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./maestro-cli/build/install/maestro/bin/maestro
asset_name: maestro
asset_content_type: application/octet-stream
2 changes: 1 addition & 1 deletion maestro-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {

defaultConfig {
applicationId "dev.mobile.maestro"
minSdk 21
minSdk 24
targetSdk 31
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.mobile.maestro

import android.os.Build
import android.view.accessibility.AccessibilityNodeInfo

object AccessibilityNodeInfoExt {

/**
* Retrieves the hint text associated with this [android.view.accessibility.AccessibilityNodeInfo].
*
* If the device API level is below 26 (Oreo), this function provides a fallback
* by returning an empty CharSequence instead.
*
* @return [CharSequence] representing the hint text or its fallback.
*/
fun AccessibilityNodeInfo.getHintOrFallback(): CharSequence {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
this.hintText
} else {
""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.widget.ListView
import android.widget.TableLayout
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import dev.mobile.maestro.AccessibilityNodeInfoExt.getHintOrFallback
import org.xmlpull.v1.XmlSerializer
import java.io.IOException
import java.io.OutputStream
Expand Down Expand Up @@ -120,7 +121,7 @@ object ViewHierarchy {
serializer.attribute("", "NAF", java.lang.Boolean.toString(true))
}
serializer.attribute("", "index", Integer.toString(index))
serializer.attribute("", "hintText", safeCharSeqToString(node.hintText))
serializer.attribute("", "hintText", safeCharSeqToString(node.getHintOrFallback()))
serializer.attribute("", "text", safeCharSeqToString(node.text))
serializer.attribute("", "resource-id", safeCharSeqToString(node.viewIdResourceName))
serializer.attribute("", "class", safeCharSeqToString(node.className))
Expand Down Expand Up @@ -276,4 +277,4 @@ object ViewHierarchy {
}
}

}
}
20 changes: 17 additions & 3 deletions maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ class AndroidDriver(

private fun startInstrumentationSession() {
val startTime = System.currentTimeMillis()
val instrumentationCommand = "am instrument -w -m -e debug false " +
"-e class 'dev.mobile.maestro.MaestroDriverService#grpcServer' " +
"dev.mobile.maestro.test/androidx.test.runner.AndroidJUnitRunner &\n"
val apiLevel = getDeviceApiLevel()

val instrumentationCommand = buildString {
append("am instrument -w ")
if (apiLevel >= 26) append("-m ")
append("-e debug false ")
append("-e class 'dev.mobile.maestro.MaestroDriverService#grpcServer' ")
append("dev.mobile.maestro.test/androidx.test.runner.AndroidJUnitRunner &\n")
}

while (System.currentTimeMillis() - startTime < getStartupTimeout()) {
instrumentationSession = dadb.openShell(instrumentationCommand)
Expand All @@ -105,6 +111,14 @@ class AndroidDriver(
throw AndroidInstrumentationSetupFailure("Maestro instrumentation could not be initialized")
}

private fun getDeviceApiLevel(): Int {
val response = dadb.openShell("getprop ro.build.version.sdk").readAll()
if (response.exitCode != 0) {
throw IOException("Failed to get device API level: ${response.errorOutput}")
}
return response.output.trim().toIntOrNull() ?: throw IOException("Invalid API level: ${response.output}")
}

private fun allocateForwarder() {
PORT_TO_FORWARDER[hostPort]?.close()
PORT_TO_ALLOCATION_POINT[hostPort]?.let {
Expand Down
Binary file modified maestro-client/src/main/resources/maestro-app.apk
Binary file not shown.
Binary file modified maestro-client/src/main/resources/maestro-server.apk
Binary file not shown.

0 comments on commit b5261b7

Please sign in to comment.