SUITCase can verify screenshots in five different ways while testing the User Interface of iOS, iPadOS, and tvOS apps in Simulator. It has been designed to be used with XCTest and written in Swift.
Built-in XCTest assertions are great for many cases when you automate user interface testing.
But some cases require testing appearance because XCUIElement
properties do not fully describe the interface.
SUITCase verifies screenshots to automate testing formatting texts, displaying images, switching themes, and much more.
SUITCase currently supports recording and testing apps in Simulator only.
SUITCase is easy to install with the Swift Package Manager. Navigate to project settings and add a package on Swift Packages page. Copy-Paste a link to this repository in the Choose Package Repository window. Continue configuring dependency as needed.
Finally, add the Environmental Variable IMAGES_DIR to your Scheme. If you want to keep your reference Images with your test code, you should probably set it to $(SOURCE_ROOT)/Images
XCTest
and SUITCase
SUITCase
(or replace XCTestCase
with SUITCase
if you change the existing class)verifyScreenshot()
to insert a screenshot assertion in test.setUp()
by adding screenshotComparisonRecordMode = true
line.import XCTest
import SUITCase
class AppearanceTests: SUITCase {
override func setUp() {
super.setUp()
// screenshotComparisonRecordMode = true
XCUIApplication().launch()
}
func testMainScreen() {
verifyScreenshot()
}
}
screenshotComparisonRecordMode = true
line.screenshotComparisonNamingStrategy
variable.withLabel
argument.screenshotComparisonNamingStrategy = .imageSize
XCUIDevice.shared.orientation = .portrait
verifyScreenshot(withLabel: "Portrait")
// Saves /Images/Reference/AppearanceTests/testMainScreen/Portrait/en_414x896.png
screenshotComparisonNamingStrategy = .deviceModelName
XCUIDevice.shared.orientation = .landscapeLeft
verifyScreenshot(withLabel: "Landscape")
// Saves /Images/Reference/AppearanceTests/testMainScreen/Landscape/en_iPhone_11.png
screenshotComparisonNamingStrategy = .manual
XCUIDevice.shared.orientation = .landscapeRight
verifyScreenshot(withLabel: "landscapeRight")
// Saves /Images/Reference/landscapeRight.png
screenshotComparisonDefaultThreshold
.
If unchanged, the default threshold is equal to 0.01, which means SUITCase allows a 1 percent difference between collected and referenced screenshots.withThreshold
argument.verifyScreenshot()
// The threshold is default and equals to 0.01
screenshotComparisonGlobalThreshold = 0.02
verifyScreenshot()
// The global threshold is now 0.02
verifyScreenshot(withThreshold: 0.03)
// The global threshold is still 0.02, but for this screenshot comparison threshold equals to 0.03
ofElement
argument.
The reference image will be cropped by this element frame.withoutElement
argument.withoutQuery
argument allows you to erase multiple elements at once.verifyScreenshot(ofElement: app.buttons["New"])
verifyScreenshot(withoutElement: app.tabBars.element)
verifyScreenshot(withoutQuery: app.images.matching(identifier: "GIF"))
withMethod
argument: verifyScreenshot(method: SUITCaseMethodStrict()])
SUITCaseMethodStrict()
SUITCaseMethodWithTolerance(_: Double = 0.1)
SUITCaseMethodGreyscaleColor(tolerance: Double = 0.1)
SUITCaseMethodDNA(tolerance: Double = 0.1, scaleFactor: Double = 0.03)
SUITCaseMethodAverageColor()
averageColorIs(_ uiColor: UIColor, tolerance: Double = 0.1)
XCTAssert(app.buttons["Red Button"].averageColorIs(.red))
SUITCase is the open-source software under the MPL 2.0 license.
link |
Stars: 20 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics