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 @@ -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 @@ -19,12 +19,29 @@ class ConfigurationScreen {
}

fun clickFlashToggleToEnable(): ConfigurationScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onView(ViewMatchers.withId(R.id.switch_flashOnByDefault)).perform(closeSoftKeyboard(), click())
onView(ViewMatchers.withId(R.id.switch_flashOnByDefault)).perform(
closeSoftKeyboard(),
click()
)
return this
}

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(
// closeSoftKeyboard(),
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
click()
)
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
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 displayDigitalInvoiceTextOnOnboardingScreen(): DigitalInvoiceScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
val onboardingScreenText = device.findObject(
UiSelector()
.className("android.widget.TextView")
.text("Digital invoice")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/onboarding_text_1")
)
onboardingScreenText.exists()
return this
}

fun displayGetStartedButtonOnOnboardingScreen(): DigitalInvoiceScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
val onboardingScreenButton = device.findObject(
UiSelector()
.className("android.widget.Button")
.text("Get Started")
.resourceId("net.gini.android.bank.sdk.exampleapp:id/done_button")
)
onboardingScreenButton.exists()
return this
}

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

fun assertDigitalInvoiceText(): DigitalInvoiceScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
val digitalInvoiceText = device.findObject(
UiSelector()
.className("android.widget.TextView")
.text("Digital Invoice")
)
digitalInvoiceText.exists()
return this
}

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

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

fun clickProceedButton(): DigitalInvoiceScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
onView(withText(net.gini.android.bank.sdk.R.string.gbs_proceed)).perform(click())
return this
}

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)
)
articleSwitch.exists()
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
articleSwitch.isClickable
articleSwitch.click()
return this
}

fun checkForReturnReasonsList(): DigitalInvoiceScreen {
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()))
return this
}

fun checkItemCountOnReturnReasonsList(): DigitalInvoiceScreen {
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
return this
}

fun clickItemOnReturnReasonsList(): DigitalInvoiceScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
val uiCollection =
UiCollection(UiSelector().className("android.widget.ListView"))
val returnReasonsItems = uiCollection.getChildByInstance(
UiSelector().className("android.widget.TextView"), 0)
returnReasonsItems.click()
return this
}

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(): DigitalInvoiceScreen {
SyedaGinii marked this conversation as resolved.
Show resolved Hide resolved
val helpButton = device.findObject(
UiSelector()
.className("android.widget.Button")
.descriptionContains("Help")
)
helpButton.exists()
helpButton.click()
return this
}

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

fun verifyFirstTitleOnHelpScreen(): DigitalInvoiceScreen {
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?")
)
)
.perform(click())
return this
}

fun checkTotalTitleIsDisplayed(): DigitalInvoiceScreen {
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()))
return this
}

fun checkTotalPriceIsDisplayed(): DigitalInvoiceScreen {
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()))
return this
}

fun storeInitialPrice(): DigitalInvoiceScreen {
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()
}
return this
}

fun storeUpdatedPrice(): DigitalInvoiceScreen {
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()
}
return this
}

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