Skip to content

Commit

Permalink
PIA-1604: Added Dedicated IP tests (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-geneva-parayno authored Apr 3, 2024
1 parent 52d6e81 commit 4df04ce
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 28 deletions.
12 changes: 12 additions & 0 deletions PIA VPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
3524670C26B432BC00E3F0AC /* TrustedNetworkHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3524670A26B431B800E3F0AC /* TrustedNetworkHelper.swift */; };
3524670E26B432ED00E3F0AC /* DashboardViewController+ServerSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3524670D26B432ED00E3F0AC /* DashboardViewController+ServerSelection.swift */; };
3524670F26B4332E00E3F0AC /* DashboardViewController+ServerSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3524670D26B432ED00E3F0AC /* DashboardViewController+ServerSelection.swift */; };
3529EF0D2BB3C977003FD26F /* DedicatedIPTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3529EF0C2BB3C977003FD26F /* DedicatedIPTests.swift */; };
3529EF0F2BB3FB69003FD26F /* DedicatedIPUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3529EF0E2BB3FB69003FD26F /* DedicatedIPUtil.swift */; };
3529EF112BB51AD9003FD26F /* DedicatedIPScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3529EF102BB51AD9003FD26F /* DedicatedIPScreen.swift */; };
3545E98026AAD60C00B812CC /* ServerSelectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3545E97F26AAD60C00B812CC /* ServerSelectionDelegate.swift */; };
3545E98226AADB2B00B812CC /* ServerSelectingTileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3545E98126AADB2B00B812CC /* ServerSelectingTileCell.swift */; };
3545E98326AADC7C00B812CC /* ServerSelectingTileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3545E98126AADB2B00B812CC /* ServerSelectingTileCell.swift */; };
Expand Down Expand Up @@ -1145,6 +1148,9 @@
3510B3BE2B439D590004851B /* DedicatedIPScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DedicatedIPScreen.swift; sourceTree = "<group>"; };
3524670A26B431B800E3F0AC /* TrustedNetworkHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrustedNetworkHelper.swift; sourceTree = "<group>"; };
3524670D26B432ED00E3F0AC /* DashboardViewController+ServerSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DashboardViewController+ServerSelection.swift"; sourceTree = "<group>"; };
3529EF0C2BB3C977003FD26F /* DedicatedIPTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DedicatedIPTests.swift; sourceTree = "<group>"; };
3529EF0E2BB3FB69003FD26F /* DedicatedIPUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DedicatedIPUtil.swift; sourceTree = "<group>"; };
3529EF102BB51AD9003FD26F /* DedicatedIPScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DedicatedIPScreen.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>"; };
35C8064B2B1075620078A2C6 /* ServerConnectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerConnectionTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2241,6 +2247,7 @@
35E8E67E2B8C60F500A3A3DB /* DashboardScreen.swift */,
35E8E6802B8C637D00A3A3DB /* SettingsScreen.swift */,
35DDA95C2B9EA53A00EB17A3 /* LocationSelectionScreen.swift */,
3529EF102BB51AD9003FD26F /* DedicatedIPScreen.swift */,
);
path = Screens;
sourceTree = "<group>";
Expand All @@ -2261,6 +2268,7 @@
35E8E6702B8C386B00A3A3DB /* SignInTests.swift */,
35E8E6822B8ED52300A3A3DB /* OnboardingTests.swift */,
35DDA95A2B9AF8A900EB17A3 /* LocationSelectionTests.swift */,
3529EF0C2BB3C977003FD26F /* DedicatedIPTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand All @@ -2277,6 +2285,7 @@
isa = PBXGroup;
children = (
35E8E67C2B8C3CBA00A3A3DB /* CredentialsUtil.swift */,
3529EF0E2BB3FB69003FD26F /* DedicatedIPUtil.swift */,
);
path = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -5100,17 +5109,20 @@
35E8E6652B870C2700A3A3DB /* Common.swift in Sources */,
35E8E66A2B8C37C900A3A3DB /* WelcomeScreen.swift in Sources */,
35E8E66E2B8C384D00A3A3DB /* OnboardingScreen.swift in Sources */,
3529EF0F2BB3FB69003FD26F /* DedicatedIPUtil.swift in Sources */,
35E8E6742B8C388A00A3A3DB /* BaseTest.swift in Sources */,
35DDA95B2B9AF8AA00EB17A3 /* LocationSelectionTests.swift in Sources */,
35E8E6682B87178600A3A3DB /* KeyboardNavigator.swift in Sources */,
35E8E6812B8C637D00A3A3DB /* SettingsScreen.swift in Sources */,
35E8E6832B8ED52300A3A3DB /* OnboardingTests.swift in Sources */,
35E8E67D2B8C3CBA00A3A3DB /* CredentialsUtil.swift in Sources */,
3529EF112BB51AD9003FD26F /* DedicatedIPScreen.swift in Sources */,
35DDA95D2B9EA53A00EB17A3 /* LocationSelectionScreen.swift in Sources */,
35E8E67F2B8C60F500A3A3DB /* DashboardScreen.swift in Sources */,
35E8E66C2B8C384200A3A3DB /* SignInScreen.swift in Sources */,
E58A457B2BAC246B002A0704 /* SwiftGen+Strings.swift in Sources */,
35E8E67A2B8C3B0500A3A3DB /* ElementHelper.swift in Sources */,
3529EF0D2BB3C977003FD26F /* DedicatedIPTests.swift in Sources */,
35E8E6712B8C386B00A3A3DB /* SignInTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion PIA-VPN_E2E_Tests/Util/CredentialsUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CredentialsUtil {
public static func credentials(type: CredentialsType) -> Credentials {
switch type {
case .invalid:
return Credentials(username: "fakeUser", password: "fakePassword123")
return Credentials(username: "aaa", password: "Aaa123")
case .valid:
let testUser = ProcessInfo.processInfo.environment["PIA_TEST_USER"] ?? "user-not-found"
let testPassword = ProcessInfo.processInfo.environment["PIA_TEST_PASSWORD"] ?? "password-not-found"
Expand Down
2 changes: 1 addition & 1 deletion PIA-VPN_E2E_Tests/Util/DedicatedIPUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DedicatedIPUtil {
case .empty:
return DedicatedIP(token: "")
case .invalid:
return DedicatedIP(token: "fakeDedicatedIP")
return DedicatedIP(token: "aaa")
case .valid:
let testDedicatedIP = ProcessInfo.processInfo.environment["PIA_TEST_DEDICATEDIP"] ?? "dedicated ip not found"
return DedicatedIP(token: testDedicatedIP)
Expand Down
2 changes: 2 additions & 0 deletions PIA-VPN_tvOS_E2E_Tests/Screens/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import XCTest

extension XCUIApplication{
var continueButton:XCUIElement {button(with: "Continue")}

func moveFocus(to element: XCUIElement, startingDirection: XCUIRemote.Button = .right) {
var direction: XCUIRemote.Button = startingDirection
var navigationCycle = NavigationCycle(startingDirection: startingDirection)
Expand Down
2 changes: 1 addition & 1 deletion PIA-VPN_tvOS_E2E_Tests/Screens/DashboardScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension XCUIApplication{

if(settingsButton.waitForElementToAppear()){
navigateToSettingsScreen()
navigateToAccountSettings()
navigateToAccountSettingsScreen()
XCTAssert(logoutButton.waitForElementToAppear())

moveFocus(to: logoutButton)
Expand Down
53 changes: 53 additions & 0 deletions PIA-VPN_tvOS_E2E_Tests/Screens/DedicatedIPScreen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// DedicatedIPScreen.swift
// PIA-VPN_tvOS_E2E_Tests
//
// Created by Geneva Parayno on 28/3/24.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import XCTest

extension XCUIApplication{
var dIPTokenTextField:XCUIElement {textField(with: "Enter Your Dedicated IP Token")}
var activateButton: XCUIElement {button(with: "Activate")}
var emptyTokenErrorMessage: XCUIElement {staticText(with: "Your token can't be empty.")}
var invalidTokenErrorMessage: XCUIElement {staticText(with: "Your token is either invalid or has expired.")}
var activeDIPMessage: XCUIElement {staticText(with: "Your Dedicated IP it's now active.")}
var deleteDedicatedIPButton: XCUIElement {button(with: "Delete Dedicated IP")}
var activeDIPStatus: XCUIElement {staticText(with: "Active")}
var confirmDeleteButton: XCUIElement {button(with: "Yes, Delete")}

func activateDIPToken(DIP: DedicatedIP){

dIPTokenTextField.waitForElementToAppear()
moveFocus(to: dIPTokenTextField)
XCUIRemote.shared.press(.select)
let navigator = KeyboardNavigator()
navigator.resetKeyboardPosition()
navigator.typeText(DIP.token, keyboardType: .multiRow)
navigator.clickNext()
activateButton.waitForElementToAppear()
moveFocus(to: activateButton, startingDirection: .down)
XCUIRemote.shared.press(.select)

if(emptyTokenErrorMessage.exists || invalidTokenErrorMessage.exists) {
return
}

else if(continueButton.exists) {
moveFocus(to: continueButton.firstMatch)
XCUIRemote.shared.press(.select)
}
}

func deleteDedicatedIP(){
deleteDedicatedIPButton.waitForElementToAppear()
moveFocus(to: deleteDedicatedIPButton)
XCUIRemote.shared.press(.select)
confirmDeleteButton.waitForElementToAppear()
moveFocus(to: confirmDeleteButton.firstMatch)
XCUIRemote.shared.press(.select)
XCTAssert(dIPTokenTextField.waitForElementToAppear())
}
}
10 changes: 5 additions & 5 deletions PIA-VPN_tvOS_E2E_Tests/Screens/LocationSelectionScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ extension XCUIApplication{
var removeFromFavoritesButton: XCUIElement {button(with: "Remove from Favorites")}
var favouritesTabButton:XCUIElement {button(with: "Favourite(s)")}

func navigateToLocationSelection() {
func navigateToLocationSelectionScreen() {
locationButton.waitForElementToAppear()
moveFocus(to: locationButton, startingDirection: .right)
XCUIRemote.shared.press(.select)
XCTAssert(locationSelectionTitle.waitForElementToAppear())
}

func navigateToAllLocations() {
func navigateToAllLocationsScreen() {
allTabButton.waitForElementToAppear()
moveFocus(to: allTabButton, startingDirection: .down)
XCTAssert(allLocationsTitle.waitForElementToAppear())
}

func navigateToSearchLocation() {
func navigateToSearchLocationScreen() {
searchTabButton.waitForElementToAppear()
moveFocus(to: searchTabButton, startingDirection: .down)
XCTAssert(searchForALocationButton.waitForElementToAppear())
}

func navigateToFavouriteLocation() {
func navigateToFavouriteLocationScreen() {
favouritesTabButton.waitForElementToAppear()
moveFocus(to: favouritesTabButton, startingDirection: .up)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ extension XCUIApplication{
return
}

navigateToFavouriteLocation()
navigateToFavouriteLocationScreen()
XCUIRemote.shared.press(.right)

while(favouritesTabButton.exists){
Expand Down
11 changes: 8 additions & 3 deletions PIA-VPN_tvOS_E2E_Tests/Screens/SettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ extension XCUIApplication{
var accountButton:XCUIElement {button(with: "Account")}
var accountTitle:XCUIElement {staticText(with: "Account")}
var dedicatedIPButton:XCUIElement {button(with: "Dedicated IP")}
var dedicatedIPTitle:XCUIElement {staticText(with: "Dedicated IP")}
var enterDedicatedIPTitle:XCUIElement {staticText(with: "Enter Dedicated IP")}
var logoutButton:XCUIElement {button(with: "Log Out")}
var logoutAlertButton:XCUIElement {alert(with: "Are you sure?").buttons["Log Out"].firstMatch}

func navigateToAccountSettings(){
func navigateToAccountSettingsScreen(){
accountButton.waitForElementToAppear()
moveFocus(to: accountButton, startingDirection: .down)
XCUIRemote.shared.press(.select)
XCTAssert(accountTitle.waitForElementToAppear())
}


func navigateToDedicatedIPScreen(){
dedicatedIPButton.waitForElementToAppear()
moveFocus(to: dedicatedIPButton, startingDirection: .down)
XCUIRemote.shared.press(.select)
XCTAssert(enterDedicatedIPTitle.waitForElementToAppear()||deleteDedicatedIPButton.waitForElementToAppear())
}
}
61 changes: 61 additions & 0 deletions PIA-VPN_tvOS_E2E_Tests/Tests/DedicatedIPTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// DedicatedIPTests.swift
// PIA-VPN_tvOS_E2E_Tests
//
// Created by Geneva Parayno on 27/3/24.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Nimble

class DedicatedIPTests: BaseTest {
override class func spec() {
super.spec()

describe("dedicated ip tests") {
context("when activating dedicated ip tokens") {
it("should display an error notification for invalid tokens") {
app.navigateToSettingsScreen()
app.navigateToDedicatedIPScreen()
if(app.deleteDedicatedIPButton.exists) {
app.deleteDedicatedIP()
}
app.activateDIPToken(DIP: DedicatedIPUtil.dedicatedIP(type: .invalid))
expect(app.invalidTokenErrorMessage.waitForElementToAppear()).to(beTrue())
}

it("should display an error notification for empty token") {
app.navigateToSettingsScreen()
app.navigateToDedicatedIPScreen()
if(app.deleteDedicatedIPButton.exists) {
app.deleteDedicatedIP()
}
app.activateDIPToken(DIP: DedicatedIPUtil.dedicatedIP(type: .empty))
expect(app.emptyTokenErrorMessage.waitForElementToAppear()).to(beTrue())
}

it("should successully activate valid tokens") {
app.navigateToSettingsScreen()
app.navigateToDedicatedIPScreen()
if(app.deleteDedicatedIPButton.exists) {
app.deleteDedicatedIP()
}
app.activateDIPToken(DIP: DedicatedIPUtil.dedicatedIP(type: .valid))
expect(app.activeDIPStatus.waitForElementToAppear()).to(beTrue())
}
}

context("when deleting dedicated ip") {
it("should remove the dip from the list") {
app.navigateToSettingsScreen()
app.navigateToDedicatedIPScreen()
if(!app.deleteDedicatedIPButton.exists) {
app.activateDIPToken(DIP: DedicatedIPUtil.dedicatedIP(type: .valid))
}
app.deleteDedicatedIP()
expect(app.enterDedicatedIPTitle.waitForElementToAppear()).to(beTrue())
}
}
}
}
}
26 changes: 13 additions & 13 deletions PIA-VPN_tvOS_E2E_Tests/Tests/LocationSelectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class LocationSelectionTests:BaseTest {
describe("location selection tests") {
context("when the user goes to 'All' tab") {
it("then the user sees all available locations") {
app.navigateToLocationSelection()
app.navigateToAllLocations()
app.navigateToLocationSelectionScreen()
app.navigateToAllLocationsScreen()

expect(app.allLocationsTitle.exists).to(beTrue())
expect(app.optimalLocationsTitle.exists).to(beTrue())
Expand All @@ -26,37 +26,37 @@ class LocationSelectionTests:BaseTest {

context("when the user goes to 'Search' tab") {
it("should display recommended locations and search location button") {
app.navigateToLocationSelection()
app.navigateToSearchLocation()
app.navigateToLocationSelectionScreen()
app.navigateToSearchLocationScreen()
expect(app.searchForALocationButton.exists).to(beTrue())
expect(app.recommendedLocationsTitle.exists || app.lastSearchedLocationsTitle.exists).to(beTrue())
}

it("should return related results when the user searches a keyword") {
app.navigateToLocationSelection()
app.navigateToSearchLocation()
app.navigateToLocationSelectionScreen()
app.navigateToSearchLocationScreen()
app.searchLocation(keyword: "Chi")
expect(app.getSearchResultButtonLabels().allSatisfy{$0.contains("Chi")}).to(beTrue())
}
}

context("display of the favourites tab") {
it("should display the favourites tab when a region is added to favourites") {
app.navigateToLocationSelection()
app.navigateToAllLocations()
app.navigateToSearchLocation()
app.navigateToLocationSelectionScreen()
app.navigateToAllLocationsScreen()
app.navigateToSearchLocationScreen()
app.addToFavorites(region: "India")
expect(app.favouritesTabButton.exists).to(beTrue())
app.navigateToFavouriteLocation()
app.navigateToFavouriteLocationScreen()
expect(app.getSearchResultButtonLabels().contains{$0.contains("India")}).to(beTrue())
}

it("should hide the favourites tab when all regions are removed from favourites") {
app.navigateToLocationSelection()
app.navigateToSearchLocation()
app.navigateToLocationSelectionScreen()
app.navigateToSearchLocationScreen()
app.addToFavorites(region: "Peru")
app.addToFavorites(region: "Chile")
app.navigateToFavouriteLocation()
app.navigateToFavouriteLocationScreen()
app.removeAllRegionsFromFavorites()
expect(!app.favouritesTabButton.exists).to(beTrue())
}
Expand Down
2 changes: 1 addition & 1 deletion PIA-VPN_tvOS_E2E_Tests/Tests/OnboardingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OnboardingTests:BaseTest {
app.loginViaUsername(with: CredentialsUtil.credentials(type: .valid))
app.acceptSharingVPNStats()
app.acceptVPNConfiguration()
expect(app.connectButton.waitForExistence(timeout: app.defaultTimeout)).to(beTrue())
expect(app.connectButton.waitForElementToAppear()).to(beTrue())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions PIA-VPN_tvOS_E2E_Tests/Tests/SignInTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class SignInTests:BaseTest {
app.logout()
app.navigateToSignInScreen()
app.loginViaUsername(with: CredentialsUtil.credentials(type: .valid))
expect(app.helpImprovePIATitle.waitForExistence(timeout: app.defaultTimeout)).to(beTrue())
expect(app.helpImprovePIATitle.waitForElementToAppear()).to(beTrue())
}

it("should display error mesages with invalid credentials"){
app.logout()
app.navigateToSignInScreen()
app.loginViaUsername(with: CredentialsUtil.credentials(type: .invalid))
expect(app.incorrectCredentialsErrorMessage.waitForExistence(timeout: app.defaultTimeout)).to(beTrue())
expect(app.incorrectCredentialsErrorMessage.waitForElementToAppear()).to(beTrue())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PIA-VPN_tvOS_E2E_Tests/Util/CredentialsUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CredentialsUtil {
public static func credentials(type: CredentialsType) -> Credentials {
switch type {
case .invalid:
return Credentials(username: "fake", password: "fake")
return Credentials(username: "aaa", password: "Aaa")
case .valid:
let testUser = ProcessInfo.processInfo.environment["PIA_TEST_USER"] ?? "user-not-found"
let testPassword = ProcessInfo.processInfo.environment["PIA_TEST_PASSWORD"] ?? "password-not-found"
Expand Down
Loading

0 comments on commit 4df04ce

Please sign in to comment.