UI 测试:从 UITextView 打开 URL 方案后找不到跳板按钮元素
在 UI 测试中,我尝试点击 call
按钮和 cancel
按钮,如下图所示。当用户单击 UITextView 中的电话号码链接时,会触发该按钮。
这个线程说我们应该使用跳板来处理URL方案弹出窗口。但是当我 po 东西时,我在控制台中收到错误。
这是lldb中的错误。
-[XCTFuture _waitForFulfillment] 中断言失败,XCTFuture.m:159 错误:执行被中断,原因:ObjC 内部异常断点(-7)..
并且我创建了以下最小应用程序来重现此问题。
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: [email protected]"
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 测试
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()
}
}
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: [email protected]"
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()
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论