Kaspresso-allure support
What's new
In the 1.3.0 Kaspresso release the allure-framework support was added. Now it is very easy to generate pretty test reports using both Kaspresso and Allure frameworks.
In this release, the file-managing classes family that is responsible for providing files for screenshots and logs has been refactored for better usage and extensibility. This change has affected the old classes that are deprecated now (see package com.kaspersky.kaspresso.files). Usage example: CustomizedSimpleTest.
Also, the following interceptors were added:
- VideoRecordingInterceptor. Tests video recording interceptor (please note that it was fully tested on emulators with android api 29 and older).
- DumpViewsInterceptor. Interceptor that dumps XML-representation of view hierarchy in case of a test failure.
In the package com.kaspersky.components.alluresupport.interceptors, there are special Kaspresso interceptors helping to link and process files for Allure-report.
How to use
First of all, add the following Gradle dependency and Allure runner to your project's gradle file to include allure-support Kaspresso module:
android {
defaultConfig {
//...
testInstrumentationRunner "com.kaspersky.kaspresso.runner.KaspressoRunner"
}
//...
}
dependencies {
//...
androidTestImplementation "com.kaspersky.android-components:kaspresso-allure-support:<latest_version>"
}
class AllureSupportTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.withForcedAllureSupport()
) {
}
class AllureSupportCustomizeTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.simple(
customize = {
videoParams = VideoParams(bitRate = 10_000_000)
screenshotParams = ScreenshotParams(quality = 1)
}
).addAllureSupport().apply {
testRunWatcherInterceptors.apply {
add(object : TestRunWatcherInterceptor {
override fun onTestFinished(testInfo: TestInfo, success: Boolean) {
viewHierarchyDumper.dumpAndApply("ViewHierarchy") { attachViewHierarchyToAllureReport() }
}
})
}
}
) {
...
}
class AllureSupportCustomizeTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.simple().apply {
stepWatcherInterceptors.addAll(
listOf(
ScreenshotStepInterceptor(screenshots),
AllureMapperStepInterceptor()
)
)
testRunWatcherInterceptors.addAll(
listOf(
DumpLogcatTestInterceptor(logcatDumper),
ScreenshotTestInterceptor(screenshots),
)
)
}
) {
...
}
Watch result
So you added the list of needed Allure-supporting interceptors to your Kaspresso configuration and launched the test. After the test finishes there will be sdcard/allure-results dir created on the device with all the files processed to be included to Allure-report.
This dir should be moved from the device to the host machine which will do generate the report.
For example, you can use adb pull command on your host for this. Let say you want to locate the data for the report at /Users/username/Desktop/allure-results, so you call:
adb pull /sdcard/allure-results /Users/username/Desktop
adb devices
List of devices attached
CLCDU18508004769 device
emulator-5554 device
adb -s emulator-5554 pull /sdcard/allure-results /Users/username/Desktop
Now, we want to generate and watch the report. The Allure server must be installed on our machine for this. To find out how to do it with all the details please follow the Allure docs.
For example to install Allure server on MacOS we can use the following command:
brew install allure
allure serve /Users/username/Desktop/allure-results
If you want to save the generated html-report to a specific dir for future use you can just call:
allure generate -o ~/kaspresso-allure-report /Users/username/Desktop/allure-results
allure open ~/kaspresso-allure-report
Details for succeeded test:
Details for failed test:
Details that you need to know
By default, Kaspresso-Allure introduces additional timeouts to assure the correctness of a Video recording as much as possible. To summarize, these timeouts increase a test execution time by 5 seconds.
You are free to change these values by customizing videoParams
in Kaspresso.Builder
. See the example above.