XCUIElement's Print Statement Not Including Nested Button

27 views Asked by At

Example Image:

enter image description here

Desired Behavior: When an XCUIElement is rendered from a screen with (Initial Conditions): An ImageView with..

isUserInteractionEnabled = YES…
IsAccessibilityElement = YES…

A nested button…

isUserInteractionEnabled = YES…
IsAccessibilityElement = YES…

Assigned to the ImageViews accessibility elements array XCUIElement’s print statement includes the nested button

Current Code:

parentImageView.image = UIImage(systemName: "mountain.2")
    parentImageView.translatesAutoresizingMaskIntoConstraints = false
    parentImageView.addGestureRecognizer(parentImageViewTapGesture)
    parentImageView.layer.cornerRadius = 4
    parentImageView.layer.borderWidth = 1
    parentImageView.layer.borderColor = UIColor.systemBlue.cgColor
    parentImageView.clipsToBounds = true
    parentImageView.accessibilityLabel = "demo image"
    parentImageView.isUserInteractionEnabled = true
    parentImageView.isAccessibilityElement = true
    addSubview(parentImageView)

    favoriteButton.setImage(UIImage(systemName: "heart"), for: .normal)
    favoriteButton.backgroundColor = .lightGray
    favoriteButton.layer.cornerRadius = 4
    favoriteButton.translatesAutoresizingMaskIntoConstraints = false
    favoriteButton.addTarget(self, action: #selector(self.favoriteButtonTapped), for: .touchUpInside)
    favoriteButton.clipsToBounds = true
    favoriteButton.accessibilityLabel = "Nested Button"
    favoriteButton.isUserInteractionEnabled = true
    parentImageView.addSubview(favoriteButton)

    parentImageView.accessibilityElements = [favoriteButton]

Current Behavior: When an XCUIElement is rendered from a screen with: (above Initial Conditions) XCUIElement’s print statement only include the ImageView

Debug Print:

Image View with No Descendants - Image, 0x7fa875d23e80, {{172.7, 292.7}, {45.0, 41.7}}, label: 'demo image' po element.images and po element.buttons -

Find: Descendants matching type Image
    Output: {
      Image, 0x7fa876e14e70, {{-8.0, 99.0}, {136.7, 109.3}}
      Image, 0x7fa876e14f80, {{-8.0, 741.7}, {136.7, 102.3}}
      Image, 0x7fa876e13da0, {{269.7, 737.0}, {136.3, 123.0}}
      Image, 0x7fa876e1a060, {{172.7, 292.7}, {45.0, 41.7}}, label: 'demo image'
    }

Output: {
      Button, 0x7fa875c12740, {{0.0, 47.0}, {68.0, 44.0}}, label: 'myApp UIKit'
      Button, 0x7fa875c24f00, {{338.0, 47.0}, {44.0, 44.0}}, identifier: 'Settings Button', label: 'Settings'
      Button, 0x7fa875c2c800, {{175.0, 533.0}, {40.0, 40.0}}
      Button, 0x7fa875c2cf30, {{183.0, 541.0}, {24.0, 24.0}}
      Button, 0x7fa875c2fa20, {{40.0, 659.3}, {153.0, 44.0}}, label: 'Left'
      Button, 0x7fa875c30cd0, {{197.0, 659.3}, {153.0, 44.0}}, label: 'Right'
    }

Comparing the coordinates of the parent image view and the nested button, the button isn't here. The 24x24 button that appears comes from another view on the same screen, noting the ample y coordinate from the parent image view's y coordinate.

Attempted Fixes: Combinations of the Initial Conditions: Attempted all combinations of Initial Condition variable values. (ie:

myImageView.accessibilityElements = [imageView, nestedButton]

myImageView.accessibilityElements = [nestedButton]

isUserInteractionEnabled = YES/NO [for both] IsAccessibilityElement = YES/NO [for both] etc for every combination of the different accessibility vars…)

0

There are 0 answers