SmartXCUICoordinate

open class SmartXCUICoordinate

Replacement for XCUICoordinate which works in portrait and landscape orientations.

XCUICoordinate has an open issue. Coordinates works correctly only in portrait orientation. This workaround was implemented based on glebon gist.

Example:

let element = app.tableViews.element
element.smartCoordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
SmartXCUICoordinate(referencedElement: element, normalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()

Note

rdar://31529903 XCUICoordinate tap() or press(forDuration:) methods work only in portrait orientation.

Remark

This functionality was implemented based on glebon gist.
  • The element that the coordinate is based on, either directly or via the coordinate from which it was derived.

    Declaration

    Swift

    open let referencedElement: XCUIElement
  • Normalized offset from the elements origin position.

    Declaration

    Swift

    open let normalizedOffset: CGVector
  • Real coordinates in the portrait orientation.

    Declaration

    Swift

    open var realCoordinate: XCUICoordinate
  • Initialize new smart coordinate with a normalized offset.

    Example:

    let smartCoordinate = SmartXCUICoordinate(referencedElement: element, normalizedOffset: CGVector(dx: 0.5, dy: 0.5))
    

    Declaration

    Swift

    public init(referencedElement: XCUIElement, normalizedOffset offset: CGVector, app: XCUIApplication = XCUIApplication(), orientation: UIDeviceOrientation = XCUIDevice.shared().orientation)

    Parameters

    referencedElement

    The element that the coordinate is based on, either directly or via the coordinate from which it was derived.

    offset

    Normalized offset from the elements origin position.

    app

    Application object used to calculate portrait screen position.

    orientation

    Device orientation.

  • Sends a tap event at the coordinate.

    Example:

    let element = app.tableViews.element
    element.smartCoordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).tap()
    

    Remark

    Wrapped XCUICoordinate method.

    Declaration

    Swift

    open func tap()
  • Sends a double tap event at the coordinate.

    Example:

    let element = app.tableViews.element
    element.smartCoordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).doubleTap()
    

    Remark

    Wrapped XCUICoordinate method.

    Declaration

    Swift

    open func doubleTap()
  • Sends a long press gesture at the coordinate, holding for the specified duration.

    Example:

    let element = app.tableViews.element
    element.smartCoordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).press(forDuration: 2)
    

    Remark

    Wrapped XCUICoordinate method.

    Declaration

    Swift

    open func press(forDuration duration: TimeInterval)

    Parameters

    duration

    Holding duration.

  • Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.

    Example:

    let element = app.tableViews.element
    element.smartCoordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).press(forDuration: 1, thenDragTo: otherCoordinate)
    

    Remark

    Wrapped XCUICoordinate method.

    Declaration

    Swift

    open func press(forDuration duration: TimeInterval, thenDragTo otherCoordinate: XCUICoordinate)

    Parameters

    duration

    Holding duration.

    otherCoordinate

    Coordinate to drag to.

  • Initiates a press-and-hold gesture at the coordinate, then drags to another coordinate.

    Example:

    let element = app.tableViews.element
    element.smartCoordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).press(forDuration: 1, thenDragTo: otherCoordinate)
    

    Remark

    Wrapped XCUICoordinate method.

    Declaration

    Swift

    open func press(forDuration duration: TimeInterval, thenDragTo otherCoordinate: SmartXCUICoordinate)

    Parameters

    duration

    Holding duration.

    otherCoordinate

    Coordinate to drag to.