Skip to content
Aleksei Tiurin edited this page Aug 20, 2023 · 4 revisions

Ultron can generate artifacts for Allure report.

Just set Ultron testInstrumentationRunner in your app build.gradle file (example build.gradle.kts)

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

and apply recommended config in your BaseTest class (example BaseTest).

@BeforeClass @JvmStatic
fun setConfig() {
    UltronConfig.applyRecommended()
    UltronAllureConfig.applyRecommended()
}

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)
        }
    }
}

Allure for Compose

add 3 lines more to your config initialisation method

@BeforeClass @JvmStatic
fun setConfig() {
    ...
    UltronComposeConfig.applyRecommended() 
    UltronComposeConfig.addListener(ScreenshotAttachListener())
    UltronComposeConfig.addListener(WindowHierarchyAttachListener())
    UltronComposeConfig.addListener(DetailedOperationAllureListener())
}

allure compose

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
    )
}
UltronComposeConfig.apply {
    this.operationTimeoutMs = 7_000
    ...
}

Add detailed info about your conditions to report

Ultron provides cool feature called Test condition management (https://github.com/open-tool/ultron/wiki/Full-control-of-your-tests)

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.kt)\

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

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 = "text/xml"
    )
}

writeContentToFile(tempFile) - you should implement it.

Manage artifact creation

You can attach artifact using 2 types of Ultron listeners:

Refer to the Listeners wiki page for details.