0

When I execute the command

(lldb) po app.debugDescription

it displays the details from the last view. How do I refresh it to show the new element tree??

anotherCoder
  • 712
  • 3
  • 11
  • 25

1 Answers1

2

The view hierarchy will refresh when you interact with the app (since it's reasonable to expect that the app's state doesn't change unless the user interacts with it).

To get a fresh view hierarchy, you can either tap on the app: app.tap() and then print the debug description, or you could create a new instance of XCUIApplication and use that instead of the existing app property which has the cached view hierarchy. The new instance should show a fresh view hierarchy.

Oletha
  • 7,324
  • 1
  • 26
  • 46
  • 1
    Yep, give it a try :) – Oletha Jul 27 '17 at 07:51
  • I tried, and it works. But if there is an alertwindow and we press tap, it gets cancelled. I want to see the details of the alert view, but the details of the old screen are shown. Any ideas?? – anotherCoder Jul 27 '17 at 15:16
  • You can print out a property of an XCUIElementQuery like count to force a fresh snapshot of the view hierarchy. For example just print `app.alerts.count` – atgrubb Jul 27 '17 at 16:39
  • @Vinayaka to interact with an alert, use an interruption monitor as explained here: https://stackoverflow.com/questions/39973904/handler-of-adduiinterruptionmonitor-is-not-called-for-alert-related-to-photos/39976352#39976352 – Oletha Jul 27 '17 at 17:13
  • 2
    @Vinayaka alerts get automatically cancelled by XCTest if you don't handle them yourself, that's why you're seeing it get cancelled. :) – Oletha Jul 27 '17 at 17:13