-
Notifications
You must be signed in to change notification settings - Fork 174
Conversation
let coordinate = app.coordinate(withNormalizedOffset: CGVector(dx: locations[0].x/(app.frame.maxX/2), dy: locations[0].y/(app.frame.maxY/2))) | ||
coordinate.tap() | ||
} | ||
} |
There was a problem hiding this comment.
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:
} | |
/// 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 ?
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 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? |
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 Merged! 🎉 🎊 |
Thanks, I am looking for a better traversal element scheme, if I find I will submit a new PR |
Temporarily resolve the failure of the base gesture when xcode10.2. #75 #73