1

I have to click on "Yes" on the alert view which is easy when the language is english.

XCUIElement *confirmationAlert = app.alerts[@"Confirmation"];
[confirmationAlert.buttons[@"Yes"] tap];

But I want the code to be robust enough to handle different languages. This step will fail when the language changes to Russian. as the test that I am now looking for is: 'Да'

Is there a better way to handle Alert window. Probably by index or something like that. I would have assigned accessibility identifier, but that can be done for the Alert, but no the buttons inside them.

Here is the Alert definition

self.currentAlertView = [[UIAlertView alloc]initWithTitle:[SystemHelper localize:@"alert_confirmation"]
                                                        message:sAlert
                                                       delegate:self
                                              cancelButtonTitle:[SystemHelper localize:@"button_no"]
                                              otherButtonTitles:[SystemHelper localize:@"button_yes"], nil];
  self.currentAlertView.accessibilityIdentifier = @"alert_remove_account_confirm";

Here the app debug element tree at the time of the alert.

Alert 0x600000369480: traits: 72057602627862528, {{52.5, 263.5}, {270.0, 140.5}}, label: 'Подтвердите действие'
      Other 0x600000369840: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
        Other 0x6000003696c0: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
          Other 0x600000369b40: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
            Other 0x600000369a80: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
            Other 0x600000369c00: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
              Other 0x600000369cc0: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
              Other 0x600000369fc0: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
          Other 0x600000369f00: traits: 8589934592, {{52.5, 263.5}, {270.0, 140.5}}
            Other 0x60000036a200: traits: 8589934592, {{52.5, 263.5}, {270.0, 96.0}}
              Other 0x60000036a140: traits: 8589934592, {{52.5, 263.5}, {270.0, 96.0}}
                StaticText 0x60000036a2c0: traits: 8589934656, {{68.5, 283.5}, {238.0, 20.5}}, label: 'Подтвердите действие'
                StaticText 0x60000036a500: traits: 8589934656, {{68.5, 307.0}, {238.0, 32.0}}, label: 'Удалить ‘popopopo’ из списка учетных записей?'
            Other 0x60000036a440: traits: 8589934592, {{52.5, 359.5}, {270.0, 0.5}}
              Other 0x60000036a5c0: traits: 8589934592, {{52.5, 359.5}, {270.0, 0.5}}
              Other 0x60000036a980: traits: 8589934592, {{52.5, 359.5}, {270.0, 0.5}}
            Other 0x60000036a800: traits: 8589934592, {{52.5, 360.0}, {270.0, 44.0}}
              Other 0x60000036aa40: traits: 8589934592, {{52.5, 360.0}, {270.0, 44.0}}
                Other 0x60000036ad40: traits: 8589934592, {{52.5, 360.0}, {270.0, 44.0}}
                  Other 0x60000036ac80: traits: 8589934592, {{52.5, 360.0}, {135.0, 44.0}}
                    Button 0x60000036ae00: traits: 8589934593, {{52.5, 360.0}, {135.0, 44.0}}, label: 'Нет'
                  Other 0x60000036b100: traits: 8589934592, {{187.5, 360.0}, {0.5, 44.0}}
                    Other 0x60000036b040: traits: 8589934592, {{187.5, 360.0}, {0.5, 44.0}}
                    Other 0x60000036b1c0: traits: 8589934592, {{187.5, 360.0}, {0.5, 44.0}}
                  Other 0x60000036b400: traits: 8589934592, {{188.0, 360.0}, {134.5, 44.0}}
                    Button 0x60000036b340: traits: 8589934593, {{188.0, 360.0}, {134.5, 44.0}}, label: 'Да'

I am stuck at this point, and I really can't proceed. All help is appreciated.

Do I resort to clicking on the coordinates?? How does the coordinates method scale to different devices??

anotherCoder
  • 712
  • 3
  • 11
  • 25
  • 1
    See https://stackoverflow.com/a/33426690/1634473 but basically you need app.alerts[NSLocalizedString(@"Confirmation"...)]; just like you do in the main app (I know this is old, just leaving this here for future readers) – yuf Feb 08 '18 at 04:48
  • 1
    You should use accessibility identifiers not the actual title – AMTourky May 08 '18 at 13:47
  • @AMTourky That is true, but unfortunately when you are treating the app as a black box you will have to use the title instead of identifiers if the identifiers aren't available. – anotherCoder May 09 '18 at 23:32
  • 1
    I don't advice treating the app as a blackbox when it's actually not! and go for the right thing chasing identifiers changes. But if it's no way, then I'll localize my test strings also, so in case of testing against Russian, then I'll use the Russian strings – AMTourky May 10 '18 at 10:16

0 Answers0