Repository navigation
[WIP] UI Tests #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evgeniyChepelev
wants to merge
4
commits into
netbirdio:main
Choose a base branch
from
evgeniyChepelev:feature/ui-tests-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[WIP] UI Tests #257
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4ec424a
Add e2e UI tests for login, profiles and connection A NetBirdUITests…
evgeniyChepelev acb322e
Retype the profile name when the keyboard changes it
evgeniyChepelev 3c27ddc
Request the device e2e run when a PR is opened or updated
evgeniyChepelev 3af3d99
Send the e2e trigger to netbirdio/mobile-e2e by default
evgeniyChepelev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
NetBird.xcodeproj/xcshareddata/xcschemes/NetBirdE2E.xcscheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Scheme | ||
| LastUpgradeVersion = "2640" | ||
| version = "1.7"> | ||
| <BuildAction | ||
| parallelizeBuildables = "YES" | ||
| buildImplicitDependencies = "YES"> | ||
| <BuildActionEntries> | ||
| <BuildActionEntry | ||
| buildForTesting = "YES" | ||
| buildForRunning = "YES" | ||
| buildForProfiling = "NO" | ||
| buildForArchiving = "NO" | ||
| buildForAnalyzing = "NO"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "50A891162A792A15007C48FC" | ||
| BuildableName = "NetBird.app" | ||
| BlueprintName = "NetBird" | ||
| ReferencedContainer = "container:NetBird.xcodeproj"> | ||
| </BuildableReference> | ||
| </BuildActionEntry> | ||
| </BuildActionEntries> | ||
| </BuildAction> | ||
| <TestAction | ||
| buildConfiguration = "Debug" | ||
| selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
| selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
| shouldUseLaunchSchemeArgsEnv = "YES"> | ||
| <TestPlans> | ||
| <TestPlanReference | ||
| reference = "container:NetBirdUITests/E2E.xctestplan" | ||
| default = "YES"> | ||
| </TestPlanReference> | ||
| </TestPlans> | ||
| </TestAction> | ||
| <LaunchAction | ||
| buildConfiguration = "Debug" | ||
| selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
| selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
| launchStyle = "0" | ||
| useCustomWorkingDirectory = "NO" | ||
| ignoresPersistentStateOnLaunch = "NO" | ||
| debugDocumentVersioning = "YES" | ||
| debugServiceExtension = "internal" | ||
| allowLocationSimulation = "YES"> | ||
| <BuildableProductRunnable | ||
| runnableDebuggingMode = "0"> | ||
| <BuildableReference | ||
| BuildableIdentifier = "primary" | ||
| BlueprintIdentifier = "50A891162A792A15007C48FC" | ||
| BuildableName = "NetBird.app" | ||
| BlueprintName = "NetBird" | ||
| ReferencedContainer = "container:NetBird.xcodeproj"> | ||
| </BuildableReference> | ||
| </BuildableProductRunnable> | ||
| </LaunchAction> | ||
| <ProfileAction | ||
| buildConfiguration = "Release" | ||
| shouldUseLaunchSchemeArgsEnv = "YES" | ||
| savedToolIdentifier = "" | ||
| useCustomWorkingDirectory = "NO" | ||
| debugDocumentVersioning = "YES"> | ||
| </ProfileAction> | ||
| <AnalyzeAction | ||
| buildConfiguration = "Debug"> | ||
| </AnalyzeAction> | ||
| <ArchiveAction | ||
| buildConfiguration = "Release" | ||
| revealArchiveInOrganizer = "YES"> | ||
| </ArchiveAction> | ||
| </Scheme> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| // | ||
| // ConnectionTests.swift | ||
| // NetBirdUITests | ||
| // | ||
| // Section H of the login UI test plan: the connection once a login is done. | ||
| // | ||
|
|
||
| import XCTest | ||
|
|
||
| final class ConnectionTests: E2ETestCase { | ||
|
|
||
| /// LOGIN-H01 — a successful login lands on a usable connection: the | ||
| /// status reads Connected, the peer's NetBird name and address are shown, | ||
| /// and the Peers tab lists the network. | ||
| func testH01_loginLandsOnUsableConnection() throws { | ||
| try requireDevice() | ||
| let profile = try createSignedInProfile() | ||
|
|
||
| step("Connect \(profile)") { | ||
| profiles.switchTo(profile) | ||
| connectWithoutLogin() | ||
| XCTAssertTrue(app.staticTexts["Connected"].exists, "the status does not read Connected") | ||
| } | ||
|
|
||
| step("The peer's name and address are shown") { | ||
| // Both arrive with the first network map, a moment after Connected. | ||
| XCTAssertTrue(connection.fqdn.waitForExistence(timeout: 30), | ||
| "no NetBird name under the status within 30 s") | ||
| XCTAssertTrue(connection.ip.waitForExistence(timeout: 30), | ||
| "no NetBird address (100.x.x.x) under the status within 30 s") | ||
| } | ||
| screenshot("Connected with name \(connection.fqdn.label), address \(connection.ip.label)") | ||
|
|
||
| step("The Peers tab renders") { | ||
| TabBar(app: app).open("Peers") | ||
| XCTAssertTrue(app.staticTexts["Peers connected"].waitForExistence(timeout: 5), "the Peers tab did not render") | ||
| let count = app.staticTexts.matching(NSPredicate(format: "label MATCHES %@", "^[0-9]+ of [0-9]+$")).firstMatch | ||
| XCTAssertTrue(count.exists, "the Peers tab shows no \"N of M\" count") | ||
| } | ||
| screenshot("Peers") | ||
| markPassed() | ||
| } | ||
|
|
||
| /// LOGIN-H02 — disconnecting ends the session cleanly: the status reads | ||
| /// Disconnected and no error follows. | ||
| /// | ||
| /// The plan also expects the name and address to be cleared or hidden. | ||
| /// The app clears them on a server or profile change but keeps them across | ||
| /// a plain disconnect — the peer's identity does not change — so whether | ||
| /// they stay is recorded with the result rather than failed on. | ||
| func testH02_disconnectEndsTheSessionCleanly() throws { | ||
| try requireDevice() | ||
| let profile = try createSignedInProfile() | ||
|
|
||
| step("Connect \(profile)") { | ||
| profiles.switchTo(profile) | ||
| connectWithoutLogin() | ||
| _ = connection.ip.waitForExistence(timeout: 30) | ||
| } | ||
|
|
||
| step("Disconnect") { | ||
| connection.disconnect() | ||
| XCTAssertTrue(app.staticTexts["Disconnected"].waitForExistence(timeout: 10), "the status does not read Disconnected") | ||
| XCTAssertEqual(app.alerts.count, 0, "an alert followed the disconnect: \(app.alerts.firstMatch.label)") | ||
| } | ||
|
|
||
| let kept = [connection.fqdn.exists ? "name" : nil, connection.ip.exists ? "address" : nil].compactMap { $0 } | ||
| XCTContext.runActivity(named: kept.isEmpty ? "Name and address are cleared" | ||
| : "Still shown after the disconnect: \(kept.joined(separator: ", "))") { _ in } | ||
| screenshot("After disconnecting") | ||
| markPassed() | ||
| } | ||
|
|
||
| /// LOGIN-H03 — two quick taps on the toggle do not leave it stuck: it | ||
| /// settles on Connected or Disconnected, and from there connects normally | ||
| /// without a login. | ||
| /// | ||
| /// The toggle treats the second tap as "disconnect", so either end state is | ||
| /// fine; what must not happen is a toggle stuck between the two. | ||
| func testH03_doubleTapDoesNotLeaveTheToggleStuck() throws { | ||
| try requireDevice() | ||
| let profile = try createSignedInProfile() | ||
| profiles.switchTo(profile) | ||
| TabBar(app: app).open("Connection") | ||
|
|
||
| step("Tap the toggle twice in quick succession") { | ||
| XCTAssertTrue(connection.toggle.waitForExistence(timeout: 10), "no connect toggle") | ||
| connection.toggle.tap() | ||
| connection.toggle.tap() | ||
| } | ||
|
|
||
| step("The toggle settles within 60 s") { | ||
| let settled = settledState(within: 60) | ||
| XCTAssertNotNil(settled, "the toggle is stuck at \(connection.state)") | ||
| XCTContext.runActivity(named: "Settled on \(settled ?? "nothing")") { _ in } | ||
| XCTAssertFalse(SignInAlert.isShowing, "a login was asked for") | ||
| XCTAssertFalse(app.alerts["Login failed"].exists, "a login error is shown") | ||
| } | ||
|
|
||
| step("It still connects normally") { | ||
| if connection.state != "Connected" { | ||
| connectWithoutLogin() | ||
| } | ||
| } | ||
| markPassed() | ||
| } | ||
|
|
||
| /// LOGIN-H04 — the connected state survives a force-quit: the tunnel runs | ||
| /// in the extension, so the relaunched app must show Connected, not a | ||
| /// stale Disconnected. | ||
| func testH04_connectedStateSurvivesRelaunch() throws { | ||
| try requireDevice() | ||
| let profile = try createSignedInProfile() | ||
|
|
||
| step("Connect \(profile)") { | ||
| profiles.switchTo(profile) | ||
| connectWithoutLogin() | ||
| } | ||
|
|
||
| step("Force-quit and relaunch") { | ||
| relaunch() | ||
| } | ||
|
|
||
| step("The app shows the running tunnel") { | ||
| TabBar(app: app).open("Connection") | ||
| let connected = NSPredicate(format: "value == %@", "Connected") | ||
| XCTAssertEqual(XCTWaiter().wait(for: [XCTNSPredicateExpectation(predicate: connected, object: connection.toggle)], | ||
| timeout: 15), .completed, | ||
| "after a relaunch the toggle shows \(connection.state)") | ||
| } | ||
| screenshot("After relaunch") | ||
| markPassed() | ||
| } | ||
|
|
||
| /// LOGIN-H05 — On Demand on a profile without credentials does not start | ||
| /// a reconnect loop. | ||
| /// | ||
| /// Asking once for a login is fine — On Demand cannot work without one, | ||
| /// and the app saying so ("Authentication required", Login / Later) is | ||
| /// the right answer. What the plan's case guards against is a loop: the | ||
| /// VPN retrying on its own and the prompt coming back again and again, or | ||
| /// the VPN coming up without credentials. So one prompt is answered with | ||
| /// Later, and the case fails only if another follows or the VPN connects. | ||
| /// | ||
| /// The plan expects the toggle to be refused; the app may instead keep the | ||
| /// preference and defer the rules. Which one happened is recorded. | ||
| /// | ||
| /// On Demand is a device-wide setting, so it is switched off again whatever | ||
| /// the outcome, unlike the rest of the state a failing test leaves behind. | ||
| func testH05_onDemandWithoutCredentialsDoesNotLoop() throws { | ||
| try requireDevice() | ||
| let profile = createSignedOutProfile() | ||
| profiles.switchTo(profile) | ||
|
|
||
| let onDemand = OnDemandScreen(app: app) | ||
| addTeardownBlock { [app] in | ||
| // An alert the case itself provoked would cover the switch. | ||
| AppAlerts.dismissAll(in: app!) | ||
| let screen = OnDemandScreen(app: app!) | ||
| screen.open() | ||
| screen.set(false) | ||
| } | ||
|
|
||
| step("Turn On Demand on") { | ||
| onDemand.open() | ||
| onDemand.set(true) | ||
| XCTContext.runActivity(named: onDemand.isOn ? "The toggle stays on (rules deferred)" : "The toggle was refused") { _ in } | ||
| screenshot("On Demand on a signed-out profile") | ||
| } | ||
|
|
||
| step("For 30 s: at most one login prompt, and no connection") { | ||
| var prompts = 0 | ||
| let deadline = Date().addingTimeInterval(30) | ||
| while Date() < deadline { | ||
| let prompt = app.alerts["Authentication required"] | ||
| if prompt.exists { | ||
| prompts += 1 | ||
| screenshot("Login prompt \(prompts)") | ||
| prompt.buttons["Later"].tap() | ||
| } | ||
| XCTAssertFalse(SignInAlert.isShowing, "On Demand opened the login browser on its own") | ||
| XCTAssertNotEqual(connection.state, "Connected", "the VPN connected without credentials") | ||
| Thread.sleep(forTimeInterval: 1) | ||
| } | ||
| XCTContext.runActivity(named: "Login prompts in 30 s: \(prompts)") { _ in } | ||
| XCTAssertLessThanOrEqual(prompts, 1, "the login prompt kept coming back: \(prompts) times in 30 s") | ||
| let others = app.alerts.allElementsBoundByIndex.map(\.label) | ||
| XCTAssertTrue(others.isEmpty, "another alert came up: \(others)") | ||
| TabBar(app: app).open("Connection") | ||
| XCTAssertNotEqual(connection.state, "Connected", "the VPN connected without credentials") | ||
| } | ||
| markPassed() | ||
| } | ||
|
|
||
| /// Waits for the toggle to rest on Connected or Disconnected for 5 s in a | ||
| /// row, accepting the VPN configuration prompt on the way. | ||
| private func settledState(within timeout: TimeInterval) -> String? { | ||
| let deadline = Date().addingTimeInterval(timeout) | ||
| var stableSince = Date() | ||
| var last = "" | ||
| while Date() < deadline { | ||
| SystemAlerts.acceptIfPresent(timeout: 0.5) | ||
| let value = connection.state | ||
| if value != last { | ||
| last = value | ||
| stableSince = Date() | ||
| } | ||
| if ["Connected", "Disconnected"].contains(value) && Date().timeIntervalSince(stableSince) >= 5 { | ||
| return value | ||
| } | ||
| Thread.sleep(forTimeInterval: 0.5) | ||
| } | ||
| return nil | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "configurations" : [ | ||
| { | ||
| "id" : "ADA7FFED-6061-4270-B142-E30B22D45CB8", | ||
| "name" : "Default", | ||
| "options" : { | ||
|
|
||
| } | ||
| } | ||
| ], | ||
| "defaultOptions" : { | ||
| "defaultTestExecutionTimeAllowance" : 600, | ||
| "preferredScreenCaptureFormat" : "video", | ||
| "targetForVariableExpansion" : { | ||
| "containerPath" : "container:NetBird.xcodeproj", | ||
| "identifier" : "50A891162A792A15007C48FC", | ||
| "name" : "NetBird" | ||
| }, | ||
| "testTimeoutsEnabled" : true, | ||
| "uiTestingScreenshotsLifetime" : "keepAlways" | ||
| }, | ||
| "testTargets" : [ | ||
| { | ||
| "target" : { | ||
| "containerPath" : "container:NetBird.xcodeproj", | ||
| "identifier" : "E2E000012F40000000000003", | ||
| "name" : "NetBirdUITests" | ||
| } | ||
| } | ||
| ], | ||
| "version" : 1 | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: netbirdio/ios-client
Length of output: 5115
Script executed:
Repository: netbirdio/ios-client
Length of output: 7936
Select the Connection tab before the polling loop.
OnDemandScreen.open()selects Settings, andConnectionScreen.statereturns""when the toggle is not visible. The loop can therefore miss a connection that starts and ends during the 30-second window. The test selects Connection only after the loop.Suggested fix
step("For 30 s: at most one login prompt, and no connection") { + TabBar(app: app).open("Connection") var prompts = 0