/
DeviceKeyboardSampleTest.kt
74 lines (64 loc) · 2.46 KB
/
DeviceKeyboardSampleTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.kaspersky.kaspressample.device_tests
import android.Manifest
import android.view.KeyEvent
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import com.kaspersky.kaspressample.device.DeviceSampleActivity
import com.kaspersky.kaspressample.screen.DeviceSampleScreen
import com.kaspersky.kaspresso.device.keyboard.Keyboard
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Rule
import org.junit.Test
class DeviceKeyboardSampleTest : TestCase() {
companion object {
const val TEXT_TO_BE_TYPED = "Kaspresso"
}
@get:Rule
val runtimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)
@get:Rule
val activityRule = activityScenarioRule<DeviceSampleActivity>()
@Test
fun keyboardSampleTest() {
run {
/**
* Consider to use [ViewActions.typeText] or [UiObject.setText] instead of [Keyboard.typeText]
*/
step("Type text using [Keyboard.typeText]") {
DeviceSampleScreen {
input {
device.keyboard.typeText(TEXT_TO_BE_TYPED)
hasText(TEXT_TO_BE_TYPED)
}
}
}
/**
* Consider to use [ViewActions.pressKey] or [UiDevice.pressKeyCode] instead of [Keyboard.sendEvent]
*/
step("Type text using [Keyboard.sendEvent]") {
DeviceSampleScreen {
input {
clearText()
}
}
// Type `kaspresso`
device.keyboard.sendEvent(KeyEvent.KEYCODE_K)
device.keyboard.sendEvent(KeyEvent.KEYCODE_A)
device.keyboard.sendEvent(KeyEvent.KEYCODE_S)
device.keyboard.sendEvent(KeyEvent.KEYCODE_P)
device.keyboard.sendEvent(KeyEvent.KEYCODE_R)
device.keyboard.sendEvent(KeyEvent.KEYCODE_E)
device.keyboard.sendEvent(KeyEvent.KEYCODE_S)
device.keyboard.sendEvent(KeyEvent.KEYCODE_S)
device.keyboard.sendEvent(KeyEvent.KEYCODE_O)
DeviceSampleScreen {
input {
hasText("kaspresso")
}
}
}
}
}
}