In UI test, I try to tap the call
button and cancel
button as below screenshot showed. That buttons are triggered when a user click on the phone number link from a UITextView.
And this Thread said we should use springboard to deal with URL scheme popups. But I get errors in console when I po the things.
That is the error in lldb.
Assertion failure in -[XCTFuture _waitForFulfillment], XCTFuture.m:159 error: Execution was interrupted, reason: internal ObjC exception breakpoint(-7)..
And I have created below minimum app to reproduce this problem.
ViewController
import UIKit
class ViewController: UIViewController, UITextViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Main View"
addUITextViews()
}
func addUITextViews(){
// lauout for the View
let myTextView3 = UITextView()
myTextView3.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(myTextView3)
let g = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
myTextView3.leadingAnchor.constraint(equalTo: g.leadingAnchor, constant: 40),
myTextView3.trailingAnchor.constraint(equalTo: g.trailingAnchor, constant: 40),
myTextView3.centerXAnchor.constraint(equalTo: view.centerXAnchor),
myTextView3.centerYAnchor.constraint(equalTo: view.centerYAnchor),
myTextView3.widthAnchor.constraint(equalToConstant: 400),
myTextView3.heightAnchor.constraint(equalToConstant: 400),
])
// set Phone# and Email Address for the UITextView
myTextView3.font = UIFont.systemFont(ofSize: 24)
myTextView3.isEditable = false
myTextView3.isSelectable = true
myTextView3.text = "Phone: 888-111-2222 \nEmail: sample@gmail.com"
myTextView3.dataDetectorTypes = .all
myTextView3.delegate = self
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
guard let currentScheme = URL.scheme else { return false }
switch currentScheme {
case "sms", "tel":
print("It is a call!")
case "mailto":
print("send email")
default: break
}
return true
}
}
UI Test
import XCTest
class InterHyperLinksUITests: XCTestCase {
var app: XCUIApplication!
var springboard: XCUIApplication!
override func setUpWithError() throws {
app = XCUIApplication()
springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
app.launch()
continueAfterFailure = false
}
func testPhoneCall() {
app.links["888-111-2222"].tap()
sleep(1)
springboard.buttons["Call (888) 111 2222"].tap()
// or try
springboard.buttons["Cancel"].tap()
}
}