Skip to main content

Allure (Android)

Ultron generates Allure artifacts through the ultron-allure module. This page covers Android instrumented tests, where the module plugs into the allure-kotlin pipeline through an instrumentation runner. Compose Multiplatform tests (desktop/JVM, iOS, macOS, js, wasmJs) use the same module and the same UltronAllureConfig with Ultron's own result writer — see Allure for Compose Multiplatform (new in 2.7.0).

Android​

Add the dependencies to the application module that holds the instrumented tests:

dependencies {
androidTestImplementation("com.atiurin:ultron-android:<latest_version>")
androidTestImplementation("com.atiurin:ultron-allure:<latest_version>")
}

set the Ultron testInstrumentationRunner in the same build.gradle.kts (example build.gradle.kts):

android {
defaultConfig {
testInstrumentationRunner = "com.atiurin.ultron.allure.UltronAllureTestRunner"
...
}
}

and apply the recommended config once in your base test class (example BaseTest):

abstract class BaseTest {
companion object {
@BeforeClass @JvmStatic
fun setConfig() {
UltronConfig.applyRecommended()
UltronAllureConfig.applyRecommended()
}
}
}

Custom results directory​

Ultron allows you to specify the directory where the Allure results will be stored. By default, the results are stored on the device in the app's private storage, <app files dir>/allure-results. You can change this directory by calling UltronAllureConfig.setAllureResultsDirectory()

@BeforeClass @JvmStatic
fun setConfig() {
...
UltronAllureConfig.applyRecommended()
UltronAllureConfig.setAllureResultsDirectory(Environment.DIRECTORY_DOWNLOADS)
}

Getting the report​

Allure result files are written on the device while the instrumented tests run; the HTML report is built on the host afterwards with the Allure command line (brew install allure, or npx allure-commandline@2.32.0 <command>).

  1. Make the results reachable with adb. The default directory, <app files dir>/allure-results (/data/data/<applicationId>/files/allure-results), is private to the app and can only be read with adb shell run-as <applicationId> on a debuggable build. Redirect the results to the public download directory instead, which UltronAllureResultsTransferListener fills after every test:

    @BeforeClass @JvmStatic
    fun setConfig() {
    UltronConfig.applyRecommended()
    UltronAllureConfig.applyRecommended()
    UltronAllureConfig.setAllureResultsDirectory(Environment.DIRECTORY_DOWNLOADS) // → /sdcard/Download/allure-results
    }
  2. Run the tests and pull the directory (clear it first so the report contains only this run):

    adb shell rm -rf /sdcard/Download/allure-results
    ./gradlew :app:connectedDebugAndroidTest # :app stands for your application module
    adb pull /sdcard/Download/allure-results build/allure-results-android

    With the default directory instead (debuggable build only): mkdir -p build/allure-results-android && adb shell run-as <applicationId> tar -cf - -C files/allure-results . | tar -xf - -C build/allure-results-android.

  3. Generate and open the report:

    allure generate build/allure-results-android --clean -o build/allure-report
    allure open build/allure-report

    allure serve build/allure-results-android does both in one step. Results of Compose Multiplatform tests from the same project (desktop, iOS, browsers) can be passed to the same allure generate and appear in one report: the host label shows the platform of a result, and each Compose Multiplatform result carries its target in the target parameter and in its historyId, so the same test run on several targets shows as separate tests rather than as retries of one; see From results to a report.

Test farms that collect allure-results themselves (Marathon, device-farm runners, the Allure Gradle plugin) read the same directory, so point them at the one configured in step 1.

Ultron Allure report contains:​

  • Detailed report about all operations in your test
  • Logcat file (in case of failure)
  • Screenshot (in case of failure)
  • Ultron log file (in case of failure)

You also can add any artifact you need. It will be described later.

allure


Ultron step​

Ultron wraps Allure step method into it's own one.

It's recommended to use Ultron method cause it will provide more info to report in future releases.

Best practice​

Wraps all steps with Ultron step method e.g.

object ChatPage: Page<ChatPage>(){
...
fun sendMessage(text: String) = apply {
step("Send message with text '$text") {
inputMessageText.typeText(text)
sendMessageBtn.click()
this.getMessageListItem(text).text
.isDisplayed()
.hasText(text)
}
}

fun assertMessageTextAtPosition(position: Int, text: String) = apply {
step("Assert item at position $position has text '$text'"){
this.getListItemAtPosition(position).text.isDisplayed().hasText(text)
}
}
}

Custom config​

UltronConfig.apply {
this.operationTimeoutMs = 10_000
this.logToFile = false
this.accelerateUiAutomator = false
}
UltronAllureConfig.apply {
this.attachUltronLog = false
this.attachLogcat = false
this.detailedAllureReport = false
this.addConditionsToReport = false
this.addScreenshotPolicy = mutableSetOf(
AllureAttachStrategy.TEST_FAILURE, // attach screenshot at the end of failed test
AllureAttachStrategy.OPERATION_FAILURE, // attach screenshot once operation failed
AllureAttachStrategy.OPERATION_SUCCESS // attach screenshot for each operation
)
this.recordVideoPolicy = mutableSetOf(
AllureAttachStrategy.TEST_FAILURE // or TEST_FINISH to keep the video of every test
)
this.screenRecordOptions = ScreenRecordOptions(size = "540x1200", bitRate = 1_000_000, timeLimitSec = 180)
}
UltronComposeConfig.apply {
this.operationTimeoutMs = 7_000
...
}

UltronAllureConfig.params is an AllureConfigParams. On Android it keeps everything it had as a data class in 2.6.6 and earlier, so existing code compiles and links unchanged: the constructor with the six parameters addScreenshotPolicy, addHierarchyPolicy, attachUltronLog, attachLogcat, addConditionsToReport, detailedAllureReport (same order, same defaults), copy(...), component1()..component6(), equals, hashCode and toString. recordVideoPolicy and screenRecordOptions are properties outside the constructor; copy takes them as two extra trailing parameters, and equals / hashCode include them.

UltronAllureConfig.params = AllureConfigParams(attachLogcat = false)
UltronAllureConfig.params = UltronAllureConfig.params.copy(attachUltronLog = false)

Screen recording​

recordVideoPolicy records every test with the on-device screenrecord binary (started through UiAutomation.executeShellCommand, no root and no host tooling) and attaches the H.264 mp4 as video/mp4, which the Allure report plays inline. TEST_FAILURE attaches the recording in testFailure, TEST_FINISH also keeps passed tests, NONE (the default) records nothing; the OPERATION_* values have no meaning for the video, and a policy with none of TEST_FAILURE / TEST_FINISH records nothing either. TEST_FINISH is a new value of AllureAttachStrategy: an exhaustive when over the enum in your own code needs a branch for it.

What to know before enabling it:

  • screenrecord stops by itself after timeLimitSec; the binary caps it at 180 s on API < 34. A test longer than the limit gets a truncated video.
  • The recording is identified by its file name, so two instrumentation runs on one device do not stop each other's recordings.
  • Old emulator images may ship without screenrecord or with a failing encoder; the recording is then logged and skipped, the test is unaffected. --size (screenRecordOptions.size) is the usual fix for encoder failures and keeps files small.
  • Recording runs in a separate process; the test thread pays only for stopping it and copying the file (about one to three seconds per test).

Add detailed info about your conditions to report​

Ultron provides cool feature called Test condition management

With recommended config all conditions will be added to Allure report automatically. The name of rule and condition is used as Allure step name.

For example this code

    val setupRule = SetUpRule("Login user rule")
.add(name = "Login valid user $CURRENT_USER") {
AccountManager(InstrumentationRegistry.getInstrumentation().targetContext).login(
CURRENT_USER.login, CURRENT_USER.password
)
}

generate following marked steps

conditions

How to add custom artifacts to Allure report?​

Write artifact to report​

The framework has special methods to write your artifacts into report.

createCacheFile - creates temp file to write the content (see InstrumentationUtil.android.kt)\

AttachUtil.attachFile(...) - to attach file to report see AttachUtil

The mimeType param accepts Ultron MimeType value, not a raw string. For an MP4 screen recording use MimeType.VIDEO_MP4 (video/mp4, played inline by Allure; the older MimeType.MP4 is audio/mp4).

You method can looks like

fun addMyArtifactToAllure(){
val tempFile = createCacheFile()
val result = writeContentToFile(tempFile)
val fileName = AttachUtil.attachFile(
name = "file_name.xml",
file = tempFile,
mimeType = MimeType.XML
)
}

writeContentToFile(tempFile) - you should implement it.

Manage artifact creation​

You can attach artifact using 2 types of Ultron listeners:

Refer to the Listeners doc page for details.

Compose Multiplatform​

Allure reporting for Compose Multiplatform tests is the same ultron-allure module on its other targets and has its own page: Allure for Compose Multiplatform. It covers setup, where the results land on each platform (including browsers), the frame-by-frame test video, and a side-by-side table of what UltronAllureConfig offers on Android and on the Compose Multiplatform targets.

In short: on those targets the same ultron-allure artifact has no instrumentation runner and no allure-kotlin dependency, writes Allure 2 result files with Ultron's own writer, attaches a PNG of the Compose root and a semantics-tree dump instead of a view hierarchy and logcat, and encodes per-operation frames as MP4, WebM or APNG depending on the target and available encoder. Gradle picks the variant by target: an Android project gets the pipeline described on this page, a desktop, iOS, macOS, js or wasmJs test compilation gets the Compose Multiplatform one, and UltronAllureConfig is the entry point on both.