Skip to content
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

Update deeplink tests #172

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions SwiftUIDemoAppUITests/Tests/DeeplinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ final class DeeplinkTests: StreamTestCase {
}

func test_associationFile_validationWasSuccessful() throws {
linkToScenario(withId: 2855)

let contentData = try Data(contentsOf: .init(string: "https://getstream.io/.well-known/apple-app-site-association")!)
let content = try XCTUnwrap(String(data: contentData, encoding: .utf8))
.trimmingCharacters(in: .whitespacesAndNewlines)
Expand All @@ -38,10 +40,13 @@ final class DeeplinkTests: StreamTestCase {
}

func test_universalLink_production_joinsExpectedCall() {
WHEN("") {
linkToScenario(withId: 2856)

WHEN("user navigates to the app through deeplink") {
Safari()
.open(MockDeeplink.production)
.tapButton("OPEN")
.alertHandler()
.tapOnOpenButton()
}
THEN("user joins the the specified call") {
userRobot
Expand All @@ -51,10 +56,12 @@ final class DeeplinkTests: StreamTestCase {
}

func test_customSchemeURL_joinsExpectedCall() {
WHEN("User opens a URL that contains a custom scheme") {
linkToScenario(withId: 2857)

WHEN("user opens a URL that contains a custom scheme") {
Safari()
.open(MockDeeplink.customScheme)
.tapButton("Open")
.tapOnOpenButton()
}
THEN("user joins the the specified call") {
userRobot
Expand Down
50 changes: 33 additions & 17 deletions TestTools/UITests/Safari.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,56 @@ import XCTest

struct Safari {

private let application = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
private let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")

init() {}

private func go(to url: URL) -> Self {
application.textFields["Address"].tap()
application.typeText(url.absoluteString)
let goButton = application.buttons["Go"]
safari.textFields["Address"].tap()
safari.typeText(url.absoluteString)
let goButton = safari.buttons["Go"]
if goButton.waitForExistence(timeout: 5) {
application.tapKeyboardKey("Go")
safari.tapKeyboardKey("Go")
}

return self
}

@discardableResult
func open(_ url: URL) -> Self {
application.launch()
safari.launch()
_ = safari.wait(for: .runningForeground, timeout: 5)
if #available(iOS 16.4, *) {
safari.open(url)
return self
} else {
// Type the deeplink and execute it
let firstLaunchContinueButton = safari.buttons["Continue"]
if firstLaunchContinueButton.exists {
firstLaunchContinueButton.tap()
}

_ = application.wait(for: .runningForeground, timeout: 5)

// Type the deeplink and execute it
let firstLaunchContinueButton = application.buttons["Continue"]
if firstLaunchContinueButton.exists {
firstLaunchContinueButton.tap()
return go(to: url)
}

return go(to: url)
}

@discardableResult
func alertHandler() -> Self {
safari.buttons["ReloadButton"].wait()
if safari.alerts.count > 0 {
while safari.alerts.count > 0 {
safari.alerts.buttons["Allow"].safeTap()
}
}
return self
}

@discardableResult
func tapButton(_ label: String, _ timeout: TimeInterval = 5) -> Self {
application
.buttons[label]
func tapOnOpenButton(_ timeout: TimeInterval = 5) -> Self {
safari
.buttons
.matching(NSPredicate(format: "label LIKE 'OPEN' OR label LIKE 'Open'"))
.firstMatch
.wait(timeout: timeout)
.tap()

Expand Down
Loading