Skip to main content

Allure

Ultron can generate artifacts for Allure report only for Android UI tests.

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

Custom results directory

Ultron allows you to specify the directory where the Allure results will be stored. By default, the results are stored in the <app_directory>/files/allure-results directory in the root of the project. You can change this directory by calling UltronAllureConfig.setAllureResultsDirectory()

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

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

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.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 doc page for details.