From c0fc9b520b0e95ff98fc40f7c428e7e7bed8af72 Mon Sep 17 00:00:00 2001 From: xv-geneva-parayno <121007829+xv-geneva-parayno@users.noreply.github.com> Date: Wed, 13 Dec 2023 09:59:13 +0800 Subject: [PATCH] Optimized tests on updated settings for each category, and server connection tests; Added Help Settings Tests (#43) --- PIA VPN.xcodeproj/project.pbxproj | 8 +- .../SettingPopoverSelectionView.swift | 1 + PIA-VPN_E2E_Tests/Helpers/ElementHelper.swift | 7 ++ .../Screens/Settings/HelpSettingsScreen.swift | 30 +++++- .../Settings/ProtocolsSettingsScreen.swift | 14 +++ .../Tests/ServerConnectionTests.swift | 6 +- ...ettingsTests.swift => SettingsTests.swift} | 91 +++++++++++-------- 7 files changed, 114 insertions(+), 43 deletions(-) rename PIA-VPN_E2E_Tests/Tests/{UpdateSettingsTests.swift => SettingsTests.swift} (52%) diff --git a/PIA VPN.xcodeproj/project.pbxproj b/PIA VPN.xcodeproj/project.pbxproj index 29058c13..a830bff1 100644 --- a/PIA VPN.xcodeproj/project.pbxproj +++ b/PIA VPN.xcodeproj/project.pbxproj @@ -181,7 +181,7 @@ 699F23B52AFBA66000EBC5E6 /* ProtocolsSettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 699F23AF2AFBA66000EBC5E6 /* ProtocolsSettingsScreen.swift */; }; 699F23B62AFBA66000EBC5E6 /* GeneralSettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 699F23B02AFBA66000EBC5E6 /* GeneralSettingsScreen.swift */; }; 699F23B72AFBA66000EBC5E6 /* PrivacySettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 699F23B12AFBA66000EBC5E6 /* PrivacySettingsScreen.swift */; }; - 699F23B92AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 699F23B82AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift */; }; + 699F23B92AFBAC0B00EBC5E6 /* SettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 699F23B82AFBAC0B00EBC5E6 /* SettingsTests.swift */; }; 69B70AB52ACBF51C0072A09D /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69B70AB42ACBF51C0072A09D /* LoginScreen.swift */; }; 69B70ABC2ACBF8300072A09D /* CredentialsUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EC2972D27D8B8580061C56A /* CredentialsUtil.swift */; }; 69B70ABE2ACC2CFE0072A09D /* AccessibilityId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69B70ABD2ACC2CFE0072A09D /* AccessibilityId.swift */; }; @@ -831,7 +831,7 @@ 699F23AF2AFBA66000EBC5E6 /* ProtocolsSettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtocolsSettingsScreen.swift; sourceTree = ""; }; 699F23B02AFBA66000EBC5E6 /* GeneralSettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralSettingsScreen.swift; sourceTree = ""; }; 699F23B12AFBA66000EBC5E6 /* PrivacySettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacySettingsScreen.swift; sourceTree = ""; }; - 699F23B82AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateSettingsTests.swift; sourceTree = ""; }; + 699F23B82AFBAC0B00EBC5E6 /* SettingsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTests.swift; sourceTree = ""; }; 69B70AB02ACBF51C0072A09D /* PIA-VPN_E2E_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "PIA-VPN_E2E_Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 69B70AB42ACBF51C0072A09D /* LoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreen.swift; sourceTree = ""; }; 69B70ABD2ACC2CFE0072A09D /* AccessibilityId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityId.swift; sourceTree = ""; }; @@ -1570,7 +1570,7 @@ 35EDD6262ADE5D1E007B9ACB /* Tests */ = { isa = PBXGroup; children = ( - 699F23B82AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift */, + 699F23B82AFBAC0B00EBC5E6 /* SettingsTests.swift */, 69C587FC2AD00C6300B95EF9 /* PIAExampleWithAuthenticatedAppTest.swift */, 35EDD6292ADE5F08007B9ACB /* SignInTests.swift */, 35EDD6322ADE7281007B9ACB /* OnboardingTests.swift */, @@ -3024,7 +3024,7 @@ 35DC7A602B0B440200502BED /* RegionSelectionScreen.swift in Sources */, 699F23B22AFBA66000EBC5E6 /* SettingsScreen.swift in Sources */, 35EDD6422AE7A83D007B9ACB /* WelcomeScreen.swift in Sources */, - 699F23B92AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift in Sources */, + 699F23B92AFBAC0B00EBC5E6 /* SettingsTests.swift in Sources */, 699F23B42AFBA66000EBC5E6 /* AutomationSettingsScreen.swift in Sources */, 35EDD62A2ADE5F08007B9ACB /* SignInTests.swift in Sources */, 69B70AB52ACBF51C0072A09D /* LoginScreen.swift in Sources */, diff --git a/PIA VPN/Settings/SettingPopoverSelectionView.swift b/PIA VPN/Settings/SettingPopoverSelectionView.swift index 14ce71dc..3a7ea91d 100644 --- a/PIA VPN/Settings/SettingPopoverSelectionView.swift +++ b/PIA VPN/Settings/SettingPopoverSelectionView.swift @@ -89,6 +89,7 @@ extension ProtocolPopoverSelectionView: UITableViewDelegate, UITableViewDataSour } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + self.accessibilityIdentifier = "ProtocolPopoverSelectionView" guard let cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) else { fatalError("no protocol available") diff --git a/PIA-VPN_E2E_Tests/Helpers/ElementHelper.swift b/PIA-VPN_E2E_Tests/Helpers/ElementHelper.swift index 00471085..5cf43e63 100644 --- a/PIA-VPN_E2E_Tests/Helpers/ElementHelper.swift +++ b/PIA-VPN_E2E_Tests/Helpers/ElementHelper.swift @@ -59,5 +59,12 @@ extension XCUIApplication { func dialog(with id: String) -> XCUIElement { return switches[id] } + + func findButtonWithPartialText(_ partialText: String) -> XCUIElement? { + let predicate = NSPredicate(format: "label CONTAINS[c] %@", partialText) + let matchingStaticTexts = staticTexts.matching(predicate) + + return matchingStaticTexts.firstMatch + } } diff --git a/PIA-VPN_E2E_Tests/Screens/Settings/HelpSettingsScreen.swift b/PIA-VPN_E2E_Tests/Screens/Settings/HelpSettingsScreen.swift index d217abf9..50e891f0 100644 --- a/PIA-VPN_E2E_Tests/Screens/Settings/HelpSettingsScreen.swift +++ b/PIA-VPN_E2E_Tests/Screens/Settings/HelpSettingsScreen.swift @@ -13,14 +13,30 @@ extension XCUIApplication { staticText(with: "Send Debug Log to support") } + var successfulSendDebugMessage: XCUIElement { + staticText(with: "Debug information submitted") + } + var helpImprovePIASwitch: XCUIElement { switches(with: "Help improve PIA") } + var connectionStatsButton: XCUIElement { + staticText(with: "Connection stats") + } + var latestNewsButton: XCUIElement { staticText(with: "Latest News") } + var versionNo: XCUIElement { + findButtonWithPartialText("Version")! + } + + var tryWireguardNowButton: XCUIElement { + findButtonWithPartialText("Try WireGuard® now")! + } + func navigateToHelpSettings() { guard dashboardMenuButton.exists else { return } dashboardMenuButton.tap() @@ -30,7 +46,19 @@ extension XCUIApplication { } if helpSettingsButton.waitForExistence(timeout: defaultTimeout) { - automationSettingsButton.tap() + helpSettingsButton.tap() + } + } + + func enableHelpImprovePIA() { + if (helpImprovePIASwitch.value as! String == "0") { + helpImprovePIASwitch.tap() + } + } + + func disableHelpImprovePIA() { + if (helpImprovePIASwitch.value as! String == "1") { + helpImprovePIASwitch.tap() } } } diff --git a/PIA-VPN_E2E_Tests/Screens/Settings/ProtocolsSettingsScreen.swift b/PIA-VPN_E2E_Tests/Screens/Settings/ProtocolsSettingsScreen.swift index 3fcd08a7..04f5c273 100644 --- a/PIA-VPN_E2E_Tests/Screens/Settings/ProtocolsSettingsScreen.swift +++ b/PIA-VPN_E2E_Tests/Screens/Settings/ProtocolsSettingsScreen.swift @@ -13,6 +13,10 @@ extension XCUIApplication { staticText(with: "Protocol Selection") } + var protocolSelectionPopover: XCUIElement { + otherElement(with: "ProtocolPopoverSelectionView") + } + var dataEncryptionButton: XCUIElement { staticText(with: "Data Encryption") } @@ -33,6 +37,10 @@ extension XCUIApplication { staticText(with: "IPSec (IKEv2)") } + var wireguard: XCUIElement { + staticText(with: "WireGuard®") + } + func navigateToProtocolSettings() { guard dashboardMenuButton.exists else { return } dashboardMenuButton.tap() @@ -45,4 +53,10 @@ extension XCUIApplication { protocolsSettingsButton.tap() } } + + func selectProtocol(protocolName: String) { + protocolSelectionButton.tap() + guard protocolSelectionPopover.exists else {return} + protocolSelectionPopover.staticTexts[protocolName].tap() + } } diff --git a/PIA-VPN_E2E_Tests/Tests/ServerConnectionTests.swift b/PIA-VPN_E2E_Tests/Tests/ServerConnectionTests.swift index fd0fd4aa..f6eba281 100644 --- a/PIA-VPN_E2E_Tests/Tests/ServerConnectionTests.swift +++ b/PIA-VPN_E2E_Tests/Tests/ServerConnectionTests.swift @@ -15,6 +15,10 @@ class ServerConnectionTests : BaseTest { describe("server connection tests") { context("when the user navigates to homescreen upon logging in") { it("should display the vpn server defaulted to 'Automatic'") { + app.logOut() + app.navigateToLoginScreen() + app.logIn(with: CredentialsUtil.credentials(type: .valid)) + app.acceptVPNPermission() expect(app.vpnServerButton.staticTexts["Automatic"].exists).to(beTrue()) } @@ -36,7 +40,7 @@ class ServerConnectionTests : BaseTest { app.disconnectToVPN() app.navigateToRegionSelection() app.searchRegion(regionName: "Philippines").firstMatch.tap() - expect(app.connectedStatusLabel.exists).to(beTrue()) + expect(app.connectedStatusLabel.waitForExistence(timeout: app.defaultTimeout)).to(beTrue()) expect(app.vpnServerButton.staticTexts["Philippines"].exists).to(beTrue()) } } diff --git a/PIA-VPN_E2E_Tests/Tests/UpdateSettingsTests.swift b/PIA-VPN_E2E_Tests/Tests/SettingsTests.swift similarity index 52% rename from PIA-VPN_E2E_Tests/Tests/UpdateSettingsTests.swift rename to PIA-VPN_E2E_Tests/Tests/SettingsTests.swift index 04c2824d..827a40a6 100644 --- a/PIA-VPN_E2E_Tests/Tests/UpdateSettingsTests.swift +++ b/PIA-VPN_E2E_Tests/Tests/SettingsTests.swift @@ -1,5 +1,5 @@ // -// UpdateSettingsTests.swift +// SettingsTests.swift // PIA-VPN_E2E_Tests // // Created by Geneva Parayno on 1/11/23. @@ -8,7 +8,7 @@ import Nimble -class UpdateSettingsTests : BaseTest { +class SettingsTests : BaseTest { override class func spec() { let geoLocatedRegionDefaultValue = "1" let vpnKillSwitchDefaultValue = "1" @@ -16,9 +16,10 @@ class UpdateSettingsTests : BaseTest { super.spec() - describe("settings return to default value after logging out") { + describe("settings tests") { context("updated settings for each category") { - it("should revert changes made on general settings to default after logging out and logging back in") { + it("should revert changes made on to default value after logging out and logging back in") { + //update general settings app.navigateToGeneralSettings() app.geoLocatedRegionsSwitch.tap() @@ -26,58 +27,74 @@ class UpdateSettingsTests : BaseTest { // TODO: Enable this check when we disable the animations on E2E tests // expect((app.geoLocatedRegionsSwitch.value as! String)) != geoLocatedRegionDefaultValue + //update protocol settings app.navigateToHomeFromSettings() - app.logOut() - app.navigateToLoginScreen() - app.logIn(with: CredentialsUtil.credentials(type: .valid)) - app.acceptVPNPermission() - app.navigateToGeneralSettings() - expect((app.geoLocatedRegionsSwitch.value as! String)) == geoLocatedRegionDefaultValue - } - - it("should revert changes made on protocol settings to default after logging out and logging back in") { app.navigateToProtocolSettings() - app.protocolSelectionButton.tap() - app.openVPN.tap() + app.selectProtocol(protocolName: "OpenVPN") expect(app.openVPN.exists).to(beTrue()) + + //update privacy settings app.navigateToHomeFromSettings() - app.logOut() - app.navigateToLoginScreen() - app.logIn(with: CredentialsUtil.credentials(type: .valid)) - app.acceptVPNPermission() - app.navigateToProtocolSettings() - expect(app.ipsec.exists).to(beTrue()) - } - - it("should revert changes made on privacy features settings to default after logging out and logging back in") { app.navigateToPrivacySettings() app.disableVPNKillSwitch() expect((app.vpnKillSwitch.value as! String)) != vpnKillSwitchDefaultValue + + //update automation settings app.navigateToHomeFromSettings() - app.logOut() - app.navigateToLoginScreen() - app.logIn(with: CredentialsUtil.credentials(type: .valid)) - app.acceptVPNPermission() - app.navigateToPrivacySettings() - expect((app.vpnKillSwitch.value as! String)) == vpnKillSwitchDefaultValue - } - - it("should revert changes made on automation settings to default after logging out and logging back in") { app.navigateToAutomationSettings() app.enableAutomationSwitch.tap() - // This check is flaky in CI because the switch has a small animation and there is a small amount of delay when the value gets updated after tapping the switch. - // TODO: Enable this check when we disable the animations on E2E tests - // expect((app.enableAutomationSwitch.value as! String)) != automationDefaultValue - app.navigateToHomeFromSettings() app.logOut() app.navigateToLoginScreen() app.logIn(with: CredentialsUtil.credentials(type: .valid)) app.acceptVPNPermission() + + //expect that the settings are reverted to default value + app.navigateToGeneralSettings() + expect((app.geoLocatedRegionsSwitch.value as! String)) == geoLocatedRegionDefaultValue + + app.navigateToHomeFromSettings() + app.navigateToProtocolSettings() + expect(app.ipsec.exists).to(beTrue()) + + app.navigateToHomeFromSettings() + app.navigateToPrivacySettings() + expect((app.vpnKillSwitch.value as! String)) == vpnKillSwitchDefaultValue + + app.navigateToHomeFromSettings() app.navigateToAutomationSettings() expect((app.enableAutomationSwitch.value as! String)) == automationDefaultValue } + + context("help settings interaction") { + it("should return 'Debug information submitted' when user clicks 'Send Debug Log to support'") { + app.navigateToHelpSettings() + app.sendDebugButton.tap() + expect(app.successfulSendDebugMessage.waitForExistence(timeout: app.defaultTimeout)).to(beTrue()) + } + + it("should when user clicks 'Latest News'") { + app.navigateToHelpSettings() + app.latestNewsButton.tap() + expect(app.tryWireguardNowButton.exists).to(beTrue()) + + app.tryWireguardNowButton.tap() + expect(app.protocolsSettingsButton.exists).to(beTrue()) + expect(app.wireguard.exists).to(beTrue()) + } + + it("should when user clicks 'Help improve PIA'") { + app.navigateToHelpSettings() + app.enableHelpImprovePIA() + expect(app.connectionStatsButton.exists).to(beTrue()) + } + + it("should display version number") { + app.navigateToHelpSettings() + expect(app.versionNo.exists).to(beTrue()) + } + } } } }