Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added automation for Digital Invoice Screen #565

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.hasChildCount
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand All @@ -15,7 +14,6 @@ import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.`is`
import org.junit.Assert.assertNotEquals

class DigitalInvoiceScreen {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
Expand Down Expand Up @@ -49,7 +47,7 @@ class DigitalInvoiceScreen {
.className("android.widget.Button")
.text("Get Started")
)
if (onboardingScreenButton.isClickable && onboardingScreenButton.exists()) {
if (onboardingScreenButton.isClickable() && onboardingScreenButton.exists()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onboardingScreenButton.click()
}
}
Expand All @@ -60,14 +58,20 @@ class DigitalInvoiceScreen {
.className("android.widget.ImageButton")
.descriptionContains("Close")
)
if(cancelButton.isClickable() && cancelButton.exists()){
if(cancelButton.exists() && cancelButton.isClickable()){
cancelButton.click()
}
}

fun assertOtherChargesDisplayed() {
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_addon_other_charges)).check(
matches(isDisplayed()))
fun assertOtherChargesDisplayed() : Boolean {
var isOtherChargesDisplayed = false
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_addon_other_charges))
.check { view, noViewFoundException ->
if (noViewFoundException == null || view.isShown()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isOtherChargesDisplayed = true
}
}
return isOtherChargesDisplayed
}

fun clickProceedButton() {
Expand All @@ -87,16 +91,23 @@ class DigitalInvoiceScreen {
return this
}

fun checkForReturnReasonsList() {
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_return_reason_dialog_title)).check(
matches(isDisplayed()))
fun checkForReturnReasonsList(): Boolean {
var isReturnReasonDisplayed = false
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_return_reason_dialog_title))
.check { view, noViewFoundException ->
if (noViewFoundException == null || view.isShown()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isReturnReasonDisplayed = true
}
}
return isReturnReasonDisplayed
}

fun checkItemCountOnReturnReasonsList() {
fun checkItemCountOnReturnReasonsList(): Int{
val uiCollection =
UiCollection(UiSelector().className("android.widget.ListView"))
val itemSize = uiCollection.childCount
onView(withClassName(`is`("android.widget.ListView"))).check(matches(hasChildCount(itemSize)))
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
return itemSize
}

fun clickItemOnReturnReasonsList() {
Expand Down Expand Up @@ -134,55 +145,88 @@ class DigitalInvoiceScreen {
}
}

fun verifyHelpTextOnNextScreen() {
fun verifyHelpTextOnNextScreen(): Boolean {
val helpText = device.findObject(
UiSelector()
.className("android.widget.TextView")
.text("Help")
)
helpText.exists()
return helpText.exists()
}

fun verifyFirstTitleOnHelpScreen() {
fun verifyFirstTitleOnHelpScreen(): Boolean {
var isFirstTitleDisplayed = false
onView(
allOf(withId(net.gini.android.bank.sdk.R.id.gbs_help_title),
withText("1. How does a digital invoice work?")
)
)
.check(matches(isDisplayed()))
.check { view, noViewFoundException ->
if (noViewFoundException == null || view.isShown()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isFirstTitleDisplayed = true
}
}
return isFirstTitleDisplayed
}

fun checkTotalTitleIsDisplayed() {
fun checkTotalTitleIsDisplayed(): Boolean {
var isTotalTitleDisplayed = false
onView(
allOf(withId(net.gini.android.bank.sdk.R.id.total_label),
withText("Total")
)
)
.check(matches(isDisplayed()))
.check { view, noViewFoundException ->
if (noViewFoundException == null || view.isShown()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isTotalTitleDisplayed = true
}
}
return isTotalTitleDisplayed
}

fun checkTotalPriceIsDisplayed() {
onView(withId(net.gini.android.bank.sdk.R.id.gross_price_total_integral_part))
.check(matches(isDisplayed()))
fun checkTotalPriceIsDisplayed() : Boolean{
var isTotalPriceDisplayed = false
onView((withId(net.gini.android.bank.sdk.R.id.gross_price_total_integral_part)))
.check { view, noViewFoundException ->
if (noViewFoundException == null || view.isShown()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isTotalPriceDisplayed = true
}
}
return isTotalPriceDisplayed
}

fun checkInitialPrice() {
fun storeInitialPrice() {
onView(withId(net.gini.android.bank.sdk.R.id.gross_price_total_integral_part))
.check { view, _ ->
val totalTextView = view as TextView
initialValue = totalTextView.text.toString()
}
}

fun checkUpdatedPrice() {
fun verifyTotalSumValue(): Boolean{
var isSumDifferent = false
if(initialValue!=updatedValue) {
isSumDifferent = true
}
return isSumDifferent
// assertNotEquals("Price should have changed after toggling", initialValue, updatedValue)
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
//
// onView(withId(net.gini.android.bank.sdk.R.id.gross_price_total_integral_part))
// .check { view, _ ->
// val totalTextView = view as TextView
// val totalSum = totalTextView.text.toString().toInt()
// if(sum==totalSum){
// isTotalSumDisplayed = true
// }
// }
// return isTotalSumDisplayed
}

fun storeUpdatedPrice() {
onView(withId(net.gini.android.bank.sdk.R.id.gross_price_total_integral_part))
.check { view, _ ->
val totalTextView = view as TextView
updatedValue = totalTextView.text.toString()
}
}

fun assertPriceHasChanged() {
assertNotEquals("Price should have changed after toggling", initialValue, updatedValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ 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.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.withHint
import androidx.test.espresso.matcher.ViewMatchers.withId
import net.gini.android.bank.sdk.exampleapp.R
Expand All @@ -23,8 +21,13 @@ class ExtractionScreen {
.perform(replaceText(value))
}

fun checkTransferSummaryButtonIsClickable(): ExtractionScreen {
onView(withId(R.id.transfer_summary)).check(matches(isClickable()))
return this
fun checkTransferSummaryButtonIsClickable(): Boolean {
var isTransferSummaryButtonClickable = false
onView(withId(R.id.transfer_summary)) .check { view, noViewFoundException ->
if (noViewFoundException == null || view.isClickable()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isTransferSummaryButtonClickable = true
}
}
return isTransferSummaryButtonClickable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import net.gini.android.bank.sdk.exampleapp.R
import androidx.test.espresso.assertion.ViewAssertions.matches

class MainScreen {
fun assertDescriptionTitle(): MainScreen {
onView(withId(R.id.tv_exampleOfPhotoPayment)).check(matches(isDisplayed()))
return this
fun assertDescriptionTitle(): Boolean {
var isDescriptionTitleDisplayed = false
onView(withId(R.id.tv_exampleOfPhotoPayment))
.check { view, noViewFoundException ->
if (noViewFoundException == null || view.isShown()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
isDescriptionTitleDisplayed = true
}
}
return isDescriptionTitleDisplayed
}

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

fun clickSettingButton(): MainScreen {
fun clickSettingButton() {
onView(withId(R.id.text_giniBankVersion)).perform(click())
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import net.gini.android.bank.sdk.exampleapp.ui.screens.ExtractionScreen
import net.gini.android.bank.sdk.exampleapp.ui.screens.MainScreen
import net.gini.android.bank.sdk.exampleapp.ui.screens.OnboardingScreen
import org.junit.Assert.assertEquals
import org.junit.Assert.assertSame
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -41,7 +42,7 @@ class DigitalInvoiceScreenTests {

@Before
fun setup() {
idlingResource = SimpleIdlingResource(7000)
idlingResource = SimpleIdlingResource(10000)
IdlingRegistry.getInstance().register(idlingResource)
}

Expand All @@ -53,8 +54,10 @@ class DigitalInvoiceScreenTests {
captureScreen.clickFiles()
pdfUploader.uploadPdfFromFiles("Testrechnung-RA-1.pdf")
idlingResource.waitForIdle()
digitalInvoiceScreen.checkDigitalInvoiceTextOnOnboardingScreenIsDisplayed()
digitalInvoiceScreen.checkDigitalInvoiceButtonOnOnboardingScreenIsDisplayed()
val isOnboardingScreenTextVisible = digitalInvoiceScreen.checkDigitalInvoiceTextOnOnboardingScreenIsDisplayed()
assertEquals(true, isOnboardingScreenTextVisible)
val isOnboardingScreenButtonVisible = digitalInvoiceScreen.checkDigitalInvoiceButtonOnOnboardingScreenIsDisplayed()
assertEquals(true, isOnboardingScreenButtonVisible)
}

@Test
Expand Down Expand Up @@ -90,13 +93,18 @@ class DigitalInvoiceScreenTests {
digitalInvoiceScreen.clickGetStartedButtonOnOnboardingScreen()
idlingResource.waitForIdle()
digitalInvoiceScreen.clickArticleSwitch()
digitalInvoiceScreen.checkForReturnReasonsList()
idlingResource.waitForIdle()
val isDisplayed = digitalInvoiceScreen.checkForReturnReasonsList()
idlingResource.waitForIdle()
assertEquals(true, isDisplayed)
}

@Test
fun test4_verifyCountOnReturnReasonsList() {
test3_returnReasonDisplaysWhenToggleSwitchIsDisabled()
digitalInvoiceScreen.checkItemCountOnReturnReasonsList()
val totalItemsOnReturnReason = 7
val itemSize = digitalInvoiceScreen.checkItemCountOnReturnReasonsList()
assertEquals(totalItemsOnReturnReason, itemSize)
}

@Test
Expand All @@ -121,14 +129,24 @@ class DigitalInvoiceScreenTests {
fun test7_differenceInTotalAmountWithSwitchEnabledOrDisabled() {
test5_checkItemOnListIsDisabledAfterClickItemOnReturnReasonsList()
idlingResource.waitForIdle()
digitalInvoiceScreen.checkTotalTitleIsDisplayed()
digitalInvoiceScreen.checkTotalPriceIsDisplayed()
digitalInvoiceScreen.checkInitialPrice()

val isTotalTitleVisible = digitalInvoiceScreen.checkTotalTitleIsDisplayed()
assertEquals(true, isTotalTitleVisible)

val isTotalPriceVisible = digitalInvoiceScreen.checkTotalPriceIsDisplayed()
assertEquals(true, isTotalPriceVisible)

digitalInvoiceScreen.storeInitialPrice()
val hasTotalSumDistinct = digitalInvoiceScreen.verifyTotalSumValue()
assertEquals(true, hasTotalSumDistinct)

digitalInvoiceScreen.clickArticleSwitch()
idlingResource.waitForIdle()
digitalInvoiceScreen.checkTotalPriceIsDisplayed()
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
digitalInvoiceScreen.checkUpdatedPrice()
digitalInvoiceScreen.assertPriceHasChanged()

digitalInvoiceScreen.storeUpdatedPrice()
val hasTotalSumChanged = digitalInvoiceScreen.verifyTotalSumValue()
assertEquals(true, hasTotalSumChanged)
idlingResource.waitForIdle()
}

Expand All @@ -143,7 +161,9 @@ class DigitalInvoiceScreenTests {
digitalInvoiceScreen.checkDigitalInvoiceButtonOnOnboardingScreenIsDisplayed()
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
digitalInvoiceScreen.clickGetStartedButtonOnOnboardingScreen()
idlingResource.waitForIdle()
digitalInvoiceScreen.assertOtherChargesDisplayed()
val isDisplayed = digitalInvoiceScreen.assertOtherChargesDisplayed()
idlingResource.waitForIdle()
assertEquals(true, isDisplayed)
}

@Test
Expand All @@ -158,7 +178,8 @@ class DigitalInvoiceScreenTests {
digitalInvoiceScreen.clickGetStartedButtonOnOnboardingScreen()
idlingResource.waitForIdle()
digitalInvoiceScreen.clickProceedButton()
extractionScreen.checkTransferSummaryButtonIsClickable()
val isTransferSummaryButtonVisible = extractionScreen.checkTransferSummaryButtonIsClickable()
assertEquals(true, isTransferSummaryButtonVisible)
}

@Test
Expand All @@ -173,8 +194,11 @@ class DigitalInvoiceScreenTests {
digitalInvoiceScreen.clickGetStartedButtonOnOnboardingScreen()
idlingResource.waitForIdle()
digitalInvoiceScreen.clickHelpButtonOnDigitalInvoiceScreen()
digitalInvoiceScreen.verifyHelpTextOnNextScreen()
digitalInvoiceScreen.verifyFirstTitleOnHelpScreen()
val isHelpTextVisible = digitalInvoiceScreen.verifyHelpTextOnNextScreen()
assertEquals(true, isHelpTextVisible)

val isFirstTitleTextVisible = digitalInvoiceScreen.verifyFirstTitleOnHelpScreen()
assertEquals(true, isFirstTitleTextVisible)
}

@Test
Expand All @@ -189,6 +213,7 @@ class DigitalInvoiceScreenTests {
digitalInvoiceScreen.clickGetStartedButtonOnOnboardingScreen()
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
idlingResource.waitForIdle()
digitalInvoiceScreen.clickCancelButton()
mainScreen.assertDescriptionTitle()
val isDescriptionTitleVisible = mainScreen.assertDescriptionTitle()
assertEquals(true, isDescriptionTitleVisible)
}
}
Loading