Skip to content

Commit

Permalink
Update deeplink tests (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple authored Oct 3, 2023
1 parent 580c431 commit d70e7ed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
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

0 comments on commit d70e7ed

Please sign in to comment.