Skip to content

Commit

Permalink
Test adding delay to UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasNaouchi committed Nov 1, 2023
1 parent 1a0ac96 commit 2e15d2d
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ class CreditCardActivityTest {
override fun onActivityDestroyed(activity: Activity) {}
}
private val mockClient: Client = mock()
private fun waitMilliseconds(delay: Long) {
try {
Thread.sleep(delay)
} catch (e: InterruptedException) {
// Handle the exception if needed
Thread.currentThread().interrupt()
}
}

@Before
fun setUp() {
Expand Down Expand Up @@ -121,7 +129,8 @@ class CreditCardActivityTest {
onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234"))
onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"))
onView(withId(R.id.edit_country)).perform(scrollTo(), click())

// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand Down Expand Up @@ -165,7 +174,8 @@ class CreditCardActivityTest {
onView(withId(R.id.edit_expiry_date)).perform(typeText("1234"))
onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"))
onView(withId(R.id.edit_country)).perform(scrollTo(), click())

// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand All @@ -182,7 +192,8 @@ class CreditCardActivityTest {
onView(withId(R.id.edit_expiry_date)).perform(typeText("1234"))
onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"))
onView(withId(R.id.edit_country)).perform(scrollTo(), click())

// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand All @@ -202,7 +213,8 @@ class CreditCardActivityTest {
onView(withId(R.id.edit_expiry_date)).perform(typeText("1234"))
onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"))
onView(withId(R.id.edit_country)).perform(scrollTo(), click())

// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand All @@ -222,7 +234,8 @@ class CreditCardActivityTest {
onView(withId(R.id.edit_expiry_date)).perform(typeText("1234"))
onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"))
onView(withId(R.id.edit_country)).perform(scrollTo(), click())

// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand All @@ -237,6 +250,8 @@ class CreditCardActivityTest {
@Test
fun postTalCode_canTypeAlphabet() {
onView(withId(R.id.edit_country)).perform(scrollTo(), click())
// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand All @@ -251,6 +266,8 @@ class CreditCardActivityTest {
@Test
fun postTalCode_canTypeStartWithZero() {
onView(withId(R.id.edit_country)).perform(scrollTo(), click())
// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand All @@ -265,6 +282,8 @@ class CreditCardActivityTest {
@Test
fun state_canTypeWhitespacesApostrophesPeriod() {
onView(withId(R.id.edit_country)).perform(scrollTo(), click())
// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand Down Expand Up @@ -349,6 +368,8 @@ class CreditCardActivityTest {
onView(withId(R.id.edit_expiry_date)).perform(typeNumberText("1234"))
onView(withId(R.id.edit_security_code)).perform(typeNumberText("123"), closeSoftKeyboard())
onView(withId(R.id.edit_country)).perform(scrollTo(), click())
// Add a delay before interacting with the dialog
waitMilliseconds(2000)
onView(withId(R.id.country_list))
.inRoot(isDialog())
.perform(
Expand Down

0 comments on commit 2e15d2d

Please sign in to comment.