مكتبة Android لتقديم شاشات التطبيق الخاصة بك بدون جهاز فعلي أو محاكي.
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 ()
}
}
}
راجع موقع المشروع للوثائق وواجهة برمجة التطبيقات.
./gradlew sample:testDebug
يقوم بتشغيل الاختبارات ويقوم بإنشاء تقرير HTML في sample/build/reports/paparazzi/
عرض جميع عمليات الاختبار واللقطات.
./gradlew sample:recordPaparazziDebug
يحفظ اللقطات كقيم ذهبية إلى موقع محدد مسبقًا يسيطر عليه المصدر (الإعدادات الافتراضية لـ src/test/snapshots
).
./gradlew sample:verifyPaparazziDebug
يدير الاختبارات ويتحقق من القيم الذهبية المسجلة مسبقًا. الفشل تولد فرق في sample/build/paparazzi/failures
.
لمزيد من الأمثلة ، تحقق من عينة مشروع.
يوصى باستخدام GIT LFS لتخزين لقطاتك. هذا إعداد سريع:
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
على CI ، يمكنك إعداد شيء مثل:
$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 لترحيل مكتبات الدعم ، فأضف ما يلي إلى gradle.properties
لاستبعاد تبعيات Android المجمعة.
android.jetifier.ignorelist =android-base-common,common
عند التقاط لقطات من الرسوم المتحركة Lottie ، تحتاج إلى إجبار Lottie على عدم الركض على موضوع خلفية ، وإلا يمكن أن يرمي المصورون الاستثناءات رقم 494 ، #630.
@Before
fun setup () {
LottieTask . EXECUTOR = Executor ( Runnable ::run)
}
بعض المواد المركبة -مثل GoogleMap()
-تحقق من LocalInspectionMode
في الدائرة القصيرة إلى @Preview
-safe composable.
ومع ذلك ، لا يقوم Paparazzi بتعيين LocalInspectionMode
على مستوى العالم لضمان أن اللقطة تمثل إخراج الإنتاج الحقيقي ، على غرار كيفية View.isInEditMode
.
كحل بديل ، نوصي بتغليف مثل هذا القابل للتكوين في مُعدّل مخصص باستخدام CompositionLocalProvider
ووضع LocalInspectionMode
محلي.
@Test
fun inspectionModeView () {
paparazzi.snapshot(
CompositionLocalProvider ( LocalInspectionMode provides true ) {
YourComposable ()
}
)
}
سجل التغيير لدينا له تاريخ الإصدار.
باستخدام تطبيق البرنامج المساعد:
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath ' app.cash.paparazzi:paparazzi-gradle-plugin:1.3.5 '
}
}
apply plugin : ' app.cash.paparazzi '
باستخدام المكونات الإضافية DSL:
plugins {
id ' app.cash.paparazzi ' version ' 1.3.5 '
}
تتوفر لقطات من إصدار التطوير في مستودع snapshots
Sonatype.
repositories {
// ...
maven {
url ' https://oss.sonatype.org/content/repositories/snapshots/ '
}
}
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.