Skip to content

Commit

Permalink
Target specific SDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomartins8 committed Jan 17, 2024
1 parent 10b7fd5 commit 6139073
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
name: Espresso Tests

on: [ push, workflow_dispatch ]
on:
workflow_dispatch:
inputs:
SDK_TARGET_VERSION:
description: 'Target a specific SDK version. Otherwise latest'
required: false
push:

env:
SDK_TARGET_VERSION: ${{ github.event.inputs.SDK_TARGET_VERSION }}

jobs:
build:
Expand Down
45 changes: 45 additions & 0 deletions app/src/androidTest/java/com/onfido/evergreen/RetryTestRule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.onfido.evergreen

import android.util.Log
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement

/**
* Retry test rule used to retry test that failed.
* Retry failed test 3 times
*/
class RetryTestRule(val retryCount: Int = 3) : TestRule {

private val TAG = RetryTestRule::class.java.simpleName

override fun apply(base: Statement, description: Description): Statement {
return statement(base, description)
}

private fun statement(base: Statement, description: Description): Statement {
return object : Statement() {
@Throws(Throwable::class)
override fun evaluate() {
var caughtThrowable: Throwable? = null

// implement retry logic here
for (i in 0 until retryCount) {
try {
base.evaluate()
return
} catch (t: Throwable) {
caughtThrowable = t
Log.e(TAG, description.displayName + ": run " + (i + 1) + " failed")
}
}

Log.e(
TAG,
description.displayName + ": giving up after " + retryCount + " failures"
)
throw caughtThrowable!!
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class WebViewIntegrationTest {
@get:Rule
var activityScenarioRule = activityScenarioRule<MainActivity>()

@Rule
@JvmField
val mRetryTestRule = RetryTestRule()

@Test
fun openApp() {
onView(withId(R.id.webview)).check(matches(isDisplayed()))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/onfido/evergreen/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.text.SimpleDateFormat
import java.util.Date

data class Configuration(
val version: String = "latest",
val version: String = System.getenv("SDK_TARGET_VERSION") ?: "latest",
val url: String? = null
)

Expand Down

0 comments on commit 6139073

Please sign in to comment.