UI Testing can't query an element with correct id

Hi all:


I create a Custom UIView, named "HeaderView" and add it into a tableView's subview,

and I set the HeaderView's isAccessibilityElement to "NO" and set the HeaderView's subview "SettingBbutton" with accessibilityIdentifier = "settingBtn" and isAccessibilityElement to "YES".


like this:


@implementation TableHeaderView

- (void)awakeFromNib {
  [super awakeFromNib];

  [self initAccessibility];
}

#pragma mark - Init

- (void)initAccessibility {
  self.isAccessibilityElement = NO;

  self.SettingBbutton.isAccessibilityElement = YES;
  self.SettingBbutton.accessibilityIdentifier = @"settingBtn";
}
@end


When I using voice over, I can find the "settingBtn" well, and using simulator's accessibility inspector also can select the "settingBtn".


But I using XCUIElemenrtQuery to find the button, like:


let app = XCUIApplication()
let tablesQuery = app.tables
tablesQuery.buttons["settingBtn"].tap();


It can't be found in table, I'm very counfuse about this question,

why the voice over and accessibility inspector can found the button, but element query can't?

I hope I can acquire some greate tips to fix this issue, thanks!

Replies

Not much help and a bit irrelevant, but the only thing I can say is that at least our testers can identify the element based on the accessibilityIdentifier, even when isAccessibilityElement is set to false.

I did a qucik test and that seems to work, which Xcode / iOS simulator combo are you using?


Also what may help you debug this further is printing out the accessibility tree as seen by the UI tests using


let app = XCUIApplication()
print(app.debugDescription)


Inspect the output and see identifier and label the settings button has


e.g. from my test:

          Other, 0x6040001945d0, traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
            Table, 0x604000193a70, traits: 35192962023424, {{0.0, 0.0}, {414.0, 736.0}}
              Button, 0x604000193e80, traits: 8589934593, {{0.0, 64.0}, {126.0, 34.0}}, identifier: 'settingsBtn', label: 'Settings Button'



Hope this helps

Is there a tableview on top of another tableView? if you could print the tree that would help. If there are 2 tableviews then that tableQuery probably refers to the first one it finds so you need to specify wich tableView you are refering to by its index...not sure if this is your case though...


Set a breakpoint before the failure and print the tree on the console to see what XCode sees with:


expr print(XCUIApplication().debugDescription)