KasperskyLab / Kaspresso

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

Video isn't recorded if testName contains special characters and test which is actually Passed, marked as Failed in the test run #675

Open zakaz opened 1 month ago

zakaz commented 1 month ago

Describe the bug In 1.5.4 Kaspresso, with withForcedAllureSupport(), if testName contains one of these symbols: : , " , *, ?, <, >, | , / then the Runner can't create a file in Android emulator. It throws java.io.IOException: Operation not permitted exception while trying to execute method .createFileIfNeeded() from this block com.kaspersky.kaspresso.files.resources.impl.DefaultResourceFilesProvider:

override fun provideVideoFile(tag: String, subDir: String?): File {
        val resFileName: String = resourceFileNamesProvider.getFileName(
            tag,
            FileExtension.MP4.toString()
        )

        return resourcesDirsProvider.provide(resourcesRootDirsProvider.videoRootDir, subDir)
            .resolve(resFileName)
            .createFileIfNeeded()
    }

Even though, the test itself is Passed, in after section it can't stop the video recording, it shows error Can't stop video recording as it was not started

To Reproduce Steps to reproduce the behavior: To reproduce the issue, you can run the test from Kaspresso framework, from com.kaspersky.kaspresso.alluresupport.sample.AllureSupportTest class.

  1. For the test counter() add testName with any of the symbols, for example: "123: 123"
  2. Execute the test
  3. You'll see in the Logcat that the test was PASSED, but due to java.io.IOException: Operation not permitted it was marked as FAILED in the test run
  4. remove : symbol from the testName,
  5. Execute the test
  6. The test is PASSED, and in the test run it also was marked as PASSED

Expected behavior It's expected that the symbols in the testName doesn't affect to the status of the test in the test run

Desktop:

Android emulator:

Additional context

zakaz commented 1 month ago

logcat_com_kaspersky_kaspresso_alluresupport_sample_AllureSupportTest.txt

zakaz commented 1 month ago

Possible solution: in com.kaspersky.components.alluresupport.interceptors.testrun.HackyVideoRecordingTestInterceptor class in onTestStarted() method replace with:

val videoName = testInfo.testName.replace("/|:|\"|\\*|\\?|<|>|\\|".toRegex(), "_")
videos.record("Video_${videoName}")