0

I have a hybrid iOS application. One of the view's is a WkWebView which loads a html file.

To test this app, I have used Google's EarlGrey framework. It works great with iOS's native UI elements. However, I am unable to test the UI elements in the html. Here is the line that fails while running the XCTest:

EarlGrey.select(elementWithMatcher: grey_accessibilityID("page_view")).perform(grey_javaScriptExecution("document.getElementById('myLegend').click()", nil))

The failure message is:

Exception Name: ConstraintFailedException
Exception Reason: Cannot perform action due to constraint(s) failure.
Exception with Action: {
  "Action Name" : "Execute JavaScript",
  "Element Description" : "<WKWebView:0x7ff6ca0b2a00; AX=N; AX.id='page_view'; AX.frame={{0, 0}, {414, 736}}; AX.activationPoint={207, 368}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 736}}; opaque; alpha=1>",
  "Failed Constraint(s)" : "kindOfClass('UIWebView')",
  "All Constraint(s)" : "(!(isSystemAlertViewShown) && kindOfClass('UIWebView'))",
  "Recovery Suggestion" : "Adjust element properties so that it matches the failed constraint(s)."
}

I have checked the UI hierarchy stack that EarlGrey prints in the console, I cannot spot the UI elements in the html.

Any suggestions on how EarlGrey can be used to test html loaded in WKWebView?

Thanks, Reshma

rlr
  • 320
  • 2
  • 11
  • EarlGrey 1.0 doesn't support WKWebViews as of now since it runs in the same process as the application under test. As a result, you're not able to see the UIElements in the WKWebView. The plan is to have this supported in future versions. You might want to ping their slack group to get more information. https://googleoss.slack.com/messages/earlgrey – gran_profaci Apr 03 '18 at 17:50
  • Thank you for the information. EarlGrey version I have used is 1.12.1. Also, under features(https://github.com/google/EarlGrey/blob/master/docs/features.md) they mention support for Web views. Does that mean UIWebView alone, and not WkWebView? – rlr Apr 05 '18 at 04:53
  • That's correct. – gran_profaci Apr 09 '18 at 21:38

0 Answers0