XCUICoordinate tap() or press(forDuration:) methods work only in portrait orientation

Originator:bartosz.janda
Number:rdar://31529903 Date Originated:2017.04.10
Status:Open Resolved:No
Product:iOS + SDK Product Version:Xcode 8.3.1
Classification: Reproducible:Always
 
XCUIElement provides method `coordinate(withNormalizedOffset:)` which returns XCUICoordinate objects with a position on the screen. The `screenPoint` is always computed correctly in any device orientation. But actions like tap or press interpret screen points as if the device was in portrait position.

element.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)).screenPoint

Above method will always return center position of the element on the screen on each orientation, but different elements will be tapped depending on the device orientation.
Problem probably exists because the `XCUIApplication` frame returns values as if the device was in the the portrait, but all its windows has correct frame. Output from the `debugDescription`:

"Attributes: Application 0x600000175780: {{0.0, 0.0}, {768.0, 1024.0}}, label: \'Test\'
Element subtree:
 →Application 0x600000175780: {{0.0, 0.0}, {768.0, 1024.0}}, label: \'Test\'
    Window 0x600000175840: Main Window, {{0.0, 0.0}, {1024.0, 768.0}}
      Other 0x600000175a80: traits: 8589934592, {{0.0, 0.0}, {1024.0, 768.0}}, identifier: \'mainView\'
        Button 0x600000174dc0: traits: 8589934593, {{20.0, 8.0}, {60.0, 60.0}}, label: \'Button A\'
        Button 0x600000175600: traits: 8589934593, {{944.0, 8.0}, {60.0, 60.0}}, label: \'Button B\'
        StaticText 0x6000001771c0: traits: 8589934656, {{491.0, 374.0}, {42.0, 20.5}}, identifier: \'label\', label: \'Label\'
        Button 0x600000176f80: traits: 8589934593, {{20.0, 699.0}, {61.0, 61.0}}, label: \'Button C\'
        Button 0x6000001768c0: traits: 8589934593, {{943.0, 699.0}, {61.0, 61.0}}, label: \'Button D\'
    Window 0x600000176980: {{0.0, 0.0}, {1024.0, 768.0}}
      StatusBar 0x600000177400: {{0.0, 0.0}, {1024.0, 20.0}}
        Other 0x600000177340: {{0.0, 0.0}, {1024.0, 20.0}}
        Other 0x600000177880: {{0.0, 0.0}, {1024.0, 20.0}}
          Other 0x600000177940: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
          Other 0x600000178480: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: \'3 of 3 Wi-Fi bars\', value: SSID
          Other 0x600000178900: traits: 8389120, {{487.0, 0.0}, {54.0, 20.0}}, label: \'12:10 PM\'
          Other 0x6000001786c0: traits: 8388608, {{960.0, 0.0}, {59.0, 20.0}}, label: \'-100% battery power\'
          Other 0x600000178b40: traits: 8388608, {{960.0, 0.0}, {31.0, 20.0}}, label: \'100% battery power\'
          Path to element:
 →Application 0x600000175780: {{0.0, 0.0}, {768.0, 1024.0}}, label: \'Test\'
 Query chain:
 →Find: Target Application 0x6100000bfa40
  Output: {
    Application 0x600000175780: {{0.0, 0.0}, {768.0, 1024.0}}, label: \'Test\'
  }
  "

Steps to Reproduce:
- Open Test application attached to this bug report with Xcode
- Run "TestUITests" test case
- In all tests, the same button is used to tap, but depending on the orientation different button was really tapped.

Expected Results:
In all orientations, the same button should be tapped.

Actual Results:
In portrait orientation Button A is tapped (correct)
In landscape left orientation Button C is tapped (incorrect)
In landscape right orientation Button B is tapped (incorrect)
In upside-down orientation Button D is tapped (incorrect)


Version:
iPad Air 2 10.3 (Simulator)

Configuration:
Xcode 8.3.1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!