Skip to content

Commit

Permalink
Rewrite screenshot tests to use new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed May 29, 2024
1 parent 2211f28 commit 640ead4
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 13 deletions.
8 changes: 8 additions & 0 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@
7A3FD1B72AD54ABD0042BEA6 /* AnyTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BDEB982A98F4ED00F578F2 /* AnyTransport.swift */; };
7A3FD1B82AD54AE60042BEA6 /* TimeServerProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BDEB9A2A98F58600F578F2 /* TimeServerProxy.swift */; };
7A42DEC92A05164100B209BE /* SettingsInputCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A42DEC82A05164100B209BE /* SettingsInputCell.swift */; };
7A45CFC32C05FF2F00D80B21 /* ScreenshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */; };
7A45CFC62C05FF6A00D80B21 /* ScreenshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */; };
7A45CFC72C071DD400D80B21 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58D0C79D23F1CEBA00FE9BA7 /* SnapshotHelper.swift */; };
7A516C2E2B6D357500BBD33D /* URL+Scoping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A516C2D2B6D357500BBD33D /* URL+Scoping.swift */; };
7A516C3A2B7111A700BBD33D /* IPOverrideWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A516C392B7111A700BBD33D /* IPOverrideWrapper.swift */; };
7A516C3C2B712F0B00BBD33D /* IPOverrideWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A516C3B2B712F0B00BBD33D /* IPOverrideWrapperTests.swift */; };
Expand Down Expand Up @@ -1854,6 +1857,7 @@
7A3353962AAA0F8600F0A71C /* OperationBlockObserverSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OperationBlockObserverSupport.swift; sourceTree = "<group>"; };
7A3FD1B42AD4465A0042BEA6 /* AppMessageHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppMessageHandlerTests.swift; sourceTree = "<group>"; };
7A42DEC82A05164100B209BE /* SettingsInputCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInputCell.swift; sourceTree = "<group>"; };
7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotTests.swift; sourceTree = "<group>"; };
7A516C2D2B6D357500BBD33D /* URL+Scoping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Scoping.swift"; sourceTree = "<group>"; };
7A516C392B7111A700BBD33D /* IPOverrideWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPOverrideWrapper.swift; sourceTree = "<group>"; };
7A516C3B2B712F0B00BBD33D /* IPOverrideWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPOverrideWrapperTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3581,6 +3585,7 @@
58D0C79F23F1CECF00FE9BA7 /* Info.plist */,
58D0C7A023F1CECF00FE9BA7 /* MullvadVPNScreenshots.swift */,
58D0C79D23F1CEBA00FE9BA7 /* SnapshotHelper.swift */,
7A45CFC22C05FF2F00D80B21 /* ScreenshotTests.swift */,
);
path = MullvadVPNScreenshots;
sourceTree = "<group>";
Expand Down Expand Up @@ -5943,6 +5948,7 @@
buildActionMask = 2147483647;
files = (
58D0C7A223F1CECF00FE9BA7 /* MullvadVPNScreenshots.swift in Sources */,
7A45CFC32C05FF2F00D80B21 /* ScreenshotTests.swift in Sources */,
F0FADDEB2BE90AAE000D0B02 /* LaunchArguments.swift in Sources */,
7A0B311F2B303A11004B12E0 /* AccessbilityIdentifier.swift in Sources */,
58D0C79E23F1CEBA00FE9BA7 /* SnapshotHelper.swift in Sources */,
Expand Down Expand Up @@ -6080,6 +6086,7 @@
850201DD2B503D8C00EF8C96 /* SelectLocationPage.swift in Sources */,
85D039982BA4711800940E7F /* SettingsMigrationTests.swift in Sources */,
850201DB2B503D7700EF8C96 /* RelayTests.swift in Sources */,
7A45CFC62C05FF6A00D80B21 /* ScreenshotTests.swift in Sources */,
852D054D2BC3DE3A008578D2 /* APIAccessPage.swift in Sources */,
85139B2D2B84B4A700734217 /* OutOfTimePage.swift in Sources */,
852969362B4E9724007EAD4C /* AccessbilityIdentifier.swift in Sources */,
Expand All @@ -6097,6 +6104,7 @@
852969282B4D9C1F007EAD4C /* AccountTests.swift in Sources */,
8587A05D2B84D43100152938 /* ChangeLogAlert.swift in Sources */,
85FB5A102B6960A30015DCED /* AccountDeletionPage.swift in Sources */,
7A45CFC72C071DD400D80B21 /* SnapshotHelper.swift in Sources */,
85557B162B5ABBBE00795FE1 /* XCUIElementQuery+Extensions.swift in Sources */,
855D9F5B2B63E56B00D7C64D /* ProblemReportPage.swift in Sources */,
8529693A2B4F0238007EAD4C /* TermsOfServicePage.swift in Sources */,
Expand Down
190 changes: 190 additions & 0 deletions ios/MullvadVPNScreenshots/ScreenshotTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
//
// ScreenshotTests.swift
// MullvadVPNScreenshots
//
// Created by Jon Petersson on 2024-05-28.
// Copyright © 2024 Mullvad VPN AB. All rights reserved.
//

import XCTest

class ScreenshotTests: BaseUITestCase {

Check failure on line 11 in ios/MullvadVPNScreenshots/ScreenshotTests.swift

View workflow job for this annotation

GitHub Actions / Unit tests

cannot find type 'BaseUITestCase' in scope
override func setUp() {

Check failure on line 12 in ios/MullvadVPNScreenshots/ScreenshotTests.swift

View workflow job for this annotation

GitHub Actions / Unit tests

method does not override any method from its superclass
setupSnapshot(app, waitForAnimations: false)

let argumentsJsonString = try? LaunchArguments(
target: .screenshots,
areAnimationsDisabled: true
).toJSON()
app.launchEnvironment[LaunchArguments.tag] = argumentsJsonString

super.setUp()

agreeToTermsOfServiceIfShown()
dismissChangeLogIfShown()

if !isLoggedIn() {
login(accountNumber: hasTimeAccountNumber)
}

if TunnelControlPage(app).connectionIsSecured {
TunnelControlPage(app)
.tapDisconnectButton()
}
}

func testTakeScreenshotOfSecuredConnection() throws {
TunnelControlPage(app)
.tapSelectLocationButton()

SelectLocationPage(app)
.tapLocationCell(withName: "Sweden")

TunnelControlPage(app)
.waitForSecureConnectionLabel()

snapshot("ConnectionSecured")
}

func testTakeScreenshotOfQuantumSecuredConnection() throws {
addTeardownBlock {
HeaderBar(self.app)
.tapSettingsButton()

SettingsPage(self.app)
.tapVPNSettingsCell()

VPNSettingsPage(self.app)
.tapQuantumResistantTunnelExpandButton()
.tapQuantumResistantTunnelOnCell()
}

HeaderBar(app)
.tapSettingsButton()

SettingsPage(app)
.tapVPNSettingsCell()

VPNSettingsPage(app)
.tapQuantumResistantTunnelExpandButton()
.tapQuantumResistantTunnelOnCell()
.tapBackButton()

SettingsPage(app)
.tapDoneButton()

TunnelControlPage(app)
.tapSelectLocationButton()

SelectLocationPage(app)
.tapLocationCell(withName: "Sweden")

TunnelControlPage(app)
.waitForSecureConnectionLabel()

snapshot("QuantumConnectionSecured")
}

func testTakeScreenshotOfCustomListSelected() throws {
TunnelControlPage(app)
.tapSelectLocationButton()

SelectLocationPage(app)
.tapWhereStatusBarShouldBeToScrollToTopMostPosition()
.tapCustomListEllipsisButton()
.tapAddNewCustomList()

CustomListPage(app)
.renameCustomList(name: "Low latency locations")
.addOrEditLocations()

EditCustomListLocationsPage(app)
.scrollToLocationWith(identifier: "se")
.unfoldLocationwith(identifier: "se")
.unfoldLocationwith(identifier: "se-got")
.toggleLocationCheckmarkWith(identifier: "se-got-wg-101")
.scrollToLocationWith(identifier: "de")
.unfoldLocationwith(identifier: "de")
.toggleLocationCheckmarkWith(identifier: "de-ber")
.scrollToLocationWith(identifier: "fi")
.toggleLocationCheckmarkWith(identifier: "fi")
.tapBackButton(action: .add)

CustomListPage(app)
.tapCreateListButton()

SelectLocationPage(app)
.tapLocationCell(withName: "Low latency locations")

TunnelControlPage(app)
.tapSelectLocationButton()

SelectLocationPage(app)
.tapLocationCellExpandButton(withName: "Low latency locations")

snapshot("CustomListSelected")
}

func testTakeScreenshotOfRelayFilter() throws {
TunnelControlPage(app)
.tapSelectLocationButton()

SelectLocationPage(app)
.tapFilterButton()

SelectLocationFilterPage(app)
.tapOwnershipCellExpandButton()
.tapProvidersCellExpandButton()

snapshot("RelayFilter")
}

func testTakeScreenshotOfVPNSettings() throws {
HeaderBar(app)
.tapSettingsButton()

SettingsPage(app)
.tapVPNSettingsCell()

snapshot("VPNSettings")
}

func testTakeScreenshotOfDNSSettings() throws {
addTeardownBlock {
DNSSettingsPage(self.app)
.tapBlockAdsSwitch()
.tapBlockTrackerSwitch()
.tapBlockMalwareSwitch()
.tapBlockAdultContentSwitch()
.tapBlockGamblingSwitch()
.tapBlockSocialMediaSwitch()
}

HeaderBar(app)
.tapSettingsButton()

SettingsPage(app)
.tapVPNSettingsCell()

VPNSettingsPage(app)
.tapDNSSettingsCell()

DNSSettingsPage(app)
.tapDNSContentBlockersHeaderExpandButton()
.tapBlockAdsSwitch()
.tapBlockTrackerSwitch()
.tapBlockMalwareSwitch()
.tapBlockAdultContentSwitch()
.tapBlockGamblingSwitch()
.tapBlockSocialMediaSwitch()

snapshot("DNSSettings")
}

func testTakeScreenshotOfAccount() throws {
HeaderBar(app)
.tapAccountButton()

snapshot("Account")
}
}
4 changes: 2 additions & 2 deletions ios/MullvadVPNUITests/CustomListsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CustomListsTests: LoggedInWithTimeUITestCase {
EditCustomListLocationsPage(app)
.scrollToLocationWith(identifier: "se")
.toggleLocationCheckmarkWith(identifier: "se")
.pressBackButton()
.tapBackButton(action: .edit)

CustomListPage(app)
.tapSaveListButton()
Expand Down Expand Up @@ -96,7 +96,7 @@ class CustomListsTests: LoggedInWithTimeUITestCase {
.unfoldLocationwith(identifier: "se")
.unfoldLocationwith(identifier: "se-got")
.toggleLocationCheckmarkWith(identifier: "se-got-wg-001")
.pressBackButton()
.tapBackButton(action: .edit)

CustomListPage(app)
.tapSaveListButton()
Expand Down
8 changes: 6 additions & 2 deletions ios/MullvadVPNUITests/Pages/CustomListPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ class CustomListPage: Page {
editCustomListNameCell.tap()
// Select the entire text with a triple tap
editCustomListNameCell.tap(withNumberOfTaps: 3, numberOfTouches: 1)
// Tap the "delete" key on the on-screen keyboard, the case is sensitive
app.keys["delete"].tap()
// Tap the "delete" key on the on-screen keyboard, the case is sensitive.
// However, on a simulator the keyboard isn't visible by default, so we
// need to take that into consideration.
if app.keys["delete"].isHittable {
app.keys["delete"].tap()
}
editCustomListNameCell.typeText(name)
return self
}
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPNUITests/Pages/DNSSettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DNSSettingsPage: Page {

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

return self
Expand Down
15 changes: 13 additions & 2 deletions ios/MullvadVPNUITests/Pages/EditCustomListLocationsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import XCTest

class EditCustomListLocationsPage: Page {
enum Action {
case add, edit
}

@discardableResult override init(_ app: XCUIApplication) {
super.init(app)

Expand Down Expand Up @@ -46,8 +50,15 @@ class EditCustomListLocationsPage: Page {
return self
}

@discardableResult func pressBackButton() -> Self {
app.navigationBars["Edit locations"].buttons.firstMatch.tap()
@discardableResult func tapBackButton(action: Action) -> Self {
let navigationBarName = switch action {
case .add:
"Add locations"
case .edit:
"Edit locations"
}

app.navigationBars[navigationBarName].buttons.firstMatch.tap()
return self
}
}
4 changes: 4 additions & 0 deletions ios/MullvadVPNUITests/Pages/TunnelControlPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class TunnelControlPage: Page {
let protocolName: String
}

var connectionIsSecured: Bool {
app.staticTexts[AccessibilityIdentifier.connectionStatusConnectedLabel].exists
}

/// 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.
/// - Parameters:
/// - attemptsCount: number of connection attempts to look for
Expand Down
12 changes: 6 additions & 6 deletions ios/MullvadVPNUITests/Pages/VPNSettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class VPNSettingsPage: Page {
super.init(app)
}

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

return expandButton
}
Expand All @@ -37,18 +37,18 @@ class VPNSettingsPage: Page {
}

@discardableResult func tapWireGuardPortsExpandButton() -> Self {
cellExpandCollapseButton(AccessibilityIdentifier.wireGuardPortsCell).tap()
cellExpandButton(AccessibilityIdentifier.wireGuardPortsCell).tap()
return self
}

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

return self
}

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

return self
}
Expand All @@ -72,7 +72,7 @@ class VPNSettingsPage: Page {
}

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

return self
}
Expand Down

0 comments on commit 640ead4

Please sign in to comment.