Skip to content

Commit

Permalink
Add Google Pay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samer-stripe committed Sep 2, 2024
1 parent 16b2da4 commit b2c5821
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,18 @@ workflows:
after_run:
- conclude_all
steps:
- android-build-for-ui-testing:
- android-build-for-ui-testing@0:
inputs:
- module: paymentsheet-example
- variant: debug
- virtual-device-testing-for-android:
- virtual-device-testing-for-android@1:
inputs:
- test_type: instrumentation
- auto_google_login: true
- use_verbose_log: true
- download_test_results: true
- environment_variables:
STRIPE_SHOULD_RUN_GOOGLE_PAY_TESTS=true
- inst_test_targets: class com.stripe.android.lpm.TestGooglePay
- test_devices: 'Pixel3,30,en,portrait'
run-connections-e2e-payments-tests:
Expand Down
4 changes: 4 additions & 0 deletions paymentsheet-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def getGooglePlacesApiKey() {
return findProperty('STRIPE_PAYMENTSHEET_EXAMPLE_GOOGLE_PLACES_API_KEY') ?: ""
}

def shouldRunGooglePayTests = System.getenv("STRIPE_SHOULD_RUN_GOOGLE_PAY_TESTS") ?: "true"

dependencies {
implementation project(':payments')
implementation project(':stripecardscan')
Expand Down Expand Up @@ -84,6 +86,8 @@ android {
versionCode 11

testInstrumentationRunner "com.karumi.shot.ShotTestRunner"
testInstrumentationRunnerArguments["com.stripe.android.should_run_google_pay_tests"] =
shouldRunGooglePayTests

buildConfigField "boolean", "IS_RUNNING_IN_CI", "$gradle.ext.isCi"
buildConfigField "boolean", "IS_NIGHTLY_BUILD", "$gradle.ext.isNightlyBuild"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,50 @@ package com.stripe.android.lpm
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.utils.GooglePayTest
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class TestGooglePay : BasePlaygroundTest() {
@Test
@GooglePayTest
fun testUnitedStates() {
testDriver.confirmWithGooglePay(Country.US)
}

@Test
@GooglePayTest
fun testFrance() {
testDriver.confirmWithGooglePay(Country.FR)
}

@Test
@GooglePayTest
fun testGreatBritain() {
testDriver.confirmWithGooglePay(Country.GB)
}

@Test
@GooglePayTest
fun testAustralia() {
testDriver.confirmWithGooglePay(Country.AU)
}

@Test
@GooglePayTest
fun testBrazil() {
testDriver.confirmWithGooglePay(Country.BR)
}

@Test
@GooglePayTest
fun testJapan() {
testDriver.confirmWithGooglePay(Country.JP)
}

@Test
@GooglePayTest
fun testMexico() {
testDriver.confirmWithGooglePay(Country.MX)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.stripe.android.utils
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
annotation class GooglePayTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.stripe.android.utils

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

class GooglePayTestRule : TestRule {
override fun apply(base: Statement, description: Description): Statement {
return object : Statement() {
override fun evaluate() {
if (description.hasGooglePayTestAnnotation()) {
if (shouldRunGooglePayTests()) {
base.evaluate()
}
} else {
base.evaluate()
}
}
}
}

private fun Description.hasGooglePayTestAnnotation(): Boolean {
for (annotation in annotations) {
if (annotation is GooglePayTest) {
return true
}
}

return false
}

private fun shouldRunGooglePayTests(): Boolean {
return InstrumentationRegistry.getArguments().getString(SHOULD_RUN_GOOGLE_PAY_TESTS_ARGUMENTS).toBoolean()
}

private companion object {
const val SHOULD_RUN_GOOGLE_PAY_TESTS_ARGUMENTS = "com.stripe.android.should_run_google_pay_tests"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TestRules private constructor(
}
}.around(Timeout.seconds(INDIVIDUAL_TEST_TIMEOUT_SECONDS))
.around(CleanupChromeRule)
.around(GooglePayTestRule())

return TestRules(chain, composeTestRule)
}
Expand Down

0 comments on commit b2c5821

Please sign in to comment.