Skip to content

Commit

Permalink
Optimized tests on updated settings for each category, and server con…
Browse files Browse the repository at this point in the history
…nection tests; Added Help Settings Tests (#43)
  • Loading branch information
kp-geneva-parayno authored Dec 13, 2023
1 parent 4eb986d commit c0fc9b5
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 43 deletions.
8 changes: 4 additions & 4 deletions PIA VPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -831,7 +831,7 @@
699F23AF2AFBA66000EBC5E6 /* ProtocolsSettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtocolsSettingsScreen.swift; sourceTree = "<group>"; };
699F23B02AFBA66000EBC5E6 /* GeneralSettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralSettingsScreen.swift; sourceTree = "<group>"; };
699F23B12AFBA66000EBC5E6 /* PrivacySettingsScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacySettingsScreen.swift; sourceTree = "<group>"; };
699F23B82AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateSettingsTests.swift; sourceTree = "<group>"; };
699F23B82AFBAC0B00EBC5E6 /* SettingsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsTests.swift; sourceTree = "<group>"; };
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 = "<group>"; };
69B70ABD2ACC2CFE0072A09D /* AccessibilityId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityId.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1570,7 +1570,7 @@
35EDD6262ADE5D1E007B9ACB /* Tests */ = {
isa = PBXGroup;
children = (
699F23B82AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift */,
699F23B82AFBAC0B00EBC5E6 /* SettingsTests.swift */,
69C587FC2AD00C6300B95EF9 /* PIAExampleWithAuthenticatedAppTest.swift */,
35EDD6292ADE5F08007B9ACB /* SignInTests.swift */,
35EDD6322ADE7281007B9ACB /* OnboardingTests.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
1 change: 1 addition & 0 deletions PIA VPN/Settings/SettingPopoverSelectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions PIA-VPN_E2E_Tests/Helpers/ElementHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

30 changes: 29 additions & 1 deletion PIA-VPN_E2E_Tests/Screens/Settings/HelpSettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}
}
}
14 changes: 14 additions & 0 deletions PIA-VPN_E2E_Tests/Screens/Settings/ProtocolsSettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extension XCUIApplication {
staticText(with: "Protocol Selection")
}

var protocolSelectionPopover: XCUIElement {
otherElement(with: "ProtocolPopoverSelectionView")
}

var dataEncryptionButton: XCUIElement {
staticText(with: "Data Encryption")
}
Expand All @@ -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()
Expand All @@ -45,4 +53,10 @@ extension XCUIApplication {
protocolsSettingsButton.tap()
}
}

func selectProtocol(protocolName: String) {
protocolSelectionButton.tap()
guard protocolSelectionPopover.exists else {return}
protocolSelectionPopover.staticTexts[protocolName].tap()
}
}
6 changes: 5 additions & 1 deletion PIA-VPN_E2E_Tests/Tests/ServerConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// UpdateSettingsTests.swift
// SettingsTests.swift
// PIA-VPN_E2E_Tests
//
// Created by Geneva Parayno on 1/11/23.
Expand All @@ -8,76 +8,93 @@

import Nimble

class UpdateSettingsTests : BaseTest {
class SettingsTests : BaseTest {
override class func spec() {
let geoLocatedRegionDefaultValue = "1"
let vpnKillSwitchDefaultValue = "1"
let automationDefaultValue = "0"

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()

// 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.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())
}
}
}
}
}
Expand Down

0 comments on commit c0fc9b5

Please sign in to comment.