Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#618: Allow allure support test without videos #619

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.kaspersky.kaspresso.runner.listener.getUniqueListener
* If a test is executing on the JVM (with Robolectric) environment then mentioned above interceptors are not including to prevent crashes.
* Allure reports don't have any sense in non Instrumental environment.
*/
@Deprecated("This builder doesn't support storage system restrictions", ReplaceWith("Kaspresso.Builder.withForcedAllureSupport()"))
fun Kaspresso.Builder.Companion.withAllureSupport(
customize: Kaspresso.Builder.() -> Unit = {}
): Kaspresso.Builder = simple(customize).addAllureSupport()
Expand Down Expand Up @@ -62,6 +63,7 @@ fun Kaspresso.Builder.addAllureSupport(): Kaspresso.Builder = apply {
* Forces file providers needed for fixed allure support
*/
fun Kaspresso.Builder.Companion.withForcedAllureSupport(
shouldRecordVideo: Boolean = true,
customize: Kaspresso.Builder.() -> Unit = {}
): Kaspresso.Builder = simple {
if (!isAndroidRuntime) {
Expand All @@ -71,7 +73,9 @@ fun Kaspresso.Builder.Companion.withForcedAllureSupport(
val instrumentalDependencyProvider = instrumentalDependencyProviderFactory.getComponentProvider<Kaspresso>(instrumentation)
forceAllureSupportFileProviders(instrumentalDependencyProvider)
addRunListenersIfNeeded(instrumentalDependencyProvider)
}.apply(::postInitAllure)
}.apply {
postInitAllure(shouldRecordVideo, builder = this)
}

private fun Kaspresso.Builder.forceAllureSupportFileProviders(provider: InstrumentalDependencyProvider) {
resourcesDirNameProvider = DefaultResourcesDirNameProvider()
Expand Down Expand Up @@ -107,12 +111,10 @@ private fun Kaspresso.Builder.addRunListenersIfNeeded(provider: InstrumentalDepe
}
}

private fun postInitAllure(builder: Kaspresso.Builder): Unit = with(builder) {
private fun postInitAllure(shouldRecordVideo: Boolean, builder: Kaspresso.Builder): Unit = with(builder) {
if (!isAndroidRuntime) {
return@with
}
val provider = instrumentalDependencyProviderFactory.getComponentProvider<Kaspresso>(instrumentation)
val allureResourcesFilesProvider = resourceFilesProvider as AllureResourceFilesProvider
stepWatcherInterceptors.addAll(
listOf(
ScreenshotStepInterceptor(screenshots),
Expand All @@ -124,7 +126,13 @@ private fun postInitAllure(builder: Kaspresso.Builder): Unit = with(builder) {
DumpLogcatTestInterceptor(logcatDumper),
ScreenshotTestInterceptor(screenshots),
DumpViewsTestInterceptor(viewHierarchyDumper),
HackyVideoRecordingTestInterceptor(videos, allureResourcesFilesProvider, provider.runNotifier.getUniqueListener())
)
)
if (shouldRecordVideo) {
val provider = instrumentalDependencyProviderFactory.getComponentProvider<Kaspresso>(instrumentation)
val allureResourcesFilesProvider = resourceFilesProvider as AllureResourceFilesProvider
testRunWatcherInterceptors.add(
HackyVideoRecordingTestInterceptor(videos, allureResourcesFilesProvider, provider.runNotifier.getUniqueListener())
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ class AllureResultsHack(
}

override fun testRunFinished(result: Result) {
if (videosToInject.isEmpty()) {
return
}
val allureResultsInjector = AllureResultInjector(
parser = AllureResultJsonParser(),
uiDevice = uiDevice,
resultsDir = allureResultsTargetDir
)

allureResultsSourceDir.copyRecursively(allureResultsTargetDir)
allureResultsInjector.injectVideos(allureResultsTargetDir, videosToInject)
if (videosToInject.isNotEmpty()) {
allureResultsInjector.injectVideos(allureResultsTargetDir, videosToInject)
}

allureResultsSourceDir.deleteRecursively()
stubVideosDir.deleteRecursively()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.kaspersky.kaspresso.alluresupport.sample

import androidx.test.ext.junit.rules.activityScenarioRule
import com.kaspersky.components.alluresupport.withAllureSupport
import com.kaspersky.components.alluresupport.withForcedAllureSupport
import com.kaspersky.kaspresso.alluresupport.sample.screen.MainScreen
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
Expand All @@ -12,7 +13,7 @@ import org.junit.Test
* Use [withAllureSupport] function to add the all available allure interceptors.
*/
class AllureSupportTest : TestCase(
kaspressoBuilder = Kaspresso.Builder.withAllureSupport()
kaspressoBuilder = Kaspresso.Builder.withForcedAllureSupport()
) {

@get:Rule
Expand Down
Loading