|
| 1 | +package com.kaspersky.kaspressample |
| 2 | + |
| 3 | +import android.Manifest |
| 4 | +import androidx.test.ext.junit.rules.activityScenarioRule |
| 5 | +import androidx.test.rule.GrantPermissionRule |
| 6 | +import com.kaspersky.kaspressample.screen.MainScreen |
| 7 | +import com.kaspersky.kaspressample.screen.SimpleScreen |
| 8 | +import com.kaspersky.kaspressample.simple_tests.CheckEditScenario |
| 9 | +import com.kaspersky.kaspresso.interceptors.watcher.testcase.impl.toast.ToastStepWatcherInterceptor |
| 10 | +import com.kaspersky.kaspresso.kaspresso.Kaspresso |
| 11 | +import com.kaspersky.kaspresso.testcases.api.testcase.TestCase |
| 12 | +import org.junit.Rule |
| 13 | +import org.junit.Test |
| 14 | + |
| 15 | +/** |
| 16 | + * This test shows how to use a ToastStepWatcherInterceptor that shows a step name in a toast. The toast will appear before each step execution. |
| 17 | + * toastContentProvider parameter is a lambda that takes a [com.kaspersky.kaspresso.testcases.models.info.StepInfo] and returns a CharSequence. |
| 18 | + * You could provide your own implementation of the content provider or use one of the predefined lambdas in the [ToastStepWatcherInterceptor.ToastContentProviders] object. |
| 19 | + */ |
| 20 | +class StepToastSample : TestCase(kaspressoBuilder = Kaspresso.Builder.simple().apply { |
| 21 | + stepWatcherInterceptors.add(ToastStepWatcherInterceptor( |
| 22 | + instrumentation.targetContext, |
| 23 | + toastContentProvider = ToastStepWatcherInterceptor.ToastContentProviders.description, |
| 24 | + )) |
| 25 | +}) { |
| 26 | + |
| 27 | + @get:Rule |
| 28 | + val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant( |
| 29 | + Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| 30 | + Manifest.permission.READ_EXTERNAL_STORAGE |
| 31 | + ) |
| 32 | + |
| 33 | + @get:Rule |
| 34 | + val activityRule = activityScenarioRule<MainActivity>() |
| 35 | + |
| 36 | + @Test |
| 37 | + fun test() = run { |
| 38 | + step("Open Simple Screen") { |
| 39 | + device.screenshots.take("Additional_screenshot") |
| 40 | + MainScreen { |
| 41 | + simpleButton { |
| 42 | + isVisible() |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + step("Sub-step") { |
| 47 | + MainScreen { |
| 48 | + simpleButton { |
| 49 | + click() |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + step("Click button_1 and check button_2") { |
| 56 | + SimpleScreen { |
| 57 | + button1 { |
| 58 | + click() |
| 59 | + } |
| 60 | + button2 { |
| 61 | + isVisible() |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + step("Click button_2 and check edit") { |
| 67 | + SimpleScreen { |
| 68 | + button2 { |
| 69 | + click() |
| 70 | + } |
| 71 | + edit { |
| 72 | + flakySafely(timeoutMs = 7000) { isVisible() } |
| 73 | + hasText(R.string.simple_fragment_text_edittext) |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + step("Check all possibilities of edit") { |
| 79 | + scenario( |
| 80 | + CheckEditScenario() |
| 81 | + ) |
| 82 | + } |
| 83 | + } |
| 84 | +} |
0 commit comments