Skip to content

Commit

Permalink
ci(bank-sdk): Introduce new test and resource classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SyedaGini committed Jul 11, 2024
1 parent 6b8fcc6 commit d2ffcb8
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 89 deletions.
1 change: 1 addition & 0 deletions bank-sdk/example-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ android {

// Use the test runner with JUnit4 support
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["clearPackageData"] = "true"

multiDexEnabled = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.gini.android.bank.sdk.exampleapp.ui.resources
import androidx.test.espresso.IdlingResource

class SimpleIdlingResource(private val waitTime: Long) : IdlingResource {

@Volatile
private var isIdleNow = true
private var callback: IdlingResource.ResourceCallback? = null

override fun getName() = SimpleIdlingResource::class.java.name

override fun isIdleNow() = isIdleNow

override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback) {
this.callback = callback
}

fun setIdleState(isIdleNow: Boolean) {
this.isIdleNow = isIdleNow
if (isIdleNow && callback != null) {
callback!!.onTransitionToIdle()
}
}

fun waitForIdle() {
isIdleNow = false
Thread {
try {
Thread.sleep(waitTime)
} catch (e: InterruptedException) {
e.printStackTrace()
}
setIdleState(true)
}.start()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ class HelpScreen {
isDescendantOfA(withId(net.gini.android.capture.R.id.gc_help_items))
)
)
.check(matches(withText("Tips for best results from photos")))
.perform(click());
return this
}

fun assertTipsForBestResultsExists(): HelpScreen {
onView(
allOf(
withId(net.gini.android.capture.R.id.gc_help_item_title),
withText("Tips for best results from photos"),
isDescendantOfA(withId(net.gini.android.capture.R.id.gc_help_items))
)
)
.check(matches(withText("Tips for best results from photos")))
return this
}

fun clickSupportedFormats(): HelpScreen {
onView(
allOf(
Expand All @@ -31,11 +42,22 @@ class HelpScreen {
isDescendantOfA(withId(net.gini.android.capture.R.id.gc_help_items))
)
)
.check(matches(withText("Supported formats")))
.perform(click());
return this
}

fun assertSupportedFormatsExists(): HelpScreen {
onView(
allOf(
withId(net.gini.android.capture.R.id.gc_help_item_title),
withText("Supported formats"),
isDescendantOfA(withId(net.gini.android.capture.R.id.gc_help_items))
)
)
.check(matches(withText("Supported formats")))
return this
}

fun clickImportDocs(): HelpScreen {
onView(
allOf(
Expand All @@ -44,13 +66,26 @@ class HelpScreen {
isDescendantOfA(withId(net.gini.android.capture.R.id.gc_help_items))
)
)
.check(matches(withText("Import documents from other apps")))
.perform(click());
return this
}

fun assertImportDocsExists(): HelpScreen {
onView(
allOf(
withId(net.gini.android.capture.R.id.gc_help_item_title),
withText("Import documents from other apps"),
isDescendantOfA(withId(net.gini.android.capture.R.id.gc_help_items))
)
)
.check(matches(withText("Import documents from other apps")))
return this
}

fun clickBackButton(): HelpScreen {
onView(withContentDescription(net.gini.android.capture.R.string.gc_back_button_description)).perform(click())
onView(withContentDescription(net.gini.android.capture.R.string.gc_back_button_description)).perform(
click()
)
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,17 @@ package net.gini.android.bank.sdk.exampleapp.ui.screens

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import net.gini.android.bank.sdk.exampleapp.R
import androidx.test.espresso.assertion.ViewAssertions.matches

class MainScreen {

fun checkWelcomeTitleIsDisplayed(): MainScreen {
onView(withId(R.id.tv_welcomeToGini)).check(matches(isDisplayed()))
return this
}

fun assertDescriptionTitle(): MainScreen {
onView(withId(R.id.tv_exampleOfPhotoPayment)).check(matches(isDisplayed()))
return this
}

fun checkCheckIconDisplayed(): MainScreen {
onView(withId(R.id.til_fieldEntryPoint)).check(matches(isDisplayed()))
return this
}

fun clickCameraIcon(): MainScreen {
onView(withId(R.id.til_fieldEntryPoint)).perform(click())
return this
}

fun checkScannerButtonDisplayed(): MainScreen {
onView(withId(R.id.button_startScanner)).check(matches(isDisplayed()))
return this
}

fun clickPhotoPaymentButton(): MainScreen {
onView(withId(R.id.button_startScanner)).perform(click())
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import org.hamcrest.CoreMatchers.allOf

class OnboardingScreen {
fun checkOnboardingScreenTitle(onboardingTitle: String): OnboardingScreen {
onView(
allOf(
withId(net.gini.android.capture.R.id.gc_title), withText(onboardingTitle)
)
).check(matches(isDisplayed()))
return this
}

fun checkNextButtonText(): OnboardingScreen {
onView(withId(net.gini.android.capture.R.id.gc_next)).check(matches(withText("Next")))
return this
}

fun assertSkipButtonText(): OnboardingScreen {
fun clickNextButton(): OnboardingScreen {
onView(withId(net.gini.android.capture.R.id.gc_next)).check(matches(isDisplayed()))
.check(matches(isClickable())).perform(click())
return this
}

fun checkSkipButtonText(): OnboardingScreen {
onView(withId(net.gini.android.capture.R.id.gc_skip)).check(matches(withText("Skip")))
return this
}
Expand All @@ -17,4 +39,9 @@ class OnboardingScreen {
onView(withId(net.gini.android.capture.R.id.gc_skip)).perform(click())
return this
}

fun checkGetStartedButton(): OnboardingScreen {
onView(withId(net.gini.android.capture.R.id.gc_get_started)).check(matches(withText("Get Started")))
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package net.gini.android.bank.sdk.exampleapp.ui.testcases

import android.Manifest
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.rule.GrantPermissionRule
import net.gini.android.bank.sdk.exampleapp.ui.MainActivity
import net.gini.android.bank.sdk.exampleapp.ui.screens.CaptureScreen
import net.gini.android.bank.sdk.exampleapp.ui.screens.HelpScreen
import net.gini.android.bank.sdk.exampleapp.ui.screens.MainScreen
import net.gini.android.bank.sdk.exampleapp.ui.screens.OnboardingScreen
import org.junit.Rule
import org.junit.Test

/**
* Test class for help screen flow.
*
* Jira link for test case: [https://ginis.atlassian.net/browse/PM-23](https://ginis.atlassian.net/browse/PM-23)
*/
class HelpScreenTests {

@get:Rule
val activityRule = activityScenarioRule<MainActivity>()

@get: Rule
val grantPermissionRule: GrantPermissionRule =
GrantPermissionRule.grant(Manifest.permission.CAMERA)

private val mainScreen = MainScreen()
private val onboardingScreen = OnboardingScreen()
private val captureScreen = CaptureScreen()
private val helpScreen = HelpScreen()

@Test
fun test2_verifyHelpItemTipsForBestResult() {
mainScreen.clickPhotoPaymentButton()
onboardingScreen.clickSkipButton()
captureScreen.clickHelpButton()
helpScreen.assertTipsForBestResultsExists()
helpScreen.clickTipsForBestResults()
helpScreen.clickBackButton()
}

@Test
fun test3_verifyHelpItemSupportedFormats() {
mainScreen.clickPhotoPaymentButton()
onboardingScreen.clickSkipButton()
captureScreen.clickHelpButton()
helpScreen.assertSupportedFormatsExists()
helpScreen.clickSupportedFormats()
helpScreen.clickBackButton()
}

@Test
fun test4_verifyHelpItemImportDocuments() {
mainScreen.clickPhotoPaymentButton()
onboardingScreen.clickSkipButton()
captureScreen.clickHelpButton()
helpScreen.assertImportDocsExists()
helpScreen.clickImportDocs()
helpScreen.clickBackButton()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasType
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.rule.GrantPermissionRule
import net.gini.android.bank.sdk.exampleapp.ui.MainActivity
import net.gini.android.bank.sdk.exampleapp.ui.screens.CaptureScreen
Expand All @@ -21,17 +20,13 @@ import net.gini.android.bank.sdk.exampleapp.ui.screens.OnboardingScreen
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.FixMethodOrder
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters


@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@RunWith(AndroidJUnit4::class)
@LargeTest
class MainActivityTest {
class MainScreenTests {

@get: Rule
val activityRule = ActivityScenarioRule(MainActivity::class.java)
Expand All @@ -41,62 +36,14 @@ class MainActivityTest {
GrantPermissionRule.grant(Manifest.permission.CAMERA)

private val mainScreen = MainScreen()
private val onboardingScreen = OnboardingScreen()
private val captureScreen = CaptureScreen()
private val helpScreen = HelpScreen()

@Before
fun setUp() {
Intents.init()
}
@Test
fun test1_assertTitlesOnMainScreen() {
mainScreen.checkWelcomeTitleIsDisplayed()
mainScreen.assertDescriptionTitle()
}
@Test
fun test2_clickPhotoPaymentButton() {
mainScreen.checkScannerButtonDisplayed()
mainScreen.clickPhotoPaymentButton()
onboardingScreen.assertSkipButtonText()
onboardingScreen.clickSkipButton()
captureScreen.assertCameraTitle()
captureScreen.clickCancelButton()
}

@Test
fun test3_clickHelpButton() {
mainScreen.clickPhotoPaymentButton()
captureScreen.clickHelpButton()
}

@Test
fun test4_verifyHelpItemTipsForBestResult() {
mainScreen.clickPhotoPaymentButton()
captureScreen.clickHelpButton()
helpScreen.clickTipsForBestResults()
helpScreen.clickBackButton()
}

@Test
fun test5_verifyHelpItemSupportedFormats() {
mainScreen.clickPhotoPaymentButton()
captureScreen.clickHelpButton()
helpScreen.clickSupportedFormats()
helpScreen.clickBackButton()
}

@Test
fun test6_verifyHelpItemImportDocuments() {
mainScreen.clickPhotoPaymentButton()
captureScreen.clickHelpButton()
helpScreen.clickImportDocs()
helpScreen.clickBackButton()
}


@Test
fun test7_pdfImportFromFiles() {
fun test1_pdfImportFromFiles() {
mainScreen.clickPhotoPaymentButton()
val resultData = Intent()
val fileUri =
Expand All @@ -110,8 +57,4 @@ class MainActivityTest {
)
).respondWith(result)
}

@After
fun tearDown() {
}
}
Loading

0 comments on commit d2ffcb8

Please sign in to comment.