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 5 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,223 @@
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.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`


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.waitForExists(8000)
}

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.waitForExists(10000)
}

fun clickGetStartedButtonOnOnboardingScreen() {
val onboardingScreenButton = device.findObject(
UiSelector()
.className("android.widget.Button")
.text("Get Started")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/done_button")
)
if (onboardingScreenButton.waitForExists(5000) && onboardingScreenButton.isClickable) {
onboardingScreenButton.click()
}
}

fun clickCancelButton() {
val cancelButton = device.findObject(
UiSelector()
.className("android.widget.ImageButton")
.descriptionContains("Close")
)
if(cancelButton.exists() && cancelButton.isClickable()){
cancelButton.click()
}
}

fun assertOtherChargesDisplayed() : Boolean {
var isOtherChargesDisplayed = false
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_addon_other_charges))
.check { view,_ ->
if (view.isShown()) {
isOtherChargesDisplayed = true
}
}
return isOtherChargesDisplayed
}

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(): Boolean {
var isReturnReasonDisplayed = false
onView(withText(net.gini.android.bank.sdk.R.string.gbs_digital_invoice_return_reason_dialog_title))
.check { view, _ ->
if (view.isShown()) {
isReturnReasonDisplayed = true
}
}
return isReturnReasonDisplayed
}

fun returnItemCountOnReturnReasonsList(): 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() {
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(): Boolean {
val helpText = device.findObject(
UiSelector()
.className("android.widget.TextView")
.text("Help")
)
return helpText.exists()
}

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 { view, _ ->
if (view.isShown()) {
isFirstTitleDisplayed = true
}
}
return isFirstTitleDisplayed
}

fun checkTotalTitleIsDisplayed(): Boolean {
var isTotalTitleDisplayed = false
onView(
allOf(withId(net.gini.android.bank.sdk.R.id.total_label),
withText("Total")
)
)
.check { view, _ ->
if (view.isShown()) {
isTotalTitleDisplayed = true
}
}
return isTotalTitleDisplayed
}

fun checkTotalPriceIsDisplayed() : Boolean{
var isTotalPriceDisplayed = false
onView((withId(net.gini.android.bank.sdk.R.id.gross_price_total_integral_part)))
.check { view, _ ->
if (view.isShown()) {
isTotalPriceDisplayed = true
}
}
return isTotalPriceDisplayed
}

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 verifyTotalSumValue(): Boolean{
var isSumDifferent = false
if(initialValue!=updatedValue) {
isSumDifferent = true
}
return isSumDifferent
}

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()
}
}
}
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
}
}
Loading
Loading