kumar
kumar

Reputation: 65

XCUI Test: How to fetch List of elements from the iOS screen

I have recently started automating iOS apps on iPhone real devices with the XCUI test setup.

I got a scenario where my app contains 5 screens in the home page, each screen contains a unique card number and its balance so i have to fetch the card number from the screen and verify it with my input(expected) card number, if both are same then i have to click on the card screen otherwise if both are not same then i have to swipe right to the second screen and do the same process.

I was able to automate this scenrio in android perfectly because in android each screen is clearly differentiated with a unique card number but when i inspect the card number screen on iOS app it was showing all the list of cards attached to the app. in this case its getting difficult for me to get the card number from the app and verify it with my input card number . please see the below code which am already using it for android

String oysterCardVisibleNumberOnApp= data.get("PrestigeCardNumber");


while(!action.getText(HomePage.oysterCardNumber,"oysterCardNumber").equalsIgnorecase(oysterCardVisibleNumberOnApp))){
      action.swipeRightToLeft();
     }

it would be great if any one has any idea how to retrieve the list of elements/cards from the iOS app please let me know. or if you know any new methods in XCUI setup will help me to achieve this then please let me know. your help will be much appreciated :)

Please see the below Android Screen & iOS Screen pictures for getting more clarity

Android Screen

iOS Screen

Thank you

Upvotes: 3

Views: 5317

Answers (3)

CodeBreaker
CodeBreaker

Reputation: 351

You can use XCUIApplication().debugDescription to get a print out of the UI tree that XCUITest sees. You can also update the application code to set custom identifiers for your UI elements (these are only seen by XCUITest). for example card-1, etc.

Upvotes: 0

Zachary Borrelli
Zachary Borrelli

Reputation: 61

If you stop at a breakpoint for instance and you use:

po XCUIApplication().descendants(matching: .any)

in the debug console, you will get a list of all descendant elements from the main Application element. It will also give you a loose view of the structure.

You can then change .any to more specific element types e.g. .textField or .buttons.

Upvotes: 6

ShaneG
ShaneG

Reputation: 1518

You might be able to use the Accessibility Inspector in xcode for this:

https://developer.apple.com/library/content/documentation/Accessibility/Conceptual/AccessibilityMacOSX/OSXAXTestingApps.html

Based on areas you select in your app, it gives back detailed descriptions on each one. But what it brings back depends on the structure of your application. I was trying to do something similar in my own ios application and this helped me a bit.

Upvotes: 0

Related Questions