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

Roborazzi AI-Powered Image Verification #491

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

takahirom
Copy link
Owner

@takahirom takahirom commented Sep 21, 2024

Background

Advancements in AI: AI technologies are becoming increasingly sophisticated and affordable.
Manual Screenshot Testing: Traditional methods require manual verification, limiting scalability.

Problem

Scalability Limitations: Manual checks hinder large-scale screenshot testing.
High Maintenance Costs: Human intervention increases effort and costs.

Proposal

Integrate AI for Image Comparison: Use AI to automate screenshot verification in tests.
Enhance Roborazzi: Add AiOptions to enable AI-based image evaluation.

Current code

@RunWith(AndroidJUnit4::class)
@GraphicsMode(GraphicsMode.Mode.NATIVE)
@Config(
  sdk = [30],
  qualifiers = RobolectricDeviceQualifiers.NexusOne
)
class AiTest {
  @get:Rule
  val composeTestRule = createAndroidComposeRule<MainActivity>()

  @get:Rule
  val roborazziRule = RoborazziRule(
    options = RoborazziRule.Options(
      roborazziOptions = RoborazziOptions(
        compareOptions = RoborazziOptions.CompareOptions(
          aiOptions = AiOptions(
            aiModel = AiOptions.AiModel.Gemini(
              apiKey = System.getenv("gemini_api_key")!!
            ),
          )
        )
      )
    )
  )

  @Test
  fun captureWithAi() {
    ROBORAZZI_DEBUG = true
    onView(ViewMatchers.isRoot())
      .captureRoboImage(
        roborazziOptions = provideRoborazziContext().options.addedCompareAiAssertions(
          AiOptions.AiAssertion(
            assertPrompt = "it should have PREVIOUS button",
            requiredFulfillmentPercent = 90,
          ),
          AiOptions.AiAssertion(
            assertPrompt = "it should show First Fragment",
            requiredFulfillmentPercent = 90,
          )
        )
      )
  }
}

image

Changes for Existing Projects

We won't introduce any new dependencies for existing projects. I think I'll add the roborazzi-ai module to manage dependencies like Gemini or others, so you don't have to worry about disrupting existing dependencies.

Discussion Points

When We Execute This

The current AI implementation runs only when:

  • AiOptions are set
    • Because we can't run without prompts and API keys
  • Comparing or verifying tasks
  • The image is changed with ImageComparator
    • Because I think we can save a lot of money if we check only when images are changed.

And the test fails only when:

  • All above conditions are met
  • requiredFulfillmentPercent is set
  • It doesn't fulfill
  • (These tests fail even if it's a compare task.)

How We Set Prompts

Currently, it is a little difficult to set a prompt because we need to change RoborazziOptions.CompareOptions.AiOptions.prompt.

Things to Do

  • Get feedback from someone
  • Decide on the name of this feature
  • Decide if it is okay to have prompt in RoborazziOptions.CompareOptions. If we create a new function for this, like captureRoboImageWithAI, it will require bigger changes. Alternatively, provide a way to change these options easily for RoborazziOptions.

@takahirom takahirom force-pushed the takahirom/roborazzi-ai-prototype/2024-09-21 branch from 7f4548b to 58046c3 Compare October 21, 2024 01:04
@takahirom takahirom force-pushed the takahirom/roborazzi-ai-prototype/2024-09-21 branch from 58046c3 to 6ef71df Compare October 21, 2024 01:05
@takahirom takahirom changed the title Roborazzi AI prototype Roborazzi AI-Powered Image Verification prototype Oct 22, 2024
@takahirom takahirom force-pushed the takahirom/roborazzi-ai-prototype/2024-09-21 branch from 1ce5650 to b58c5ff Compare October 22, 2024 02:44
@takahirom
Copy link
Owner Author

takahirom commented Oct 22, 2024

TODO:

  • Add a test using AiModel.Manual
  • remove loadRoboAi()
  • Separate roborazzi-ai into roborazzi-ai and roborazzi-ai-gemini

@takahirom takahirom changed the title Roborazzi AI-Powered Image Verification prototype Roborazzi AI-Powered Image Verification Oct 25, 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.

1 participant