Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-88: Add ScreenshotScenarioRule #201

Merged
merged 5 commits into from
May 27, 2024

Conversation

DanielJette
Copy link
Contributor

@DanielJette DanielJette commented Jan 7, 2024

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 @ScreenshotInstrumentation annotation.

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 main in a shippable state; it may be shipped without further notice.

@AndroidTestifyBot
Copy link
Contributor

AndroidTestifyBot commented Jan 7, 2024

✅ Success! - Legacy Sample screenshot test results

View build for commit e20121f

@AndroidTestifyBot
Copy link
Contributor

AndroidTestifyBot commented Jan 7, 2024

✅ Success! - Flix Sample screenshot test results

View build for commit e20121f

@AndroidTestifyBot
Copy link
Contributor

AndroidTestifyBot commented Jan 7, 2024

✅ Success! - Flix Library screenshot test results

View build for commit e20121f

@DanielJette DanielJette force-pushed the ISSUE-88-ScreenshotScenarioRule branch from 534a21a to f94a0a0 Compare March 24, 2024 19:25
@DanielJette DanielJette force-pushed the ISSUE-79-configuration_cache branch from f2f91ed to 62c2de4 Compare March 24, 2024 19:26
@DanielJette DanielJette force-pushed the ISSUE-88-ScreenshotScenarioRule branch 2 times, most recently from b4668cc to 5d44ea8 Compare March 24, 2024 21:59
@DanielJette DanielJette marked this pull request as ready for review March 25, 2024 00:07
@DanielJette DanielJette requested a review from a team March 25, 2024 00:07
@DanielJette DanielJette force-pushed the ISSUE-79-configuration_cache branch from 62c2de4 to 528aef4 Compare March 25, 2024 01:45
@DanielJette DanielJette force-pushed the ISSUE-88-ScreenshotScenarioRule branch from 5d44ea8 to ec7f4ce Compare March 25, 2024 01:45
Copy link
Contributor

@lwise lwise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the screenshot file for testUnexpectedDevice shouldn't be included but otherwise LGTM

@DanielJette DanielJette force-pushed the ISSUE-88-ScreenshotScenarioRule branch from ec7f4ce to 6eca560 Compare May 27, 2024 01:53
Base automatically changed from ISSUE-79-configuration_cache to main May 27, 2024 12:57
@DanielJette DanielJette force-pushed the ISSUE-88-ScreenshotScenarioRule branch from 6eca560 to f67e475 Compare May 27, 2024 17:08
@DanielJette DanielJette merged commit 1b378a8 into main May 27, 2024
2 checks passed
@DanielJette DanielJette deleted the ISSUE-88-ScreenshotScenarioRule branch May 27, 2024 17:34
@DanielJette DanielJette mentioned this pull request Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActivityTestRule deprecated Provide ActivityScenarioRule-based Testify version
3 participants