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 2 commits
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 @@ -6,7 +6,7 @@ import androidx.test.uiautomator.UiSelector

class PdfUploader {
private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun uploadPdfFromFiles() {
fun uploadPdfFromFiles(file: String) {
device.waitForIdle()
val tabTitle = device.findObject(UiSelector().className("android.widget.TextView").text("Recent"))
if (tabTitle.exists()) {
Expand All @@ -23,12 +23,12 @@ class PdfUploader {
downloadsOption.click()

//Select desired pdf file
val selectPdfFile = device.findObject(UiSelector().text("sample.pdf"))
val selectPdfFile = device.findObject(UiSelector().text(file))
selectPdfFile.click()
}
else {
//Select desired pdf file
val selectPdfFile = device.findObject(UiSelector().text("sample.pdf"))
val selectPdfFile = device.findObject(UiSelector().text(file))
selectPdfFile.click()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ class ConfigurationScreen {
return this
}

fun clickFlashToggleToEnable(): ConfigurationScreen {
onView(ViewMatchers.withId(R.id.switch_flashOnByDefault)).perform(closeSoftKeyboard(), click())
return this
fun clickFlashToggleToEnable() {
onView(ViewMatchers.withId(R.id.switch_flashOnByDefault)).perform(
closeSoftKeyboard(),
click()
)
}

fun assertFlashToggleIsDisable(): ConfigurationScreen {
onView(ViewMatchers.withId(R.id.switch_flashOnByDefault)).check(matches(isDisplayed()))
return this
}

fun scrollToUICustomizationText(): ConfigurationScreen {
onView(withText("UI customization"))
.perform(scrollTo())
return this
}

fun clickReturnReasonsDialogToEnable(): ConfigurationScreen {
onView(ViewMatchers.withId(R.id.switch_returnReasonsDialog)).perform(click()
)
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package net.gini.android.bank.sdk.exampleapp.ui.screens

import android.widget.TextView
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
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiCollection
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())
private var initialValue: String? = null
private var updatedValue: String? = null


fun checkDigitalInvoiceTextOnOnboardingScreenIsDisplayed(): Boolean {
val onboardingScreenText = device.findObject(
UiSelector()
.className("android.widget.TextView")
.text("Digital invoice")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/onboarding_text_1")
)
return onboardingScreenText.exists()
}

fun checkDigitalInvoiceButtonOnOnboardingScreenIsDisplayed(): Boolean {
val onboardingScreenButton = device.findObject(
UiSelector()
.className("android.widget.Button")
.text("Get Started")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/done_button")
)
return onboardingScreenButton.exists()
}

fun clickGetStartedButtonOnOnboardingScreen() {
val onboardingScreenButton = device.findObject(
UiSelector()
.className("android.widget.Button")
.text("Get Started")
)
if (onboardingScreenButton.isClickable && onboardingScreenButton.exists()) {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onboardingScreenButton.click()
}
}

fun clickCancelButton() {
val cancelButton = device.findObject(
UiSelector()
.className("android.widget.ImageButton")
.descriptionContains("Close")
)
if(cancelButton.isClickable() && cancelButton.exists()){
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
cancelButton.click()
}
}

fun assertOtherChargesDisplayed() {
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_addon_other_charges)).check(
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
matches(isDisplayed()))
}

fun clickProceedButton() {
onView(withText(net.gini.android.bank.sdk.R.string.gbs_proceed)).perform(click())
}

fun clickArticleSwitch(): DigitalInvoiceScreen {
val articleSwitch = device.findObject(
UiSelector()
.className("android.widget.Switch")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/gbs_enable_switch")
.index(1)
)
if(articleSwitch.exists() && articleSwitch.isClickable){
articleSwitch.click()
}
return this
}

fun checkForReturnReasonsList() {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_return_reason_dialog_title)).check(
matches(isDisplayed()))
}

fun checkItemCountOnReturnReasonsList() {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
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
}

fun clickItemOnReturnReasonsList() {
val uiCollection =
UiCollection(UiSelector().className("android.widget.ListView"))
val returnReasonsItems = uiCollection.getChildByInstance(
UiSelector().className("android.widget.TextView"), 0)
returnReasonsItems.click()
}

fun checkItemIsDisabledFromDigitalScreen(): Boolean {
val returnReasonsItems = device.findObject(UiSelector()
.className("android.view.ViewGroup")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/gsb_line_item")
.index(0))
return !(returnReasonsItems.isEnabled)
}

fun checkItemIsEnabledFromDigitalScreen(): Boolean {
val returnReasonsItems = device.findObject(UiSelector()
.className("android.view.ViewGroup")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/gsb_line_item")
.index(0))
return returnReasonsItems.isEnabled
}

fun clickHelpButtonOnDigitalInvoiceScreen() {
val helpButton = device.findObject(
UiSelector()
.className("android.widget.Button")
.descriptionContains("Help")
)
if(helpButton.exists()){
helpButton.click()
}
}

fun verifyHelpTextOnNextScreen() {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
val helpText = device.findObject(
UiSelector()
.className("android.widget.TextView")
.text("Help")
)
helpText.exists()
}

fun verifyFirstTitleOnHelpScreen() {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onView(
allOf(withId(net.gini.android.bank.sdk.R.id.gbs_help_title),
withText("1. How does a digital invoice work?")
)
)
.check(matches(isDisplayed()))
}

fun checkTotalTitleIsDisplayed() {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onView(
allOf(withId(net.gini.android.bank.sdk.R.id.total_label),
withText("Total")
)
)
.check(matches(isDisplayed()))
}

fun checkTotalPriceIsDisplayed() {
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(matches(isDisplayed()))
}

fun checkInitialPrice() {
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
initialValue = totalTextView.text.toString()
}
}

fun checkUpdatedPrice() {
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
updatedValue = totalTextView.text.toString()
}
}

fun assertPriceHasChanged() {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
assertNotEquals("Price should have changed after toggling", initialValue, updatedValue)
}
}
Loading
Loading