takahirom / roborazzi

Make JVM Android integration test visible 🤖📸
https://takahirom.github.io/roborazzi/
Apache License 2.0
693 stars 27 forks source link

[IDE Plugin] More flexible screenshots paths detection #467

Open Pschsch opened 4 weeks ago

Pschsch commented 4 weeks ago

@takahirom Thank you so much for library and all the collaborators.

Problem: by default, IDE plugin looks for screenshot names by next pattern: {selected screenshots folder in settings}/{Test class name}.{Test name}.png If I change this pattern, IDE Plugin breaks, it could not resolve paths to generated screenshots. Consider the next case: I have test class:

// Robolectric setup
class TestClass {
    @Test fun myTest() { /* some screenshot logic */ } 
}

And I want to store screenshot of this test in path: src/test/screenshots/com.test.TestClass/myTest.png

IDE plugin would not detect location of this screenshot and show empty window when focused on it.

Possible solution as I see it: Generate some mapping file for IDE plugin, where key is full-qualified test name and value is path to screenshot. Mapping file will be edited on each captureRoboImage() Possible example of mapping in this case in JSON format:

[
  {
    "testName": "com.test.TestClass.myTest",
    "screenshotPath": "src/test/screenshots/com.test.TestClass/myTest.png"
  }
]

We could store it in some location of build directory, for example, build/intermediates/roborazzi

And look for screenshot path by testName key.

It's will be also nice to have ability to disable mapping file generation, for example, via gradle plugin extension property to reduce possible performance affects on CI.

@takahirom What do you think about this solution?

takahirom commented 4 weeks ago

Thank you for using Roborazzi! Well, we actually have that kind of JSON file in the test-results directory. So I think we have the information we need. The reason why we don't do it is that it could be a bit challenging to implement. Another approach could be to improve the image search algorithm using the pathname.

  "results": [
    {
      "golden_file_path": "xxx/git/conference-app-2024/feature/profilecard/build/outputs/roborazzi/ProfileCardScreenTest[ProfileCardScreen - when profile card is not found - input nickname - input occupation - click create button - click edit button - it should show edit screen].png",
      "timestamp": 839363151954000,
      "context_data": {
        "roborazzi_description_class": "io.github.droidkaigi.confsched.profilecard.ProfileCardScreenTest"
      },
      "type": "recorded"
    },
    {
      "golden_file_path": "xxx/git/conference-app-2024/feature/profilecard/build/outputs/roborazzi/ProfileCardScreenTest[ProfileCardScreen - when profile card is not found - input nickname - input occupation - click create button - click edit button - it should show edit screen].png",
      "timestamp": 839363091096916,
      "context_data": {
        "roborazzi_description_class": "io.github.droidkaigi.confsched.profilecard.ProfileCardScreenTest"
      },
      "type": "recorded"
    }
  ]