Skip to content

Commit

Permalink
Added VPNServerListTests, enhanced existing screens and tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-geneva-parayno authored Nov 23, 2023
1 parent 49ec8a1 commit 4742c67
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 5 deletions.
8 changes: 8 additions & 0 deletions PIA VPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
3545E98426AADC7E00B812CC /* ServerSelectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3545E97F26AAD60C00B812CC /* ServerSelectionDelegate.swift */; };
35950B312ADD2996006F3CD9 /* Quick in Frameworks */ = {isa = PBXBuildFile; productRef = 35950B302ADD2996006F3CD9 /* Quick */; };
35950B342ADD2EE5006F3CD9 /* Nimble in Frameworks */ = {isa = PBXBuildFile; productRef = 35950B332ADD2EE5006F3CD9 /* Nimble */; };
35DC7A5E2B0B325700502BED /* VPNServerListTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DC7A5D2B0B325700502BED /* VPNServerListTests.swift */; };
35DC7A602B0B440200502BED /* RegionSelectionScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DC7A5F2B0B440200502BED /* RegionSelectionScreen.swift */; };
35EDD6282ADE5D31007B9ACB /* BaseTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35EDD6272ADE5D31007B9ACB /* BaseTest.swift */; };
35EDD62A2ADE5F08007B9ACB /* SignInTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35EDD6292ADE5F08007B9ACB /* SignInTests.swift */; };
35EDD6332ADE7281007B9ACB /* OnboardingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35EDD6322ADE7281007B9ACB /* OnboardingTests.swift */; };
Expand Down Expand Up @@ -778,6 +780,8 @@
3524670D26B432ED00E3F0AC /* DashboardViewController+ServerSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DashboardViewController+ServerSelection.swift"; sourceTree = "<group>"; };
3545E97F26AAD60C00B812CC /* ServerSelectionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionDelegate.swift; sourceTree = "<group>"; };
3545E98126AADB2B00B812CC /* ServerSelectingTileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectingTileCell.swift; sourceTree = "<group>"; };
35DC7A5D2B0B325700502BED /* VPNServerListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNServerListTests.swift; sourceTree = "<group>"; };
35DC7A5F2B0B440200502BED /* RegionSelectionScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegionSelectionScreen.swift; sourceTree = "<group>"; };
35EDD6272ADE5D31007B9ACB /* BaseTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTest.swift; sourceTree = "<group>"; };
35EDD6292ADE5F08007B9ACB /* SignInTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInTests.swift; sourceTree = "<group>"; };
35EDD6322ADE7281007B9ACB /* OnboardingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1511,6 +1515,7 @@
35EDD6292ADE5F08007B9ACB /* SignInTests.swift */,
35EDD6322ADE7281007B9ACB /* OnboardingTests.swift */,
35EDD65B2B047839007B9ACB /* QuickSettingsTests.swift */,
35DC7A5D2B0B325700502BED /* VPNServerListTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand All @@ -1525,6 +1530,7 @@
35EDD6412AE7A83D007B9ACB /* WelcomeScreen.swift */,
35EDD6432AE7B480007B9ACB /* Common.swift */,
35EDD6592B035B51007B9ACB /* SideMenuScreen.swift */,
35DC7A5F2B0B440200502BED /* RegionSelectionScreen.swift */,
);
path = Screens;
sourceTree = "<group>";
Expand Down Expand Up @@ -2827,6 +2833,7 @@
35EDD6372ADE761A007B9ACB /* HomeScreen.swift in Sources */,
35EDD63B2AE62D15007B9ACB /* ElementHelper.swift in Sources */,
69C587FD2AD00C6300B95EF9 /* PIAExampleWithAuthenticatedAppTest.swift in Sources */,
35DC7A602B0B440200502BED /* RegionSelectionScreen.swift in Sources */,
699F23B22AFBA66000EBC5E6 /* SettingsScreen.swift in Sources */,
35EDD6422AE7A83D007B9ACB /* WelcomeScreen.swift in Sources */,
699F23B92AFBAC0B00EBC5E6 /* UpdateSettingsTests.swift in Sources */,
Expand All @@ -2837,6 +2844,7 @@
35EDD6332ADE7281007B9ACB /* OnboardingTests.swift in Sources */,
699F23B52AFBA66000EBC5E6 /* ProtocolsSettingsScreen.swift in Sources */,
69B70AC02ACC2CFE0072A09D /* AccessibilityId.swift in Sources */,
35DC7A5E2B0B325700502BED /* VPNServerListTests.swift in Sources */,
699F23B62AFBA66000EBC5E6 /* GeneralSettingsScreen.swift in Sources */,
699F23B72AFBA66000EBC5E6 /* PrivacySettingsScreen.swift in Sources */,
);
Expand Down
1 change: 1 addition & 0 deletions PIA VPN/Tiles/RegionTileCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RegionTileCollectionViewCell: UICollectionViewCell, TileableCell {
}

func setupCellForStatus(_ status: TileStatus) {
self.accessibilityIdentifier = "RegionTileCollectionViewCell"
self.accessibilityLabel = L10n.Localizable.Tiles.Region.title
Theme.current.applyPrincipalBackground(self)
Theme.current.applyPrincipalBackground(self.contentView)
Expand Down
15 changes: 13 additions & 2 deletions PIA-VPN_E2E_Tests/Screens/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extension XCUIApplication {
button(with: "Disable VPN Kill Switch")
}

var vpnServerButton: XCUIElement {
cell(with: "RegionTileCollectionViewCell")
}

func logOut() {
guard dashboardMenuButton.exists else { return }
dashboardMenuButton.tap()
Expand All @@ -54,7 +58,8 @@ extension XCUIApplication {
if confirmationDialogButton.waitForExistence(timeout: shortTimeout) {
confirmationDialogButton.tap()
}
welcomeLoginButton.waitForExistence(timeout: defaultTimeout)
WaitHelper.waitForElementToBeVisible(welcomeLoginButton, timeout: defaultTimeout,
onSuccess:{print("successful logout")}, onFailure:{error in print("welcomeLoginButton is not visible")})
}
}

Expand All @@ -80,7 +85,13 @@ extension XCUIApplication {

func navigateToHome() {
closeButton.tap()
dashboardMenuButton.waitForExistence(timeout: defaultTimeout)
WaitHelper.waitForElementToBeVisible(dashboardMenuButton, timeout: defaultTimeout,
onSuccess:{print("successfully navigate to Home")}, onFailure:{error in print("dashboardMenuButton is not visible")})
}

func navigateToRegionSelection(){
guard vpnServerButton.exists else { return }
vpnServerButton.tap()
}

func enableVPNKillSwitchOnHome() {
Expand Down
4 changes: 3 additions & 1 deletion PIA-VPN_E2E_Tests/Screens/LoginScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extension XCUIApplication {

swipeUp()

connectionButton.waitForExistence(timeout: defaultTimeout)
WaitHelper.waitForElementToBeVisible(connectionButton, timeout: defaultTimeout,
onSuccess:{print("successful login")}, onFailure:{error in print("connectionButton is not visible")})

}
}
87 changes: 87 additions & 0 deletions PIA-VPN_E2E_Tests/Screens/RegionSelectionScreen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// RegionSelectionScreen.swift
// PIA-VPN_E2E_Tests
//
// Created by Geneva Parayno on 20/11/23.
// Copyright © 2023 Private Internet Access Inc. All rights reserved.
//

import XCTest

extension XCUIApplication {
var searchRegionField: XCUIElement {
searchField(with: "Search for a region")
}

var cancelSearchButton: XCUIElement {
button(with: "Cancel")
}

var sortButton: XCUIElement {
button(with: "Filter")
}

var sortPopUpHeader: XCUIElement {
staticText(with: "SORT REGIONS BY")
}

func searchRegion(regionName: String) -> XCUIElementQuery {
while(!searchRegionField.isHittable) {
swipeDown()
}
searchRegionField.tap()
searchRegionField.typeText(regionName)

return getRegionList()
}

func cancelSearch() {
cancelSearchButton.tap()
WaitHelper.waitForElementToBeVisible(sortButton, timeout: defaultTimeout, onSuccess: {}, onFailure: {error in print("sortButton is not displayed")})
}

func getRegionList() -> XCUIElementQuery {
let query = cells.matching(NSPredicate(format: "identifier == %@", "uitests.regions.region_name"))
return query
}

func addRegionAsFavourite(regionName: String) {
let region = searchRegion(regionName: regionName).firstMatch

let regionAddAsAFavouriteButton = region.buttons["Add a favorite region"]
let regionRemoveAsAFavouriteButton = region.buttons["Remove a favorite region"]

if(regionRemoveAsAFavouriteButton.exists) {
regionRemoveAsAFavouriteButton.tap()
}
WaitHelper.waitForElementToBeVisible(regionAddAsAFavouriteButton, timeout: defaultTimeout, onSuccess: {}, onFailure: {error in print("regionRemoveAsAFavouriteButton is not visible")})
WaitHelper.waitForElementToNotBeVisible(regionRemoveAsAFavouriteButton, timeout: defaultTimeout, onSuccess: {}, onFailure: {error in print("regionAddAsAFavouriteButton is not visible")})

}

func removeRegionAsFavourite(regionName: String) {

}

func isRegionFavourite(regionName: String) -> Bool {
var isFavourite: Bool = false

let region = getRegionList().firstMatch

let regionAddAsAFavouriteButton = region.buttons["Add a favorite region"]
let regionRemoveAsAFavouriteButton = region.buttons["Remove a favorite region"]

if(regionAddAsAFavouriteButton.exists && !regionRemoveAsAFavouriteButton.exists) {
isFavourite = true
}

return isFavourite
}

func sortRegionsBy(sortType: String) {
guard sortButton.exists else {return}
sortButton.tap()
WaitHelper.waitForElementToBeVisible(sortPopUpHeader, timeout: defaultTimeout, onSuccess: {}, onFailure: {error in print("sortPopUpHeader is not visible")})
button(with: sortType).tap()
}
}
12 changes: 12 additions & 0 deletions PIA-VPN_E2E_Tests/Screens/Settings/PrivacySettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ extension XCUIApplication {
privacySettingsButton.tap()
}
}

func enableVPNKillSwitch(){
if ((vpnKillSwitch.value as! String) != "1") {
vpnKillSwitch.tap()
}
}

func disableVPNKillSwitch(){
if ((vpnKillSwitch.value as! String) != "0") {
vpnKillSwitch.tap()
}
}
}
1 change: 0 additions & 1 deletion PIA-VPN_E2E_Tests/Tests/QuickSettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Nimble
import Foundation

class QuickSettingsTests : BaseTest {
override class func spec() {
Expand Down
2 changes: 1 addition & 1 deletion PIA-VPN_E2E_Tests/Tests/UpdateSettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UpdateSettingsTests : BaseTest {

it("should revert changes made on privacy features settings to default after logging out and logging back in") {
app.navigateToPrivacySettings()
app.vpnKillSwitch.tap()
app.disableVPNKillSwitch()
expect((app.vpnKillSwitch.value as! String)) != vpnKillSwitchDefaultValue
app.navigateToHomeFromSettings()
app.logOut()
Expand Down
88 changes: 88 additions & 0 deletions PIA-VPN_E2E_Tests/Tests/VPNServerListTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// VPNServerListTests.swift
// PIA-VPN_E2E_Tests
//
// Created by Geneva Parayno on 20/11/23.
// Copyright © 2023 Private Internet Access Inc. All rights reserved.
//

import Nimble

class VPNServerListTests : BaseTest {
override class func spec() {
let regionKeyword = "australia"
let characterKey = "au"
let favouriteRegionKeyword = "Philippines"

super.spec()

describe("vpn server list tests") {
context("when the user navigates to region selection screen") {
it("should show the search region field when the user scrolls down") {
app.navigateToRegionSelection()
while(!app.searchRegionField.isHittable) {
app.swipeDown()
}

expect(app.searchRegionField.isHittable).to(beTrue())
}
}

context("when the user performs search") {
it("should return results based on searched keyword \(regionKeyword)") {
app.navigateToRegionSelection()
let cellsQuery = app.searchRegion(regionName: regionKeyword)

for cell in cellsQuery.allElementsBoundByIndex {
expect(cell.label.lowercased().contains(regionKeyword)).to(beTrue())
}
}
it("should return results based on searched \(characterKey)") {
app.navigateToRegionSelection()
let cellsQuery = app.searchRegion(regionName: characterKey)

for cell in cellsQuery.allElementsBoundByIndex {
expect(cell.label.lowercased().contains(characterKey)).to(beTrue())
}
}
}

context("when the user selects a region as a favorite") {
it("should be displayed as a favourite region") {
app.navigateToRegionSelection()
app.addRegionAsFavourite(regionName: favouriteRegionKeyword)
expect(app.isRegionFavourite(regionName: favouriteRegionKeyword)).to(beTrue())
}
}

context("when the user sorts the region selection") {
it("should sort the regions by name, when 'name' is selected") {
app.navigateToRegionSelection()
app.sortRegionsBy(sortType: "NAME")
let regionList = app.getRegionList().allElementsBoundByIndex.prefix(21).map{$0.label}.filter{$0 != "Automatic"}
expect(regionList).to(equal(regionList.sorted(by: <)))
}

it("should sort the regions by latency, when 'latency' is selected") {
app.navigateToRegionSelection()
app.sortRegionsBy(sortType: "LATENCY")
let regionList = app.getRegionList().allElementsBoundByIndex.prefix(21).map{$0.label}.filter{$0 != "Automatic"}
expect(regionList) == regionList.sorted {
let latency01 = Int($0.components(separatedBy: ", ").last?.dropLast(2) ?? "") ?? 0
let latency02 = Int($1.components(separatedBy: ", ").last?.dropLast(2) ?? "") ?? 0
return latency01<latency02
}
}

it("should sort the regions by favourites, when 'favourites' is selected") {
app.navigateToRegionSelection()
app.addRegionAsFavourite(regionName: favouriteRegionKeyword)
app.cancelSearch()
app.sortRegionsBy(sortType: "FAVORITES")
let firstRegion = app.getRegionList().allElementsBoundByIndex.prefix(2).filter({$0.label != "Automatic"}).first
expect(firstRegion?.label).to(contain(favouriteRegionKeyword))
}
}
}
}
}

0 comments on commit 4742c67

Please sign in to comment.