I would like to test my React Native application using screenshots. The UIAutomation javascript file will be executed by fastlane and should deliver me all subviews I need. This part works fine.
My main problem is that I don't understand how I may have an element clicked. Every example I found was plain objective-c and used standard elements for navigation like a tab bar. My application has a Burger Icon, which has a click event on the TouchableHighlight
which opens a menu. I am searching for a possibility to reference a single TouchableHighlight
element in order to interact with it.
Bonus points for such answers, which don't have me to write Objective-C.
Fastlane (more specific snapshot) has deprecated UI Automation for UI Tests. In case you need to update the gems, your UIA javascript won't work for UI Tests (which are written in Obj C or Swift)
https://github.com/fastlane/snapshot
Looks like someone else using React Native made a little progress with UI Testing and Snapshot: https://github.com/fastlane/snapshot/issues/267
I'm not familiar with fastlane, but you might want to give Jest a try since it's officially supported. They admittedly don't have full coverage, and it's quite possible you'll have to roll your own solution in some cases given how young react native is, but this ought to get you started on the right foot Snapshot Tests (iOS only)
Create a new project.
Test it works, launch welcome screen.
fastlane output:
Step 1: Add a new UI Test target to your project
Xcode Version 8.3.3 > Open NativeSnapshots.xcodeproj
Step 2: Add the ./fastlane/SnapshotHelper.swift to your UI Test target
Step 3: Call setupSnapshot(app) when launching your app
Open
NativeSnapshotsUITests/NativeSnapshotsUITests.swift
in Xcode.Replace:
With:
Step 4: Add
snapshot("0Launch")
to wherever you want to create the screenshotsAdd snapshot call in testExample() in UI Tests.
Edit the Snapfile to avoid a huge matrix.
It should be ready to go.
Copied from aj0strow