Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Shot/shot-android/src/main/java/com/karumi/shot/ActivityScenarioUtils.kt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
25 lines (23 sloc)
992 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.karumi.shot | |
import android.app.Activity | |
import androidx.test.core.app.ActivityScenario | |
import java.lang.IllegalStateException | |
/* ActivityTestRule has been deprecated and now the usage of ActivityScenario is recommended. | |
* However, Shot needs to be executed from the instrumentation thread to be able to extract | |
* all the test metadata needed to record and verify screenshots. That's why we've created this | |
* extension to be able to get the activity instance from the instrumentation thread instead | |
* of running Shot from the app target thread. I hope we can find a better solution in the future. | |
*/ | |
object ActivityScenarioUtils { | |
fun <A : Activity> ActivityScenario<A>.waitForActivity(): A { | |
var activity: A? = null | |
onActivity { | |
activity = it | |
} | |
return if (activity != null) { | |
activity!! | |
} else { | |
throw IllegalStateException("The activity scenario could not be initialized.") | |
} | |
} | |
} |