Skip to content

Commit 51d886e

Browse files
Merge pull request #536 from Iterable/tapash/mob-4101-session-tracking-ui-tests
[MOB-4101] - Add UI tests for session tracking.
2 parents eac577f + 6b30dbf commit 51d886e

File tree

4 files changed

+168
-1
lines changed

4 files changed

+168
-1
lines changed

swift-sdk.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
55DD207F26A0D83800773CC7 /* IterableAuthManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55DD207E26A0D83800773CC7 /* IterableAuthManagerProtocol.swift */; };
3939
55E02D39253F8D86009DB8BC /* WebViewProtocolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E02D38253F8D86009DB8BC /* WebViewProtocolTests.swift */; };
4040
55E6F462238E066400808BCE /* DeepLinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E6F45E238E066400808BCE /* DeepLinkTests.swift */; };
41+
5B49BB3E27CFB71500E6F00C /* PopupInboxSessionUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B49BB3D27CFB71500E6F00C /* PopupInboxSessionUITests.swift */; };
42+
5B6C3C1127CE871F00B9A753 /* NavInboxSessionUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B6C3C1027CE871F00B9A753 /* NavInboxSessionUITests.swift */; };
4143
AC02480822791E2100495FB9 /* IterableInboxNavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC02480722791E2100495FB9 /* IterableInboxNavigationViewController.swift */; };
4244
AC02CAA6234E50B5006617E0 /* RegistrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC02CAA5234E50B5006617E0 /* RegistrationTests.swift */; };
4345
AC03094B21E532470003A288 /* InAppPersistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC03094A21E532470003A288 /* InAppPersistence.swift */; };
@@ -403,6 +405,8 @@
403405
55DD207E26A0D83800773CC7 /* IterableAuthManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableAuthManagerProtocol.swift; sourceTree = "<group>"; };
404406
55E02D38253F8D86009DB8BC /* WebViewProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewProtocolTests.swift; sourceTree = "<group>"; };
405407
55E6F45E238E066400808BCE /* DeepLinkTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeepLinkTests.swift; sourceTree = "<group>"; };
408+
5B49BB3D27CFB71500E6F00C /* PopupInboxSessionUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopupInboxSessionUITests.swift; sourceTree = "<group>"; };
409+
5B6C3C1027CE871F00B9A753 /* NavInboxSessionUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavInboxSessionUITests.swift; sourceTree = "<group>"; };
406410
AC02480722791E2100495FB9 /* IterableInboxNavigationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableInboxNavigationViewController.swift; sourceTree = "<group>"; };
407411
AC02CAA5234E50B5006617E0 /* RegistrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationTests.swift; sourceTree = "<group>"; };
408412
AC03094A21E532470003A288 /* InAppPersistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InAppPersistence.swift; sourceTree = "<group>"; };
@@ -1215,6 +1219,8 @@
12151219
ACBDDE5B23C4EDEC0008CC4D /* InboxCustomizationTests.swift */,
12161220
ACDA977023159C39004C412E /* InboxUITests.swift */,
12171221
ACC6A851232407B5003CC4BE /* InboxUITestsHelper.swift */,
1222+
5B6C3C1027CE871F00B9A753 /* NavInboxSessionUITests.swift */,
1223+
5B49BB3D27CFB71500E6F00C /* PopupInboxSessionUITests.swift */,
12181224
ACDA977223159C39004C412E /* Info.plist */,
12191225
);
12201226
path = "inbox-ui-tests";
@@ -1972,9 +1978,11 @@
19721978
files = (
19731979
ACBDDE5C23C4EDEC0008CC4D /* InboxCustomizationTests.swift in Sources */,
19741980
ACC6A852232407B5003CC4BE /* InboxUITestsHelper.swift in Sources */,
1981+
5B49BB3E27CFB71500E6F00C /* PopupInboxSessionUITests.swift in Sources */,
19751982
ACFF428824656A2000FDF10D /* CommonMocks.swift in Sources */,
19761983
AC19520D231D9AC600CD5B61 /* Common.swift in Sources */,
19771984
AC195210231DAD6B00CD5B61 /* TestUtils.swift in Sources */,
1985+
5B6C3C1127CE871F00B9A753 /* NavInboxSessionUITests.swift in Sources */,
19781986
ACDA977123159C39004C412E /* InboxUITests.swift in Sources */,
19791987
ACC6A8502323910D003CC4BE /* UITestsHelper.swift in Sources */,
19801988
ACFF4287246569D300FDF10D /* CommonExtensions.swift in Sources */,

tests/inbox-ui-tests/InboxUITestsHelper.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,25 @@ extension IterableInboxUITestsProtocol where Self: XCTestCase {
2727
return request.body! as! [String: Any]
2828
}
2929

30+
func count(forEvent event: String) -> Int {
31+
allEventRows(forEvent: event).count
32+
}
33+
3034
func serializableRequest(forEvent event: String) -> SerializableRequest {
3135
let serializedString = lastElement(forEvent: event).staticTexts["serializedString"].label
3236
return SerializableRequest.create(from: serializedString)
3337
}
3438

3539
private func lastElement(forEvent event: String) -> XCUIElement {
36-
let eventRows = app.tables.cells.containing(.staticText, identifier: Const.apiPath + event)
40+
let eventRows = allEventRows(forEvent: event)
3741
let count = eventRows.count
3842
return eventRows.element(boundBy: count - 1)
3943
}
4044

45+
private func allEventRows(forEvent event: String) -> XCUIElementQuery {
46+
app.tables.cells.containing(.staticText, identifier: Const.apiPath + event)
47+
}
48+
4149
func gotoTab(_ tabName: TabName) {
4250
app.gotoTab(tabName.rawValue)
4351
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// Copyright © 2022 Iterable. All rights reserved.
3+
//
4+
5+
import XCTest
6+
7+
@testable import IterableSDK
8+
9+
class NavInboxSessionUITests: XCTestCase, IterableInboxUITestsProtocol {
10+
lazy var app: XCUIApplication! = UITestsGlobal.application
11+
12+
override func setUp() {
13+
// In UI tests it is usually best to stop immediately when a failure occurs.
14+
continueAfterFailure = false
15+
16+
clearNetwork()
17+
}
18+
19+
func test_simple_tab_switch() {
20+
gotoTab(.home)
21+
app.button(withText: "Load Dataset 1").tap()
22+
23+
gotoTab(.customInbox)
24+
sleep(1)
25+
gotoTab(.network)
26+
27+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 1)
28+
29+
let dict = body(forEvent: Const.Path.trackInboxSession)
30+
let impressions = dict[keyPath: KeyPath(keys: JsonKey.impressions)] as! [[String: Any]]
31+
XCTAssertEqual(impressions.count, 3)
32+
}
33+
34+
func test_view_messages_continues_session() {
35+
gotoTab(.home)
36+
app.button(withText: "Load Dataset 1").tap()
37+
38+
gotoTab(.customInbox)
39+
// view first message
40+
app.tableCell(withText: "title1").waitToAppear().tap()
41+
app.navButton(withText: "Custom Inbox").waitToAppear().tap()
42+
// view second message
43+
app.tableCell(withText: "title2").waitToAppear().tap()
44+
app.navButton(withText: "Custom Inbox").waitToAppear().tap()
45+
46+
gotoTab(.network)
47+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 1)
48+
49+
let dict = body(forEvent: Const.Path.trackInboxSession)
50+
let impressions = dict[keyPath: KeyPath(keys: JsonKey.impressions)] as! [[String: Any]]
51+
XCTAssertEqual(impressions.count, 3)
52+
}
53+
54+
func test_currently_viewing_message_continues_session() {
55+
gotoTab(.home)
56+
app.button(withText: "Load Dataset 1").tap()
57+
58+
gotoTab(.customInbox)
59+
// view first message
60+
app.tableCell(withText: "title1").waitToAppear().tap()
61+
gotoTab(.network)
62+
app.swipeUp()
63+
app.swipeUp()
64+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 1)
65+
66+
let dict = body(forEvent: Const.Path.trackInboxSession)
67+
let impressions = dict[keyPath: KeyPath(keys: JsonKey.impressions)] as! [[String: Any]]
68+
XCTAssertEqual(impressions.count, 3)
69+
70+
// remove the showing message
71+
gotoTab(.customInbox)
72+
app.navButton(withText: "Custom Inbox").waitToAppear().tap()
73+
}
74+
75+
func test_back_to_viewing_message_starts_new_session() {
76+
gotoTab(.home)
77+
app.button(withText: "Load Dataset 1").tap()
78+
79+
gotoTab(.customInbox)
80+
// view first message
81+
app.tableCell(withText: "title1").waitToAppear().tap()
82+
gotoTab(.network)
83+
app.swipeUp()
84+
app.swipeUp()
85+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 1)
86+
87+
// back to inbox
88+
gotoTab(.customInbox)
89+
gotoTab(.network)
90+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 2)
91+
92+
// remove the showing message
93+
gotoTab(.customInbox)
94+
app.navButton(withText: "Custom Inbox").waitToAppear().tap()
95+
}
96+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// Copyright © 2022 Iterable. All rights reserved.
3+
//
4+
5+
import XCTest
6+
7+
@testable import IterableSDK
8+
9+
class PopupInboxSessionUITests: XCTestCase, IterableInboxUITestsProtocol {
10+
lazy var app: XCUIApplication! = UITestsGlobal.application
11+
12+
override func setUp() {
13+
// In UI tests it is usually best to stop immediately when a failure occurs.
14+
continueAfterFailure = false
15+
16+
clearNetwork()
17+
}
18+
19+
func test_simple_tab_switch() {
20+
gotoTab(.home)
21+
app.button(withText: "Load Dataset 1").tap()
22+
23+
gotoTab(.inbox)
24+
sleep(1)
25+
gotoTab(.network)
26+
27+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 1)
28+
29+
let dict = body(forEvent: Const.Path.trackInboxSession)
30+
let impressions = dict[keyPath: KeyPath(keys: JsonKey.impressions)] as! [[String: Any]]
31+
XCTAssertEqual(impressions.count, 3)
32+
}
33+
34+
func test_view_messages_continues_session() {
35+
gotoTab(.home)
36+
app.button(withText: "Load Dataset 1").tap()
37+
38+
gotoTab(.inbox)
39+
// view first message
40+
app.tableCell(withText: "title1").waitToAppear().tap()
41+
app.link(withText: "Click Here1").waitToAppear().tap()
42+
// view second message
43+
app.tableCell(withText: "title2").waitToAppear().tap()
44+
app.link(withText: "Click Here2").waitToAppear().tap()
45+
46+
gotoTab(.network)
47+
app.swipeUp()
48+
app.swipeUp()
49+
XCTAssertEqual(count(forEvent: Const.Path.trackInboxSession), 1)
50+
51+
let dict = body(forEvent: Const.Path.trackInboxSession)
52+
let impressions = dict[keyPath: KeyPath(keys: JsonKey.impressions)] as! [[String: Any]]
53+
XCTAssertEqual(impressions.count, 3)
54+
}
55+
}

0 commit comments

Comments
 (0)