ISSUE-88: Add ScreenshotScenarioRule
What does this change accomplish?
Resolves #88 Resolves #72
Adds ScreenshotScenarioRule which works in conjunction with Android's ActivityScenario.
How have you achieved it?
As ActivityTestRule is deprecated, the Android SDK now recommends the usage of ActivityScenario as the modern alternative. Testify provides ScreenshotScenarioRule which works in conjunction with ActivityScenario to easily add screenshot tests to scenario-based UI tests.
ScreenshotScenarioRule is more flexible than the older ScreenshotTestRule as it no longer requires you to couple the rule's instantiatiation with a specific Activity subclass. This allows the flexibility of testing multiple different activities in the same test class.
Screenshot test integration with ActivityScenario is achieved via the withScenario() function. An active instance of a scenario must be provided to Testify prior to calling assertSame(). Typically, this is done by passing the scaneario instance returned by ActivityScenario.launch to the ScreenshotScenarioRule instance within a use {} block.
[!TIP] To enable Android Studio Plugin integration with your tests, each test method should be annotated with the
@ScreenshotInstrumentationannotation.
import androidx.test.core.app.launchActivity
import dev.testify.MainActivity
import dev.testify.annotation.ScreenshotInstrumentation
import org.junit.Rule
import org.junit.Test
class MainActivityScreenshotTest {
@get:Rule val rule = ScreenshotScenarioRule()
@ScreenshotInstrumentation
@Test
fun default() {
launchActivity<MainActivity>().use { scenario ->
screenshotRule.withScenario(scenario).assertSame()
}
}
}
Scope of Impact and Testing instructions
The best way to test this is to pull down this branch and read through the documentation. The samples have been updated to include Scenario-based tests. The documentation explains how to use all of the Testify features with Scenarios.
You can view the documentation locally by running yarn start from the docs directory.
Notice
[!WARNING] This change must keep
mainin a shippable state; it may be shipped without further notice.
:white_check_mark: Success! - Legacy Sample screenshot test results
View build for commit e20121fd9f5786501437437388f0e6115b4ea13b
:white_check_mark: Success! - Flix Sample screenshot test results
View build for commit e20121fd9f5786501437437388f0e6115b4ea13b