-
Notifications
You must be signed in to change notification settings - Fork 12
Allure
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()
}
- 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.
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.
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)
}
}
}
add 3 lines more to your config initialisation method
@BeforeClass @JvmStatic
fun setConfig() {
...
UltronComposeConfig.applyRecommended()
UltronComposeConfig.addListener(ScreenshotAttachListener())
UltronComposeConfig.addListener(WindowHierarchyAttachListener())
UltronComposeConfig.addListener(DetailedOperationAllureListener())
}
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
...
}
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
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.
You can attach artifact using 2 types of Ultron listeners:
-
UltronLifecycleListener - once Ultron operation finished with any result. Sample - ScreenshotAttachListener.kt
-
UltronRunListener which is inherited from RunListener. This type can be used to add artifact in different test lifecycle state. Sample - WindowHierarchyAttachRunListener.kt
Refer to the Listeners wiki page for details.