5

Is there any way of testing the UIApplication shortcuts within XCUITests?

I know that in order to test 3d shortcuts in a simulator you need a trackpad with force touch, but I was wondering if I could write tests that test my shortcuts.

trusk
  • 1,634
  • 2
  • 18
  • 32
  • Were you able to find a solution for this? I am trying the suggestion from Chase Holland but it doesn't seam to work. I managed to present the app shortcuts menu but only once in a while, it doesn't seam to work reliably, but even when it is presented I can't tap on any of the shortcuts (not even with a mouse directly in the Simulator). Thanks for the update! – Miroslav Kovac Oct 02 '18 at 18:58
  • @MiroslavKovac sadly no – trusk Oct 04 '18 at 05:50

1 Answers1

0

Looks like yes! You'll need to expose a private API, though. Exported XCUIElement header from Facebook's WebDriverAgent here.

Or, if that's the only thing you need, just expose it ala:

@interface XCUIElement (Private)
    - (void)forcePress;
@end

And then to force press your icon by going to the springboard and getting your icon element see my answer here.

class Springboard {
    // this is another private method you'll need to expose (see linked other answer)
    static let springboard = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.springboard")


    /// Open the 3d touch menu
    class func open3dTouchMenu() {
        XCUIApplication().terminate() // this may or may not be necessary depending on your desired function / app state

        // Resolve the query for the springboard rather than launching it
        springboard.resolve()

        // Force delete the app from the springboard
        let icon = springboard.icons["MyAppName"]
        if icon.exists {
            icon.forcePress()
            // do something with the menu that comes up
        }
    }
 }

* I have not tested this yet.

Chase Holland
  • 2,178
  • 19
  • 23