KasperskyLab / Kaspresso

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

"No such file or dirictory" #304

Closed PaladiRka closed 3 years ago

PaladiRka commented 3 years ago

Hi, I test new possible, and go to guide, but when I did everything from "How to use" my tests failure with this error shown below . If i remove from TestCase constructor kaspressoBuilder parameter I can get success test.

java.io.IOException: No such file or directory
    at java.io.UnixFileSystem.createFileExclusively0(Native Method)
    at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
    at java.io.File.createNewFile(File.java:1008)
    at com.kaspersky.kaspresso.internal.extensions.other.FileExtKt.createFileIfNeeded(FileExt.kt:29)
    at com.kaspersky.kaspresso.files.resources.impl.DefaultResourceFilesProvider.provideVideoFile(DefaultResourceFilesProvider.kt:47)
    at com.kaspersky.kaspresso.files.resources.ResourceFilesProvider$DefaultImpls.provideVideoFile$default(ResourceFilesProvider.kt:11)
    at com.kaspersky.kaspresso.device.video.VideosImpl.record(VideosImpl.kt:15)
    at com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.video.VideoRecordingInterceptor.onTestStarted(VideoRecordingInterceptor.kt:12)
    at com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.composite.TestRunCompositeWatcherInterceptor.onTestStarted(TestRunCompositeWatcherInterceptor.kt:37)
    at com.kaspersky.kaspresso.testcases.core.TestRunner.run(TestRunner.kt:47)
    at com.kaspersky.kaspresso.testcases.core.sections.MainTestSection.run(MainTestSection.kt:29)
    at com.kaspersky.kaspresso.testcases.api.testcase.BaseTestCase.run(BaseTestCase.kt:90)
    at com.kaspersky.kaspresso.testcases.api.testcase.BaseTestCase.run$default(BaseTestCase.kt:86)
    at com.example.myawesometestingproject.MainTest.test(MainTest.kt:110)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at androidx.test.rule.GrantPermissionRule$RequestPermissionStatement.evaluate(GrantPermissionRule.java:134)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:154)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)

My test.kt:

package com.example.myawesometestingproject

import android.Manifest
import android.content.Intent
import androidx.test.core.app.ActivityScenario
import androidx.test.espresso.Espresso
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.rule.ActivityTestRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.components.alluresupport.withAllureSupport
import com.kaspersky.kaspresso.files.dirs.DefaultDirsProvider
import com.kaspersky.kaspresso.files.resources.ResourceFileNamesProvider
import com.kaspersky.kaspresso.files.resources.ResourcesDirsProvider
import com.kaspersky.kaspresso.files.resources.ResourcesRootDirsProvider
import com.kaspersky.kaspresso.files.resources.impl.DefaultResourceFilesProvider
import com.kaspersky.kaspresso.files.resources.impl.DefaultResourcesDirNameProvider
import com.kaspersky.kaspresso.files.resources.impl.DefaultResourcesDirsProvider
import com.kaspersky.kaspresso.interceptors.watcher.testcase.TestRunWatcherInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.logging.DumpLogcatInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.screenshot.TestRunnerScreenshotWatcherInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.video.VideoRecordingInterceptor
import com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.views.DumpViewsInterceptor
import com.kaspersky.kaspresso.kaspresso.Kaspresso
import com.kaspersky.kaspresso.params.ScreenshotParams
import com.kaspersky.kaspresso.params.VideoParams
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import com.kaspersky.kaspresso.testcases.models.info.TestInfo
import org.hamcrest.Matchers.not
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.io.File

@RunWith(AndroidJUnit4::class)
class MainTest : TestCase(
    kaspressoBuilder = Kaspresso.Builder.advanced(
        customize = {
            videoParams = VideoParams(bitRate = 10_000_000)
            screenshotParams = ScreenshotParams(quality = 1)

            dirsProvider = DefaultDirsProvider(InstrumentationRegistry.getInstrumentation())
            resourcesDirNameProvider = DefaultResourcesDirNameProvider()

            resourcesRootDirsProvider = object : ResourcesRootDirsProvider {
                override val logcatRootDir = File("custom_logcat")
                override val screenshotsRootDir = File("custom_screenshots")
                override val videoRootDir = File("custom_video")
                override val viewHierarchy = File("custom_view_hierarchy")
            }

            resourcesDirsProvider = object : ResourcesDirsProvider by DefaultResourcesDirsProvider(
                dirsProvider = dirsProvider,
                resourcesDirNameProvider = resourcesDirNameProvider
            ) {
                override fun provide(dest: File, subDir: String?): File =
                    dirsProvider.provideCleared(dirsProvider.provideNew(dest))
            }

            resourceFileNamesProvider = object : ResourceFileNamesProvider {
                private var counter = 0
                override fun getFileName(tag: String, fileExtension: String): String =
                    "resource#${counter++}_$tag$fileExtension"
            }

            resourceFilesProvider = DefaultResourceFilesProvider(
                resourcesRootDirsProvider,
                resourcesDirsProvider,
                resourceFileNamesProvider
            )
        }
    ).apply {
        testRunWatcherInterceptors.apply {
            clear()
            addAll(
                listOf(
                    DumpLogcatInterceptor(logcatDumper),
                    TestRunnerScreenshotWatcherInterceptor(screenshots),
                    VideoRecordingInterceptor(videos),
                    DumpViewsInterceptor(viewHierarchyDumper),
                    object : TestRunWatcherInterceptor {
                        override fun onTestFinished(testInfo: TestInfo, success: Boolean) {
                            viewHierarchyDumper.dump("ViewHierarchy")
                        }
                    }
                )
            )
        }
    }
) {

    @get:Rule
    val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE
    )

    @Test
    fun test() =
        run {
            step("Open Simple Screen") {
                ActivityScenario.launch(MainActivity::class.java)
                testLogger.i("I am testLogger")
                device.screenshots.take("Additional_screenshot")
                Espresso.onView(ViewMatchers.withId(R.id.button)).perform(click())
            }

            step("Click button_1 and check button_2") {
                Espresso.onView(ViewMatchers.withId(R.id.text))
                    .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
            }
        }

}
matzuk commented 3 years ago

Hi! Have you added testInstrumentationRunner = "io.qameta.allure.android.runners.AllureAndroidJUnitRunner" in your build.gradle?

PaladiRka commented 3 years ago

Resolved. I add testInstrumentationRunner = "io.qameta.allure.android.runners.AllureAndroidJUnitRunner" but I don't remove default testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner". After remove tests run success. It also helps to put test Instrumentation Runner "io.qameta.allure.android.runners.AllureAndroidJUnitRunner" at the end ofdefaultConfig`.