• Stars
    star
    2,164
  • Rank 20,446 (Top 0.5 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 7 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Render your Android screens without a physical device or emulator

Paparazzi

An Android library to render your application screens without a physical device or emulator.

class LaunchViewTest {
  @get:Rule
  val paparazzi = Paparazzi(
    deviceConfig = PIXEL_5,
    theme = "android:Theme.Material.Light.NoActionBar"
    // ...see docs for more options
  )

  @Test
  fun launchView() {
    val view = paparazzi.inflate<LaunchView>(R.layout.launch)
    // or...
    // val view = LaunchView(paparazzi.context)

    view.setModel(LaunchModel(title = "paparazzi"))
    paparazzi.snapshot(view)
  }

  @Test
  fun launchComposable() {
    paparazzi.snapshot {
      MyComposable()
    }
  }
}

See the project website for documentation and APIs.

Tasks

./gradlew sample:testDebug

Runs tests and generates an HTML report at sample/build/reports/paparazzi/ showing all test runs and snapshots.

./gradlew sample:recordPaparazziDebug

Saves snapshots as golden values to a predefined source-controlled location (defaults to src/test/snapshots).

./gradlew sample:verifyPaparazziDebug

Runs tests and verifies against previously-recorded golden values. Failures generate diffs at sample/build/paparazzi/failures.

For more examples, check out the sample project.

Git LFS

It is recommended you use Git LFS to store your snapshots. Here's a quick setup:

brew install git-lfs
git config core.hooksPath  # optional, confirm where your git hooks will be installed
git lfs install --local
git lfs track "**/snapshots/**/*.png"
git add .gitattributes

On CI, you might set up something like:

$HOOKS_DIR/pre-receive

# compares files that match .gitattributes filter to those actually tracked by git-lfs
diff <(git ls-files ':(attr:filter=lfs)' | sort) <(git lfs ls-files -n | sort) >/dev/null

ret=$?
if [[ $ret -ne 0 ]]; then
  echo >&2 "This remote has detected files committed without using Git LFS. Run 'brew install git-lfs && git lfs install' to install it and re-commit your files.";
  exit 1;
fi

your_build_script.sh

if [[ is running snapshot tests ]]; then
  # fail fast if files not checked in using git lfs
  "$HOOKS_DIR"/pre-receive
  git lfs install --local
  git lfs pull
fi

Jetifier

If using Jetifier to migrate off Support libraries, add the following to your gradle.properties to exclude bundled Android dependencies.

android.jetifier.ignorelist=android-base-common,common

Lottie

When taking screenshots of Lottie animations, you need to force Lottie to not run on a background thread, otherwise Paparazzi can throw exceptions #494, #630.

@Before
fun setup() {
    LottieTask.EXECUTOR = Executor(Runnable::run)
}

LocalInspectionMode

Some Composables -- such as GoogleMap() -- check for LocalInspectionMode to short-circuit to a @Preview-safe Composable.

However, Paparazzi does not set LocalInspectionMode globally to ensure that the snapshot represents the true production output, similar to how it overrides View.isInEditMode for legacy views.

As a workaround, we recommend wrapping such a Composable in a custom Composable with a CompositionLocalProvider and setting LocalInspectionMode there.

 @Test
  fun inspectionModeView() {
    paparazzi.snapshot(
      CompositionLocalProvider(LocalInspectionMode provides true) {
        YourComposable()
      }
    )
  }

Releases

Our change log has release history.

Using plugin application:

buildscript {
  repositories {
    mavenCentral()
    google()
  }
  dependencies {
    classpath 'app.cash.paparazzi:paparazzi-gradle-plugin:1.3.1'
  }
}

apply plugin: 'app.cash.paparazzi'

Using the plugins DSL:

plugins {
  id 'app.cash.paparazzi' version '1.3.1'
}

Snapshots of the development version are available in Sonatype's snapshots repository.

repositories {
  // ...
  maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots/'
  }
}

License

Copyright 2019 Square, Inc.

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.

More Repositories

1

sqldelight

SQLDelight - Generates typesafe Kotlin APIs from SQL
Kotlin
5,918
star
2

turbine

A small testing library for kotlinx.coroutines Flow
Kotlin
2,323
star
3

zipline

Run Kotlin/JS libraries in Kotlin/JVM and Kotlin/Native programs
C
1,914
star
4

molecule

Build a StateFlow stream using Jetpack Compose
Kotlin
1,710
star
5

contour

Layouts with lambdas 😎
Kotlin
1,522
star
6

redwood

Multiplatform reactive UI for Android, iOS, and web using Kotlin and Jetpack Compose
Kotlin
1,458
star
7

InflationInject

Constructor-inject views during XML layout inflation
Kotlin
908
star
8

pranadb

Go
615
star
9

licensee

Gradle plugin which validates the licenses of your dependency graph match what you expect
Kotlin
599
star
10

hermit

🐚 Hermit manages isolated, self-bootstrapping sets of tools in software projects.
Go
557
star
11

AccessibilitySnapshot

Easy regression testing for iOS accessibility
Swift
522
star
12

exhaustive

An annotation and Kotlin compiler plugin for enforcing a when statement is exhaustive
Kotlin
465
star
13

multiplatform-paging

A library that packages AndroidX Paging for Kotlin/Multiplatform.
Kotlin
452
star
14

misk

Microservice Kontainer
Kotlin
386
star
15

copper

A content provider wrapper for reactive queries
Kotlin
300
star
16

barber

Barber πŸ’ˆ A type safe Kotlin JVM library for building up localized, fillable, themed documents using Mustache templating
Kotlin
157
star
17

paraphrase

A Gradle plugin that generates type-safe formatters for Android string resources in the ICU message format.
Kotlin
157
star
18

stagehand

Modern, type-safe API for building animations on iOS
Swift
126
star
19

hermit-packages

Hermit manages isolated, self-bootstrapping sets of tools in software projects.
HCL
111
star
20

quiver

Quiver is a collection of extension methods and handy functions to make the wonderful functional programming Kotlin library, Arrow, even better.
Kotlin
95
star
21

spirit

Online Schema Change Tool for MySQL 8.0
Go
87
star
22

pivit

Go
82
star
23

tempest

Typesafe DynamoDB for Kotlin and Java.
Kotlin
80
star
24

better-dynamic-features

Making dynamic feature modules better
Kotlin
70
star
25

misk-web

Micro-Frontends React + Redux + Typescript Framework
TypeScript
65
star
26

blip

Sublime MySQL monitoring
Go
59
star
27

logquacious

Logquacious (lq) is a fast and simple log viewer.
TypeScript
58
star
28

wisp

Wisp is a collection of kotlin modules providing various features and utilities, including config, logging, feature flags and more.
Kotlin
58
star
29

certifikit

Kotlin Certificate processing library.
Kotlin
40
star
30

backfila

Service that manages backfill state, calling into other services to do batched work
Kotlin
30
star
31

cash-app-pay-android-sdk

Cash Android PayKit SDK for merchant integrations with Cash App Pay
Kotlin
29
star
32

nostrino

A Kotlin SDK for Nostr
Kotlin
28
star
33

transflect

Kubernetes operator using Istio to set up Envoy's gRPC-JSON transcoding.
Go
24
star
34

cmmc

K8S ConfigMap Merging Controller
Go
20
star
35

cloner

Go
20
star
36

kfsm

Finite state machinery in Kotlin
Kotlin
19
star
37

yet-another-aws-exporter

A Prometheus metrics exporter for AWS that fills in gaps CloudWatch doesn't cover
Go
17
star
38

cash-app-pay-ios-sdk

Swift
14
star
39

protosync

ProtoSync synchronises remote .proto files to a local directory
Go
13
star
40

cash-pay-pay-sdk-android-sample-app

Cash App Pay Kit SDK Sample app for Android.
Kotlin
12
star
41

trifle

Security functionality for interoperability/interaction with core services.
Swift
11
star
42

AardvarkReveal

Generate and attach a Reveal file to your Aardvark bug reports
Swift
10
star
43

ln-invoice

Parse lightning network payment requests (invoices) in Kotlin.
Kotlin
10
star
44

kfactories

Set of factories and utils to create effective and lightweight property-based testing strategies.
Kotlin
9
star
45

jooq-encryption

Kotlin
9
star
46

hermit-ij-plugin

Kotlin
8
star
47

cash-app-pay-sdk-ios-sample-app

Swift
7
star
48

AardvarkCrashReport

AardvarkCrashReport makes it easy to provide high quality data about crashes in your bug reports
Swift
7
star
49

awsu

su for aws roles
Go
7
star
50

check-signature-action

Shell
6
star
51

csop

Go
6
star
52

activate-hermit

Github Action to activate a Hermit environment.
Shell
6
star
53

kruit

TypeScript
4
star
54

chronicler

Kotlin
3
star
55

hermit-build

Relocatable/static builds for Hermit packages
Makefile
3
star
56

s3-copy-gradle-plugin

1
star
57

.github

1
star
58

hermit-package-version

Shell
1
star
59

cash-app-pay-sandbox-releases

1
star