From be1e8a8ef8740bb5412de1e337ee620c19efc52c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 15 Sep 2022 09:28:37 +0100 Subject: [PATCH 1/4] adding and recording example paparazzi test --- .../PaparazziExampleScreenshotTest.kt | 45 +++++++++++++++++++ ...eScreenshotTest_example paparazzi test.png | 3 ++ 2 files changed, 48 insertions(+) create mode 100644 vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt create mode 100644 vector/src/test/snapshots/images/im.vector.app.screenshot_PaparazziExampleScreenshotTest_example paparazzi test.png diff --git a/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt b/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt new file mode 100644 index 0000000000..a1b1d05327 --- /dev/null +++ b/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.screenshot + +import android.widget.ImageView +import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout +import app.cash.paparazzi.DeviceConfig.Companion.PIXEL_3 +import app.cash.paparazzi.Paparazzi +import im.vector.app.R +import org.junit.Rule +import org.junit.Test + +class PaparazziExampleScreenshotTest { + + @get:Rule + val paparazzi = Paparazzi( + deviceConfig = PIXEL_3, + theme = "Theme.Vector.Light", + ) + + @Test + fun `example paparazzi test`() { + val view = paparazzi.inflate(R.layout.item_radio) + + view.findViewById(R.id.actionTitle).text = paparazzi.resources.getString(R.string.room_settings_all_messages) + view.findViewById(R.id.radioIcon).setImageResource(R.drawable.ic_radio_on) + + paparazzi.snapshot(view) + } +} diff --git a/vector/src/test/snapshots/images/im.vector.app.screenshot_PaparazziExampleScreenshotTest_example paparazzi test.png b/vector/src/test/snapshots/images/im.vector.app.screenshot_PaparazziExampleScreenshotTest_example paparazzi test.png new file mode 100644 index 0000000000..bba610b25f --- /dev/null +++ b/vector/src/test/snapshots/images/im.vector.app.screenshot_PaparazziExampleScreenshotTest_example paparazzi test.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:113cf006e9a881f19b79462297cf276aea2b82268182f9ecc297d4b31640b507 +size 11174 From 4a81ee25ac6d2c8819be5ee42e4080516b5bd574 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 26 Sep 2022 14:19:02 +0100 Subject: [PATCH 2/4] manually including the paparazzi jar as the plugin is only applied when executing the screenshot tasks (which automatically included the jar previously) --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 7b67c89502..6b8df62b5e 100644 --- a/build.gradle +++ b/build.gradle @@ -312,6 +312,7 @@ ext.initScreenshotTests = { project -> if (hasScreenshots) { project.apply plugin: 'app.cash.paparazzi' } + project.dependencies { testCompileOnly "app.cash.paparazzi:paparazzi:1.0.0" } project.android.testOptions.unitTests.all { def screenshotTestCapture = "**/*ScreenshotTest*" if (hasScreenshots) { From 28f4e79b43fa10bcd228c1da2bf19bcd290b4e46 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 27 Sep 2022 10:16:45 +0100 Subject: [PATCH 3/4] attempting to use 0% difference for screenshot verification - this may cause false errors with the navigation/status bar https://github.com/cashapp/paparazzi/issues/453#issuecomment-1254001714 --- .../im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt b/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt index a1b1d05327..fb8bed0034 100644 --- a/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt +++ b/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt @@ -31,6 +31,7 @@ class PaparazziExampleScreenshotTest { val paparazzi = Paparazzi( deviceConfig = PIXEL_3, theme = "Theme.Vector.Light", + maxPercentDifference = 0.0, ) @Test From 2d2b2e9218ec83a45dec09e401ae6eb843f4191e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 27 Sep 2022 11:03:44 +0100 Subject: [PATCH 4/4] using latest upload-artifact action (should fix missing glob) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d0d125e7ae..b049346548 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,7 +37,7 @@ jobs: - name: Archive Screenshot Results on Error if: failure() - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 with: name: screenshot-results path: |