Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

fix: use Public API on Xcode10.2 #81

Merged
merged 2 commits into from
Oct 4, 2019
Merged

Conversation

a455455b
Copy link
Contributor

Temporarily resolve the failure of the base gesture when xcode10.2. #75 #73

let coordinate = app.coordinate(withNormalizedOffset: CGVector(dx: locations[0].x/(app.frame.maxX/2), dy: locations[0].y/(app.frame.maxY/2)))
coordinate.tap()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thanks for the feedback! Your implementation does not really utilize multiple touches, as this API is not available on the XCUICoordinate object. Also I noticed that touches have tendency to cluster on the edges of the screen:

I am also concerned by let app = XCUIApplication() inside the action. According to #70 it might cause memory bloat. Here is how I would change the code:

Suggested change
}
/// Add an action that generates a tap, with a possibility for double taps, using the public XCTest API.
/// - Parameter app: The application proxy.
/// - Parameter weight: The relative probability of this event being generated. Can be any value larger than zero. Probabilities
/// will be normalised to the sum of all relative probabilities.
/// - Parameter doubleTapProbability: Probability that a double tap event is used. Between 0 and 1.
public func addXCTestPublicTapAction(app: XCUIApplication,
weight: Double,
doubleTapProbability: Double = 0.05) {
addAction(weight: weight) { [unowned self] in
let doubleTap = self.r.randomDouble() < doubleTapProbability
let coordinate = app.coordinate(withNormalizedOffset: .zero).withOffset(self.randomOffset())
if doubleTap {
coordinate.doubleTap()
} else {
coordinate.tap()
}
}
}

Notice that I've replaced multipleTouchProbability with doubleTapProbability as this is supported directly by the XCUICoordinate class. I haven't tested though whether tapping immediately multiple coordinates would generate a multi-touch event. I would also add the app parameter to the addDefaultXCTestPublicActions method, e.g:

public func addDefaultXCTestPublicActions(app: XCUIApplication) {
    addXCTestPublicTapAction(app: app, weight: 25)
    addXCTestPublicLongPressAction(app: app, weight: 1)
    addXCTestPublicDragAction(app: app, weight: 1)
}

What do you think @a455455b ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to attach the code for randomVector() method (though it's very straightforward):

/// Generates a random `CGVector` inside the frame of the app.
public func randomOffset() -> CGVector {
    let point = randomPoint()
    return CGVector(dx: point.x, dy: point.y)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good, it gave me a lot of inspiration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need me to modify and resubmit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ideally you could try adapting other methods that you've added (add the app parameter, compute coordinates properly, etc.).

If you wish I can also do it myself by providing code suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi,I submitted a fix.

@wojciechczerski
Copy link
Member

Nicely done @a455455b, thank you very much! I think we can merge that one and after that I'll try looking for whether we can simulate pinch gestures and multi-touch.

@wojciechczerski
Copy link
Member

👍

@a455455b
Copy link
Contributor Author

a455455b commented Oct 4, 2019

@wojciechczerski I don't have permission to execute, I hope you can finish it, and the solution I implemented in Firebase Test Lab is to iterate through all the clickable elements and click on them randomly, it works but it's slow. Do you have any suggestions?

@wojciechczerski
Copy link
Member

Could you try giving this PR a 👍 (just as I did)? If that doesn't work I'll ask someone in the office to approve it.

@a455455b
Copy link
Contributor Author

a455455b commented Oct 4, 2019

👍

@wojciechczerski wojciechczerski merged commit 0f6849d into zalando:master Oct 4, 2019
@wojciechczerski
Copy link
Member

@a455455b Merged! 🎉 🎊

@a455455b
Copy link
Contributor Author

a455455b commented Oct 4, 2019

Thanks, I am looking for a better traversal element scheme, if I find I will submit a new PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants