简体   繁体   中英

composeTestRule not work in Scenario() in kaspresso

I'm trying to write Scenario() with composeTestRule in Kaspresso, but I get an error:

Test not setup properly. Use a ComposeTestRule in your test to be able to interact with composables

My scenario for example:

class FillOtp(
) : Scenario() {

    override val steps: TestContext<Unit>.() -> Unit = {

        val baseTest = BaseTest()

        step("Write 0000") {
                baseTest.composeTestRule
                    .onNodeWithTag("test")
                    .performClick()
                MyScreen {
                    pinEdit {
                        typeText("0000")
                    }
                    continueBtn.click()
                }
            }
        }

    }
}

But I have added composeTestRule in BaseTest() class. And composeTestRule works successfully in tests without Scenario()

could you help me solve the problem?

On another site I was offered the answer:

You can pass it to the constructor from the test:

class MyScenario(semanticsProvider: SemanticsNodeInteractionsProvider) : Scenario() {
 override val steps: TestContext<Unit>.() -> Unit = {
  semanticsProvider.onNode(...)
 }
}

And in test:

scenario(MyScenario(composeTestRule))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM