EarlGreySnapshots 0.0.2

EarlGreySnapshots 0.0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release May 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Jakub Turek.


Downloads

Total591
Week10
Month75

Installs

Pod Tries3
Test Targets11
Test WeekTests This week 2
powered by Segment

GitHub

Stars6
Watchers3
Forks1
Issues1
Contributors1
Pull Requests0

Code

Files7
LOCLines of Code 140


 
Depends on:
EarlGrey~> 1.9
FBSnapshotTestCase~> 2.1
 

EarlGreySnapshots

EarlGrey actions for FBSnapshotTestCase. Provides functional tests counterpart for Nimble Snapshots.

Usage

Before using the library you need to have a project integrated with EarlGrey library. It is highly recommended to follow an official installation guide and create a separate test target for feature testing, since they are less reliable than usual unit tests.

Next, make sure to define two environment variables which point to:

  • FB_REFERENCE_IMAGE_DIR - directory containing reference snapshots,
  • IMAGE_DIFF_DIR - directory containing failure snapshots and visual diffs.

Sane default values for those variables are (as proposed in FBSnapshotTestCase README):

Name Value
FB_REFERENCE_IMAGE_DIR $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages
IMAGE_DIFF_DIR $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/FailureDiffs

Now it is time to record your first reference snapshot. Select the reference element using EarlGrey’s selection API and invoke grey_recordSnapshot() action:

EarlGrey.select(elementWithMatcher: grey_kindOfClass(AViewToSnapshotClass.self))
    .assert(grey_recordSnapshot())

Run the test target. The test should fail with the following error:

Image recorded successfully! Replace with grey_verifySnapshot().

Having followed the instruction you should alter the test as following:

EarlGrey.select(elementWithMatcher: grey_kindOfClass(AViewToSnapshotClass.self))
    .assert(grey_verifySnapshot())

That’s it! From now on the tests will verify whether selected view matches reference snapshot.

Device agnostic snapshots

Using grey_recordSnapshot() and grey_verifySnapshot() will not work when executing the tests against devices with differing resoultions and pixel densities. To enable such tests you should use grey_recordDeviceAgnosticSnapshot() and grey_verifyDeviceAgnosticSnapshot() APIs instead. They compare the snapshots paired by the test name and also device type, which means you have to separately record snapshots for all the supported device types.

Requirements

EarlGreySnapshots glues together two libraries:

Make sure to install them both alongside the project.

Installation

EarlGreySnapshots is available through CocoaPods. To install it, simply add following lines to your Podfile:

pod 'EarlGrey', '~> 1.9'
pod 'FBSnapshotTestCase', '~> 2.1'
pod 'EarlGreySnapshots', '~> 0.0.1'

Don’t forget to run pod install afterwards!

Example project

To run the example project, clone the repo, and run pod install from the Example directory first.

Credits

The project derives heavily from ideas found in Nimble Snapshots. Huge credits go to @ashfurrow and other maintainers.

Author

turekj, [email protected]

License

EarlGreySnapshots is available under the MIT license. See the LICENSE file for more info.