KasperskyLab / Kaspresso

Android UI test framework
https://kasperskylab.github.io/Kaspresso/
Apache License 2.0
1.81k stars 153 forks source link

Provide a better way to tweak the default Kasspresso.Builder #49

Closed aartikov closed 4 years ago

aartikov commented 5 years ago

It is hard to change something in the default Kaspresso.Builder without breaking of consistency. For example, to change a screenshots directory this code is required:

 fun Kaspresso.Builder.changeScreenshotsDir(screenshotDir: File) {
    screenshots = ScreenshotsImpl(libLogger, activities, screenshotDir)

    stepWatcherInterceptors.replaceAll {
        if (it is ScreenshotStepWatcherInterceptor) {
            ScreenshotStepWatcherInterceptor(screenshots)
        } else {
            it
        }
    }

    testRunWatcherInterceptors.replaceAll {
        if (it is TestRunnerScreenshotWatcherInterceptor) {
            TestRunnerScreenshotWatcherInterceptor(screenshots)
        } else {
            it
        }
    }
}

Without calls of replaceAll interceptors will use old screenshots implementation.

Can this api be more convenient?

matzuk commented 5 years ago

Yes, it's true. But I have some draft ideas about how to fix it. The outcome will be like:

class KaspressoConfiguringTest : TestCase(
    kaspressoBuilder = Kaspresso.Builder().apply {
        screenshots = ScreenshotsImpl(libLogger, activities)
    }.default()
) {

Is it ok?

aartikov commented 5 years ago

@matzuk Yes, it looks fine.