0

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.

enter image description here

enter image description here

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()
    }
}
Zhou Haibo
  • 1,681
  • 1
  • 12
  • 32
  • I have found the solution, please check this thread https://stackoverflow.com/questions/71246393/how-to-locate-element-on-system-action-sheet-in-ios-ui-test – Zhou Haibo Feb 25 '22 at 09:22
  • Good stuff! That was going to be my suggestion; wait for it to really get up and running. Your error points to trying to do something in some interstitial state. – Mike Collins Feb 25 '22 at 15:49
  • yeah, it is a workaround though I still wonder why Xcode needs to wait that long time for Springboard became available – Zhou Haibo Feb 26 '22 at 03:57

0 Answers0