ios11xcode9xctestxcode-ui-testingswift3.2

How to pinch with two fingers in iOS app automation with swift


I want to apply pinch-in and pinch-out gesture into a imageView in my application.

I am using Xcode9 and swift 3.2

I could not able to tap on specific two coordinate at a time of my desired image

app.scrollViews.scrollViews.images.element(boundBy: 0)

Solution

  • For zoom in or zoom out you have to use pinch(withScale:velocity:) method of xctest.

    Your code should look like below

    let image = app.scrollViews.scrollViews.images.element(boundBy: 0)
    

    Zoom in:

    image.pinch(withScale: 3, velocity: 1) // zoom in
    

    Zoom out:

    image.pinch(withScale: 0.5, velocity: -1) // zoom out
    

    According to api documentation of pinch(withScale:velocity:) negative velocity is for zoom out and positive velocity is for zoom in

    Please use the above code and let me know your feedback.