Skip to content

Commit c55f8a7

Browse files
author
Jon Petersson
committed
Rewrite screenshot tests to use new syntax
1 parent 2211f28 commit c55f8a7

8 files changed

+230
-13
lines changed

ios/MullvadVPN.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@
498498
7A3FD1B72AD54ABD0042BEA6 /* AnyTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BDEB982A98F4ED00F578F2 /* AnyTransport.swift */; };
499499
7A3FD1B82AD54AE60042BEA6 /* TimeServerProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BDEB9A2A98F58600F578F2 /* TimeServerProxy.swift */; };
500500
7A42DEC92A05164100B209BE /* SettingsInputCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A42DEC82A05164100B209BE /* SettingsInputCell.swift */; };
501+
7A45CFC32C05FF2F00D80B21 /* ScreenshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */; };
502+
7A45CFC62C05FF6A00D80B21 /* ScreenshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */; };
503+
7A45CFC72C071DD400D80B21 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D0C79D23F1CEBA00FE9BA7 /* SnapshotHelper.swift */; };
501504
7A516C2E2B6D357500BBD33D /* URL+Scoping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A516C2D2B6D357500BBD33D /* URL+Scoping.swift */; };
502505
7A516C3A2B7111A700BBD33D /* IPOverrideWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A516C392B7111A700BBD33D /* IPOverrideWrapper.swift */; };
503506
7A516C3C2B712F0B00BBD33D /* IPOverrideWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A516C3B2B712F0B00BBD33D /* IPOverrideWrapperTests.swift */; };
@@ -1854,6 +1857,7 @@
18541857
7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationBlockObserverSupport.swift; sourceTree = "<group>"; };
18551858
7A3FD1B42AD4465A0042BEA6 /* AppMessageHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMessageHandlerTests.swift; sourceTree = "<group>"; };
18561859
7A42DEC82A05164100B209BE /* SettingsInputCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInputCell.swift; sourceTree = "<group>"; };
1860+
7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotTests.swift; sourceTree = "<group>"; };
18571861
7A516C2D2B6D357500BBD33D /* URL+Scoping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Scoping.swift"; sourceTree = "<group>"; };
18581862
7A516C392B7111A700BBD33D /* IPOverrideWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPOverrideWrapper.swift; sourceTree = "<group>"; };
18591863
7A516C3B2B712F0B00BBD33D /* IPOverrideWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPOverrideWrapperTests.swift; sourceTree = "<group>"; };
@@ -3581,6 +3585,7 @@
35813585
58D0C79F23F1CECF00FE9BA7 /* Info.plist */,
35823586
58D0C7A023F1CECF00FE9BA7 /* MullvadVPNScreenshots.swift */,
35833587
58D0C79D23F1CEBA00FE9BA7 /* SnapshotHelper.swift */,
3588+
7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */,
35843589
);
35853590
path = MullvadVPNScreenshots;
35863591
sourceTree = "<group>";
@@ -5943,6 +5948,7 @@
59435948
buildActionMask = 2147483647;
59445949
files = (
59455950
58D0C7A223F1CECF00FE9BA7 /* MullvadVPNScreenshots.swift in Sources */,
5951+
7A45CFC32C05FF2F00D80B21 /* ScreenshotTests.swift in Sources */,
59465952
F0FADDEB2BE90AAE000D0B02 /* LaunchArguments.swift in Sources */,
59475953
7A0B311F2B303A11004B12E0 /* AccessbilityIdentifier.swift in Sources */,
59485954
58D0C79E23F1CEBA00FE9BA7 /* SnapshotHelper.swift in Sources */,
@@ -6080,6 +6086,7 @@
60806086
850201DD2B503D8C00EF8C96 /* SelectLocationPage.swift in Sources */,
60816087
85D039982BA4711800940E7F /* SettingsMigrationTests.swift in Sources */,
60826088
850201DB2B503D7700EF8C96 /* RelayTests.swift in Sources */,
6089+
7A45CFC62C05FF6A00D80B21 /* ScreenshotTests.swift in Sources */,
60836090
852D054D2BC3DE3A008578D2 /* APIAccessPage.swift in Sources */,
60846091
85139B2D2B84B4A700734217 /* OutOfTimePage.swift in Sources */,
60856092
852969362B4E9724007EAD4C /* AccessbilityIdentifier.swift in Sources */,
@@ -6097,6 +6104,7 @@
60976104
852969282B4D9C1F007EAD4C /* AccountTests.swift in Sources */,
60986105
8587A05D2B84D43100152938 /* ChangeLogAlert.swift in Sources */,
60996106
85FB5A102B6960A30015DCED /* AccountDeletionPage.swift in Sources */,
6107+
7A45CFC72C071DD400D80B21 /* SnapshotHelper.swift in Sources */,
61006108
85557B162B5ABBBE00795FE1 /* XCUIElementQuery+Extensions.swift in Sources */,
61016109
855D9F5B2B63E56B00D7C64D /* ProblemReportPage.swift in Sources */,
61026110
8529693A2B4F0238007EAD4C /* TermsOfServicePage.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
//
2+
// ScreenshotTests.swift
3+
// MullvadVPNScreenshots
4+
//
5+
// Created by Jon Petersson on 2024-05-28.
6+
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
7+
//
8+
9+
import XCTest
10+
11+
class ScreenshotTests: BaseUITestCase {
12+
override func setUp() {
13+
setupSnapshot(app, waitForAnimations: false)
14+
15+
let argumentsJsonString = try? LaunchArguments(
16+
target: .screenshots,
17+
areAnimationsDisabled: true
18+
).toJSON()
19+
app.launchEnvironment[LaunchArguments.tag] = argumentsJsonString
20+
21+
super.setUp()
22+
23+
agreeToTermsOfServiceIfShown()
24+
dismissChangeLogIfShown()
25+
26+
if !isLoggedIn() {
27+
login(accountNumber: hasTimeAccountNumber)
28+
}
29+
30+
if TunnelControlPage(app).connectionIsSecured {
31+
TunnelControlPage(app)
32+
.tapDisconnectButton()
33+
}
34+
}
35+
36+
func testTakeScreenshotOfSecuredConnection() throws {
37+
TunnelControlPage(app)
38+
.tapSelectLocationButton()
39+
40+
SelectLocationPage(app)
41+
.tapLocationCell(withName: "Sweden")
42+
43+
TunnelControlPage(app)
44+
.waitForSecureConnectionLabel()
45+
46+
snapshot("ConnectionSecured")
47+
}
48+
49+
func testTakeScreenshotOfQuantumSecuredConnection() throws {
50+
addTeardownBlock {
51+
HeaderBar(self.app)
52+
.tapSettingsButton()
53+
54+
SettingsPage(self.app)
55+
.tapVPNSettingsCell()
56+
57+
VPNSettingsPage(self.app)
58+
.tapQuantumResistantTunnelExpandButton()
59+
.tapQuantumResistantTunnelOnCell()
60+
}
61+
62+
HeaderBar(app)
63+
.tapSettingsButton()
64+
65+
SettingsPage(app)
66+
.tapVPNSettingsCell()
67+
68+
VPNSettingsPage(app)
69+
.tapQuantumResistantTunnelExpandButton()
70+
.tapQuantumResistantTunnelOnCell()
71+
.tapBackButton()
72+
73+
SettingsPage(app)
74+
.tapDoneButton()
75+
76+
TunnelControlPage(app)
77+
.tapSelectLocationButton()
78+
79+
SelectLocationPage(app)
80+
.tapLocationCell(withName: "Sweden")
81+
82+
TunnelControlPage(app)
83+
.waitForSecureConnectionLabel()
84+
85+
snapshot("QuantumConnectionSecured")
86+
}
87+
88+
func testTakeScreenshotOfCustomListSelected() throws {
89+
TunnelControlPage(app)
90+
.tapSelectLocationButton()
91+
92+
SelectLocationPage(app)
93+
.tapWhereStatusBarShouldBeToScrollToTopMostPosition()
94+
.tapCustomListEllipsisButton()
95+
.tapAddNewCustomList()
96+
97+
CustomListPage(app)
98+
.renameCustomList(name: "Low latency locations")
99+
.addOrEditLocations()
100+
101+
EditCustomListLocationsPage(app)
102+
.scrollToLocationWith(identifier: "se")
103+
.unfoldLocationwith(identifier: "se")
104+
.unfoldLocationwith(identifier: "se-got")
105+
.toggleLocationCheckmarkWith(identifier: "se-got-wg-101")
106+
.scrollToLocationWith(identifier: "de")
107+
.unfoldLocationwith(identifier: "de")
108+
.toggleLocationCheckmarkWith(identifier: "de-ber")
109+
.scrollToLocationWith(identifier: "fi")
110+
.toggleLocationCheckmarkWith(identifier: "fi")
111+
.tapBackButton(action: .add)
112+
113+
CustomListPage(app)
114+
.tapCreateListButton()
115+
116+
SelectLocationPage(app)
117+
.tapLocationCell(withName: "Low latency locations")
118+
119+
TunnelControlPage(app)
120+
.tapSelectLocationButton()
121+
122+
SelectLocationPage(app)
123+
.tapLocationCellExpandButton(withName: "Low latency locations")
124+
125+
snapshot("CustomListSelected")
126+
}
127+
128+
func testTakeScreenshotOfRelayFilter() throws {
129+
TunnelControlPage(app)
130+
.tapSelectLocationButton()
131+
132+
SelectLocationPage(app)
133+
.tapFilterButton()
134+
135+
SelectLocationFilterPage(app)
136+
.tapOwnershipCellExpandButton()
137+
.tapProvidersCellExpandButton()
138+
139+
snapshot("RelayFilter")
140+
}
141+
142+
func testTakeScreenshotOfVPNSettings() throws {
143+
HeaderBar(app)
144+
.tapSettingsButton()
145+
146+
SettingsPage(app)
147+
.tapVPNSettingsCell()
148+
149+
snapshot("VPNSettings")
150+
}
151+
152+
func testTakeScreenshotOfDNSSettings() throws {
153+
addTeardownBlock {
154+
DNSSettingsPage(self.app)
155+
.tapBlockAdsSwitch()
156+
.tapBlockTrackerSwitch()
157+
.tapBlockMalwareSwitch()
158+
.tapBlockAdultContentSwitch()
159+
.tapBlockGamblingSwitch()
160+
.tapBlockSocialMediaSwitch()
161+
}
162+
163+
HeaderBar(app)
164+
.tapSettingsButton()
165+
166+
SettingsPage(app)
167+
.tapVPNSettingsCell()
168+
169+
VPNSettingsPage(app)
170+
.tapDNSSettingsCell()
171+
172+
DNSSettingsPage(app)
173+
.tapDNSContentBlockersHeaderExpandButton()
174+
.tapBlockAdsSwitch()
175+
.tapBlockTrackerSwitch()
176+
.tapBlockMalwareSwitch()
177+
.tapBlockAdultContentSwitch()
178+
.tapBlockGamblingSwitch()
179+
.tapBlockSocialMediaSwitch()
180+
181+
snapshot("DNSSettings")
182+
}
183+
184+
func testTakeScreenshotOfAccount() throws {
185+
HeaderBar(app)
186+
.tapAccountButton()
187+
188+
snapshot("Account")
189+
}
190+
}

ios/MullvadVPNUITests/CustomListsTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CustomListsTests: LoggedInWithTimeUITestCase {
6565
EditCustomListLocationsPage(app)
6666
.scrollToLocationWith(identifier: "se")
6767
.toggleLocationCheckmarkWith(identifier: "se")
68-
.pressBackButton()
68+
.tapBackButton(action: .edit)
6969

7070
CustomListPage(app)
7171
.tapSaveListButton()
@@ -96,7 +96,7 @@ class CustomListsTests: LoggedInWithTimeUITestCase {
9696
.unfoldLocationwith(identifier: "se")
9797
.unfoldLocationwith(identifier: "se-got")
9898
.toggleLocationCheckmarkWith(identifier: "se-got-wg-001")
99-
.pressBackButton()
99+
.tapBackButton(action: .edit)
100100

101101
CustomListPage(app)
102102
.tapSaveListButton()

ios/MullvadVPNUITests/Pages/CustomListPage.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ class CustomListPage: Page {
3939
editCustomListNameCell.tap()
4040
// Select the entire text with a triple tap
4141
editCustomListNameCell.tap(withNumberOfTaps: 3, numberOfTouches: 1)
42-
// Tap the "delete" key on the on-screen keyboard, the case is sensitive
43-
app.keys["delete"].tap()
42+
// Tap the "delete" key on the on-screen keyboard, the case is sensitive.
43+
// However, on a simulator the keyboard isn't visible by default, so we
44+
// need to take that into consideration.
45+
if app.keys["delete"].isHittable {
46+
app.keys["delete"].tap()
47+
}
4448
editCustomListNameCell.typeText(name)
4549
return self
4650
}

ios/MullvadVPNUITests/Pages/DNSSettingsPage.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DNSSettingsPage: Page {
3838

3939
@discardableResult func tapDNSContentBlockersHeaderExpandButton() -> Self {
4040
let headerView = app.otherElements[AccessibilityIdentifier.dnsContentBlockersHeaderView]
41-
let expandButton = headerView.buttons[AccessibilityIdentifier.collapseButton]
41+
let expandButton = headerView.buttons[AccessibilityIdentifier.expandButton]
4242
expandButton.tap()
4343

4444
return self

ios/MullvadVPNUITests/Pages/EditCustomListLocationsPage.swift

+13-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import XCTest
1010

1111
class EditCustomListLocationsPage: Page {
12+
enum Action {
13+
case add, edit
14+
}
15+
1216
@discardableResult override init(_ app: XCUIApplication) {
1317
super.init(app)
1418

@@ -46,8 +50,15 @@ class EditCustomListLocationsPage: Page {
4650
return self
4751
}
4852

49-
@discardableResult func pressBackButton() -> Self {
50-
app.navigationBars["Edit locations"].buttons.firstMatch.tap()
53+
@discardableResult func tapBackButton(action: Action) -> Self {
54+
let navigationBarName = switch action {
55+
case .add:
56+
"Add locations"
57+
case .edit:
58+
"edit locations"
59+
}
60+
61+
app.navigationBars[navigationBarName].buttons.firstMatch.tap()
5162
return self
5263
}
5364
}

ios/MullvadVPNUITests/Pages/TunnelControlPage.swift

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class TunnelControlPage: Page {
1616
let protocolName: String
1717
}
1818

19+
var connectionIsSecured: Bool {
20+
app.staticTexts[AccessibilityIdentifier.connectionStatusConnectedLabel].exists
21+
}
22+
1923
/// Poll the "in address row" label for its updated values and output an array of ConnectionAttempt objects representing the connection attempts that have been communicated through the UI.
2024
/// - Parameters:
2125
/// - attemptsCount: number of connection attempts to look for

ios/MullvadVPNUITests/Pages/VPNSettingsPage.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class VPNSettingsPage: Page {
1414
super.init(app)
1515
}
1616

17-
private func cellExpandCollapseButton(_ cellAccessiblityIdentifier: AccessibilityIdentifier) -> XCUIElement {
17+
private func cellExpandButton(_ cellAccessiblityIdentifier: AccessibilityIdentifier) -> XCUIElement {
1818
let table = app.tables[AccessibilityIdentifier.vpnSettingsTableView]
1919
let matchingCells = table.otherElements.containing(.any, identifier: cellAccessiblityIdentifier.rawValue)
20-
let expandButton = matchingCells.buttons[AccessibilityIdentifier.collapseButton]
20+
let expandButton = matchingCells.buttons[AccessibilityIdentifier.expandButton]
2121

2222
return expandButton
2323
}
@@ -37,18 +37,18 @@ class VPNSettingsPage: Page {
3737
}
3838

3939
@discardableResult func tapWireGuardPortsExpandButton() -> Self {
40-
cellExpandCollapseButton(AccessibilityIdentifier.wireGuardPortsCell).tap()
40+
cellExpandButton(AccessibilityIdentifier.wireGuardPortsCell).tap()
4141
return self
4242
}
4343

4444
@discardableResult func tapWireGuardObfuscationExpandButton() -> Self {
45-
cellExpandCollapseButton(AccessibilityIdentifier.wireGuardObfuscationCell).tap()
45+
cellExpandButton(AccessibilityIdentifier.wireGuardObfuscationCell).tap()
4646

4747
return self
4848
}
4949

5050
@discardableResult func tapUDPOverTCPPortExpandButton() -> Self {
51-
cellExpandCollapseButton(AccessibilityIdentifier.udpOverTCPPortCell).tap()
51+
cellExpandButton(AccessibilityIdentifier.udpOverTCPPortCell).tap()
5252

5353
return self
5454
}
@@ -72,7 +72,7 @@ class VPNSettingsPage: Page {
7272
}
7373

7474
@discardableResult func tapQuantumResistantTunnelExpandButton() -> Self {
75-
cellExpandCollapseButton(AccessibilityIdentifier.quantumResistantTunnelCell).tap()
75+
cellExpandButton(AccessibilityIdentifier.quantumResistantTunnelCell).tap()
7676

7777
return self
7878
}

0 commit comments

Comments
 (0)