pedrovgs/Shot
``compareScreenshot`` does not accept ``ActivityScenario`` but ``Activity`` instead
Open
#242 opened on Jul 11, 2021
enhancementhelp wanted
Repository metrics
- Stars
- (1,208 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Using the example test theActivityIsShownProperly shown in the README with ActivityScenario does not work as intended
Expected behaviour
I expected using the default test in the README to work as intended when using ActivityScenario to launch the activity without any additional steps when using
class MyActivtyTest: ScreenshotTest {
@Test
fun rendersTheDefaultActivityState() {
val activity = ActivityScenario.launch(MainActivity::class.java)
compareScreenshot(activity)
}
}
Actual behaviour
However I see the following error messages when inheriting ScreenshotTest

When I do the following setup, it works but I am not sure is this necessary or should I just need to rely on ScreenshotTest for it to work. Any help on the matter would be greatly appreciated.
@RunWith(AndroidJUnit4::class)
class MyActivityTest : com.example.shot_snapshot_application.ScreenshotTest<MainActivity>(MainActivity::class.java) {
@Test
fun theAcitivityIsShownProperly() {
val scenario = startActivity()
compareScreenshot(scenario)
}
}
and
@LargeTest
@RunWith(AndroidJUnit4::class)
abstract class ScreenshotTest<T : Activity>(private val clazz: Class<T>) :
ScreenshotTest {
private var scenario: ActivityScenario<T>? = null
@Before
fun setup() {
Intents.init()
}
@After
fun tearDown() {
scenario?.close()
Intents.release()
}
fun startActivity(args: Bundle = Bundle()): T {
val intent = Intent(ApplicationProvider.getApplicationContext(), clazz)
intent.putExtras(args)
scenario = ActivityScenario.launch(intent)
return scenario!!.waitForActivity()
}
}
Steps to reproduce
- Setup a new project
- Follow the setup steps as mentioned the readme
- For the sample test
theActivityIsShownProperlyuseval activity = ActivityScenario.launch(MainActivity::class.java)instead ofval mainActivity = startMainActivity();
Version of the library
5.11.0