1

I am writing a test that fails with following error:

Error Domain=com.google.earlgrey.ElementInteractionErrorDomain Code=0 "No element found." UserInfo={NSLocalizedDescription=No element found.}

I can see in the generated screenshot that the element I am trying to match exists. I stepped through the code and saw that earlgrey uses element providers. When my test failed, I saw a ui hierarchy dump. I want to print the exact same ui hierarchy at specific breakpoints instead. How can I do that?

khandpur
  • 705
  • 3
  • 12

2 Answers2

2

You can use the GREYElementHierarchy class to print the element hierarchy at any point in your EarlGrey test.

UIWindow *hierarchy = [[[UIApplication sharedApplication] delegate] window]);

NSLog(@"Hierarchy: %@", hierarchy);

gran_profaci
  • 8,087
  • 15
  • 66
  • 99
1

As in EarlGrey FAQ you can add a breakpoint anywhere in your tests and, when hit, run in Xcode's debug window:

expression -- print(GREYElementHierarchy.hierarchyStringForAllUIWindows())

This will output the complete hierarchy so it will be a little confusing to parse out.

Good luck