Skip to content

Commit

Permalink
Improved teardowns
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund committed May 15, 2024
1 parent cb52f80 commit 3fd09c3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
24 changes: 23 additions & 1 deletion ios/MullvadVPNUITests/RelayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import XCTest

fileprivate struct RelayInfo {
private struct RelayInfo {
var name: String
var ipAddress: String
}
Expand Down Expand Up @@ -93,6 +93,17 @@ class RelayTests: LoggedInWithTimeUITestCase {
FirewallAPIClient().removeRules()
removeFirewallRulesInTearDown = true

addTeardownBlock {
TunnelControlPage(self.app)
.tapSelectLocationButton()

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

TunnelControlPage(self.app)
.tapCancelButton()
}

// First get relay IP address
let relayInfo = getGothenburgRelayInfo()

Expand Down Expand Up @@ -160,6 +171,17 @@ class RelayTests: LoggedInWithTimeUITestCase {
FirewallAPIClient().removeRules()
removeFirewallRulesInTearDown = true

addTeardownBlock {
TunnelControlPage(self.app)
.tapSelectLocationButton()

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

TunnelControlPage(self.app)
.tapCancelButton()
}

// First get relay IP address
let relayInfo = getGothenburgRelayInfo()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,41 @@
//

import Foundation
import XCTest

/// Base class for tests that should start from a state of being logged on to an account with time left
class LoggedInWithTimeUITestCase: BaseUITestCase {
var hasTimeAccountNumber: String?

override func setUp() {
super.setUp()

let hasTimeAccountNumber = getAccountWithTime()

addTeardownBlock {
self.returnAccountWithTime(accountNumber: hasTimeAccountNumber)
}
hasTimeAccountNumber = getAccountWithTime()

agreeToTermsOfServiceIfShown()
dismissChangeLogIfShown()
logoutIfLoggedIn()

guard let hasTimeAccountNumber = self.hasTimeAccountNumber else {
XCTFail("hasTimeAccountNumber unexpectedly not set")
return
}

login(accountNumber: hasTimeAccountNumber)

// Relaunch app so that tests start from a deterministic state
app.terminate()
app.launch()
}

override func tearDown() {
guard let hasTimeAccountNumber = self.hasTimeAccountNumber else {
XCTFail("hasTimeAccountNumber unexpectedly not set")
return
}

app.terminate() // Terminate app to make sure we have Internet connectivity
self.returnAccountWithTime(accountNumber: hasTimeAccountNumber)
app.launch()
}
}

0 comments on commit 3fd09c3

Please sign in to comment.