forked from zelo72/mastodon-ios
feat: add UITests for snapshots
This commit is contained in:
parent
a73e65e903
commit
37f4bc1fc9
AppStoreSnapshotTestPlan.xctestplan
Mastodon.xcodeproj
MastodonUITests
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"configurations" : [
|
||||
{
|
||||
"id" : "E27ADCCD-D2DF-4255-81D1-21CFC3C33254",
|
||||
"name" : "Configuration 1",
|
||||
"options" : {
|
||||
|
||||
}
|
||||
}
|
||||
],
|
||||
"defaultOptions" : {
|
||||
"testTimeoutsEnabled" : true
|
||||
},
|
||||
"testTargets" : [
|
||||
{
|
||||
"selectedTests" : [
|
||||
"MastodonUISnapshotTests\/testSnapshot()"
|
||||
],
|
||||
"target" : {
|
||||
"containerPath" : "container:Mastodon.xcodeproj",
|
||||
"identifier" : "DB427DF225BAA00100D1B89D",
|
||||
"name" : "MastodonUITests"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 1
|
||||
}
|
|
@ -244,6 +244,7 @@
|
|||
DB45FB0F25CA87D0005A8AC7 /* AuthenticationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB45FB0E25CA87D0005A8AC7 /* AuthenticationService.swift */; };
|
||||
DB45FB1D25CA9D23005A8AC7 /* APIService+HomeTimeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB45FB1C25CA9D23005A8AC7 /* APIService+HomeTimeline.swift */; };
|
||||
DB47229725F9EFAD00DA7F53 /* NSManagedObjectContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB47229625F9EFAD00DA7F53 /* NSManagedObjectContext.swift */; };
|
||||
DB47AB6227CF752B00CD73C7 /* MastodonUISnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB47AB6127CF752B00CD73C7 /* MastodonUISnapshotTests.swift */; };
|
||||
DB482A3F261331E8008AE74C /* UserTimelineViewModel+State.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB482A3E261331E8008AE74C /* UserTimelineViewModel+State.swift */; };
|
||||
DB482A4B261340A7008AE74C /* APIService+UserTimeline.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB482A4A261340A7008AE74C /* APIService+UserTimeline.swift */; };
|
||||
DB4924E226312AB200E9DB22 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB4924E126312AB200E9DB22 /* NotificationService.swift */; };
|
||||
|
@ -969,6 +970,8 @@
|
|||
DB45FB0E25CA87D0005A8AC7 /* AuthenticationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationService.swift; sourceTree = "<group>"; };
|
||||
DB45FB1C25CA9D23005A8AC7 /* APIService+HomeTimeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+HomeTimeline.swift"; sourceTree = "<group>"; };
|
||||
DB47229625F9EFAD00DA7F53 /* NSManagedObjectContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSManagedObjectContext.swift; sourceTree = "<group>"; };
|
||||
DB47AB6127CF752B00CD73C7 /* MastodonUISnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonUISnapshotTests.swift; sourceTree = "<group>"; };
|
||||
DB47AB6327CF858400CD73C7 /* AppStoreSnapshotTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = AppStoreSnapshotTestPlan.xctestplan; sourceTree = "<group>"; };
|
||||
DB482A3E261331E8008AE74C /* UserTimelineViewModel+State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserTimelineViewModel+State.swift"; sourceTree = "<group>"; };
|
||||
DB482A4A261340A7008AE74C /* APIService+UserTimeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "APIService+UserTimeline.swift"; sourceTree = "<group>"; };
|
||||
DB4924E126312AB200E9DB22 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
|
||||
|
@ -2079,6 +2082,7 @@
|
|||
children = (
|
||||
DBF53F5F25C14E88008AAC7B /* Mastodon.xctestplan */,
|
||||
DBF53F6025C14E9D008AAC7B /* MastodonSDK.xctestplan */,
|
||||
DB47AB6327CF858400CD73C7 /* AppStoreSnapshotTestPlan.xctestplan */,
|
||||
DB3D0FED25BAA42200EAA174 /* MastodonSDK */,
|
||||
DB427DD425BAA00100D1B89D /* Mastodon */,
|
||||
DB427DEB25BAA00100D1B89D /* MastodonTests */,
|
||||
|
@ -2145,6 +2149,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
DB427DF725BAA00100D1B89D /* MastodonUITests.swift */,
|
||||
DB47AB6127CF752B00CD73C7 /* MastodonUISnapshotTests.swift */,
|
||||
DB427DF925BAA00100D1B89D /* Info.plist */,
|
||||
);
|
||||
path = MastodonUITests;
|
||||
|
@ -4273,6 +4278,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
DB47AB6227CF752B00CD73C7 /* MastodonUISnapshotTests.swift in Sources */,
|
||||
DB427DF825BAA00100D1B89D /* MastodonUITests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -48,16 +48,6 @@
|
|||
ReferencedContainer = "container:Mastodon.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "DB89B9F525C10FD0008580ED"
|
||||
BuildableName = "CoreDataStackTests.xctest"
|
||||
BlueprintName = "CoreDataStackTests"
|
||||
ReferencedContainer = "container:Mastodon.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
reference = "container:Mastodon/Mastodon.xctestplan"
|
||||
default = "YES">
|
||||
</TestPlanReference>
|
||||
<TestPlanReference
|
||||
reference = "container:AppStoreSnapshotTestPlan copy.xctestplan">
|
||||
</TestPlanReference>
|
||||
</TestPlans>
|
||||
<Testables>
|
||||
<TestableReference
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<key>AppShared.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>29</integer>
|
||||
<integer>21</integer>
|
||||
</dict>
|
||||
<key>CoreDataStack.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
|
@ -24,6 +24,11 @@
|
|||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>Mastodon - Snapshot.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>2</integer>
|
||||
</dict>
|
||||
<key>Mastodon - ar.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
|
@ -97,7 +102,7 @@
|
|||
<key>MastodonIntent.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>30</integer>
|
||||
<integer>23</integer>
|
||||
</dict>
|
||||
<key>MastodonIntents.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
|
@ -112,12 +117,12 @@
|
|||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>2</integer>
|
||||
<integer>3</integer>
|
||||
</dict>
|
||||
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>28</integer>
|
||||
<integer>24</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
//
|
||||
// MastodonUISnapshotTests.swift
|
||||
// MastodonUITests
|
||||
//
|
||||
// Created by MainasuK on 2022-3-2.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
extension UInt64 {
|
||||
static let second: UInt64 = 1_000_000_000
|
||||
}
|
||||
|
||||
@MainActor
|
||||
class MastodonUISnapshotTests: XCTestCase {
|
||||
|
||||
override func setUpWithError() throws {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override class func tearDown() {
|
||||
super.tearDown()
|
||||
let app = XCUIApplication()
|
||||
print(app.debugDescription)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MastodonUISnapshotTests {
|
||||
|
||||
func testSmoke() async throws {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
||||
// Any test you write for XCTest can be annotated as throws and async.
|
||||
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
|
||||
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MastodonUISnapshotTests {
|
||||
|
||||
func testSnapshot() async throws {
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
try await snapshotHome()
|
||||
try await snapshotSearch()
|
||||
try await snapshotProfile()
|
||||
|
||||
}
|
||||
|
||||
func snapshotHome() async throws {
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
func tapTab() {
|
||||
XCTAssert(app.tabBars.buttons["Home"].exists)
|
||||
app.tabBars.buttons["Home"].tap()
|
||||
}
|
||||
|
||||
tapTab()
|
||||
try await Task.sleep(nanoseconds: .second * 3)
|
||||
takeSnapshot(name: "Home - 1")
|
||||
|
||||
tapTab()
|
||||
try await Task.sleep(nanoseconds: .second * 3)
|
||||
takeSnapshot(name: "Home - 2")
|
||||
|
||||
tapTab()
|
||||
try await Task.sleep(nanoseconds: .second * 3)
|
||||
takeSnapshot(name: "Home - 3")
|
||||
}
|
||||
|
||||
func snapshotSearch() async throws {
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
func tapTab() {
|
||||
XCTAssert(app.tabBars.buttons["Search"].exists)
|
||||
app.tabBars.buttons["Search"].tap()
|
||||
}
|
||||
|
||||
tapTab()
|
||||
try await Task.sleep(nanoseconds: .second * 3)
|
||||
takeSnapshot(name: "Search - 1")
|
||||
|
||||
tapTab()
|
||||
try await Task.sleep(nanoseconds: .second * 3)
|
||||
takeSnapshot(name: "Search - 2")
|
||||
|
||||
tapTab()
|
||||
try await Task.sleep(nanoseconds: .second * 3)
|
||||
takeSnapshot(name: "Search - 3")
|
||||
}
|
||||
|
||||
func snapshotProfile() async throws {
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
// Go to Search tab
|
||||
XCTAssert(app.tabBars.buttons["Search"].exists)
|
||||
app.tabBars.buttons["Search"].tap()
|
||||
|
||||
// Tap and search user
|
||||
let searchField = app.navigationBars.searchFields.firstMatch
|
||||
XCTAssert(searchField.waitForExistence(timeout: 5))
|
||||
searchField.tap()
|
||||
searchField.typeText("@dentaku@fnordon.de")
|
||||
|
||||
// Tap the cell and display user profile
|
||||
let cell = app.tables.cells.firstMatch
|
||||
XCTAssert(cell.waitForExistence(timeout: 5))
|
||||
cell.tap()
|
||||
|
||||
try await Task.sleep(nanoseconds: .second * 5)
|
||||
|
||||
takeSnapshot(name: "Profile")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension MastodonUISnapshotTests {
|
||||
func takeSnapshot(name: String) {
|
||||
let snapshot = XCUIScreen.main.screenshot()
|
||||
let attachment = XCTAttachment(screenshot: snapshot)
|
||||
attachment.lifetime = .keepAlways
|
||||
add(attachment)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue