-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestGeneratedWithAssistant.kt
188 lines (172 loc) · 6.11 KB
/
TestGeneratedWithAssistant.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package com.barryzeha.couponsapp.mainModule.view
import android.view.View
import android.view.ViewGroup
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.barryzeha.couponsapp.R
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/*
* Esta clase de testing fue generada con el asistente pata test de android
* desde el menu. Build -> Record Expresso Test
* */
@LargeTest
@RunWith(AndroidJUnit4::class)
class TestGeneratedWithAssistant {
@Rule
@JvmField
var mActivityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
@Test
fun testGeneratedWithAssistant() {
// Added a sleep statement to match the app's execution delay.
// The recommended way to handle such scenarios is to use Espresso idling resources:
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
Thread.sleep(500)
val textInputEditText = onView(
allOf(
withId(R.id.edtConsult), withContentDescription("Consultar cupón"),
childAtPosition(
childAtPosition(
withId(R.id.tilConsult),
0
),
0
),
isDisplayed()
)
)
textInputEditText.perform(click())
val textInputEditText2 = onView(
allOf(
withId(R.id.edtConsult), withContentDescription("Consultar cupón"),
childAtPosition(
childAtPosition(
withId(R.id.tilConsult),
0
),
0
),
isDisplayed()
)
)
textInputEditText2.perform(replaceText("Test01"), closeSoftKeyboard())
val materialButton = onView(
allOf(
withId(R.id.btnConsult), withText("Consultar"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0
),
2
),
isDisplayed()
)
)
materialButton.perform(click())
val textInputEditText3 = onView(
allOf(
withId(R.id.edtConsult),
withText("Test01"),
withContentDescription("Consultar cupón"),
childAtPosition(
childAtPosition(
withId(R.id.tilConsult),
0
),
0
),
isDisplayed()
)
)
textInputEditText3.perform(click())
val textInputEditText4 = onView(
allOf(
withId(R.id.edtConsult),
withText("Test01"),
withContentDescription("Consultar cupón"),
childAtPosition(
childAtPosition(
withId(R.id.tilConsult),
0
),
0
),
isDisplayed()
)
)
textInputEditText4.perform(replaceText("Cupon18"))//cambiar cada vez que se requiera probar con un nuevo cupón a guardar
val textInputEditText5 = onView(
allOf(
withId(R.id.edtConsult),
withText("Cupon18"),//cambiar el valor de la cadena para que sea igual al de la parte superior
withContentDescription("Consultar cupón"),
childAtPosition(
childAtPosition(
withId(R.id.tilConsult),
0
),
0
),
isDisplayed()
)
)
textInputEditText5.perform(closeSoftKeyboard())
val textInputEditText6 = onView(
allOf(
withId(R.id.edtDescription), withContentDescription("descripción"),
childAtPosition(
childAtPosition(
withId(R.id.tilDescription),
0
),
0
),
isDisplayed()
)
)
textInputEditText6.perform(replaceText("Cupón test asistente"), closeSoftKeyboard())
val materialButton2 = onView(
allOf(
withId(R.id.btnCreate), withText("Crear"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0
),
3
),
isDisplayed()
)
)
materialButton2.perform(click())
//comprobamos que el mensaje de cupón guardado sea el devuelto
val msgSnackbar = onView(withId(com.google.android.material.R.id.snackbar_text))
msgSnackbar.check(matches(withText(R.string.save_coupon_msg)))
}
private fun childAtPosition(
parentMatcher: Matcher<View>, position: Int
): Matcher<View> {
return object : TypeSafeMatcher<View>() {
override fun describeTo(description: Description) {
description.appendText("Child at position $position in parent ")
parentMatcher.describeTo(description)
}
public override fun matchesSafely(view: View): Boolean {
val parent = view.parent
return parent is ViewGroup && parentMatcher.matches(parent)
&& view == parent.getChildAt(position)
}
}
}
}