Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
pixels-catcher
Advanced tools
Library for testing React Native UI components and screens
$ npm install pixels-catcher --save
For the application integration only react-native-save-view is used which is required to convert View
to base64 data and has native implementation. Therefore the linking is required and this can be easily done with the following steps:
android/settings.gradle
file include the dependency:include ':react-native-save-view'
project(':react-native-save-view').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-save-view/android')
android/app/build.gradle
file add:dependencies {
compile project(':react-native-save-view') // <-- This
...
}
android/app/src/main/java/com/.../MainApplication.java
add it to packages list@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SaveViewPackage() // <-- This
);
}
Create new entry file, for example, indexSnapshot
or check the demo project. You will need to import registerSnapshot
, runSnapshots
and Snapshot
from pixels-catcher
:
import {
registerSnapshot,
runSnapshots,
Snapshot,
} from 'pixels-catcher';
After that create the snapshot component, which should extend Snapshot
and implement static snapshotName
and renderContent
method. The implementation can be:
class AppSnapshot extends Snapshot<*, *> {
static snapshotName = 'AppSnapshot';
renderContent() {
return (
<App />
);
}
}
after that register it:
registerSnapshot(AppSnapshot);
and run snapshots:
runSnapshots(PUT_YOUR_APP_NAME_HERE);
Snapshots testing will be started as soon as the application is started.
In package.json
add the following section (change the values according to your project, or check demo project):
"PixelsCatcher": {
"activityName" : "ACTIVITY_NAME",
"apkFile" : "PATH_TO_APK_FILE",
"emulatorName" : "EMULATOR_NAME",
"packageName" : "ANDROID_PACKAGE_NAME",
"snapshotsPath": "PATH_TO_SNAPSHOTS_FILES"
}
There are two options to run UI snapshots:
Using the generated api file, provided via PixelsCatcher.packageName
. This case can be useful for CI, for example. To run the test all what you need is to execute the following command in the command line:
./node_modules/.bin/pixels-catcher
This command will open android emulator, install apk file and execute all tests, providing report at the end.
By default the index.android.js
file is used which refer to your application. To fix it, in the android/app/build.gradle
add the following config
project.ext.react = [
entryFile: System.getProperty("entryFile") ?: "index.js",
bundleInDebug: System.getProperty("bundleInDebug") ?: true
]
And generate the apk as following:
cd android && ./gradlew assembleRelease -DentryFile="indexSnapshot"
Using development mode and react native development server. In this case you need to run the PixelsCatcher
in development mode:
./node_modules/.bin/pixels-catcher dev
This will start only server and you can run the test as many times as you need, by reloading the app.
Also verify that you use indexSnapshot
instead of your default entry point.
Check the demo which includes an example how the snapshots can be done and also has some useful scripts that can be used to integrate with CI.
FAQs
UI snapshot testing for React Native
The npm package pixels-catcher receives a total of 36,698 weekly downloads. As such, pixels-catcher popularity was classified as popular.
We found that pixels-catcher demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.