3

I want to write an UI automation test that log in by using Google. The webview is embedded in the app. In Earlgrey, how can I select a text field or a button of a web view. Thanks

sahara108
  • 2,829
  • 1
  • 22
  • 41
  • If your webview is embedded in the app then each element that you need to select should have an accessibility wrapper around it. You should be able to interact with elements using that and run regular EarlGrey statements. Is there a specific hierarchy or case that you would like to handle? – gran_profaci May 12 '16 at 05:21
  • No specific hierarchy at all. For instance, I just want to touch down `Allow` button. Tried to use matcher `grey_buttonTitle(@"Allow")` but it can't find the button. I doubt that EarlGrey can select an element inside an UIWebview – sahara108 May 12 '16 at 06:59
  • Note that `grey_buttonTitle` only selects UIButton classes, `grey_text(@"Allow")` is a better alternative here. – Gautam May 12 '16 at 21:13
  • Thanks for the tip. I tried `grey_text` but it still can't find the element. – sahara108 May 13 '16 at 02:39
  • does grey_accessibilityLabel(@"Allow") or grey_accessibilityID(@"Allow) work? And on a separate note, is it a WKWebView or a UIWebView? – khandpur May 13 '16 at 16:23
  • @sahara108, any update on this issue? – gran_profaci Aug 01 '16 at 08:49
  • I still haven't found any solution. Do you have answer? – sahara108 Aug 01 '16 at 08:51

1 Answers1

1

EarlGrey provides a great log of the UI hierarchy when a test fails. My suggestion is to write a test that navigates to the login view, and then force EarlGrey to fail. Then in the log, look for the elements you need. You should see something like:

--<WebAccessibilityObjectWrapper:0x7fbca2422fb0; AX=Y; AX.value='Email'; AX.frame={{72, 145}, {270, 38}}; AX.activationPoint={207, 164}; AX.traits='UIAccessibilityTraitNone'; AX.focused='Y'>
--<WebAccessibilityObjectWrapper:0x7fbca4e82360; AX=Y; AX.value='Password'; AX.frame={{72, 201}, {270, 38}}; AX.activationPoint={207, 220}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'>

From this log you can see that the two elements are accessible via:

EarlGrey().selectElementWithMatcher(grey_accessibilityValue("Email"))
EarlGrey().selectElementWithMatcher(grey_accessibilityValue("Password"))
Wilson
  • 251
  • 3
  • 9
  • 1
    Or you can even put a break point and punch this into gdb: `po [GREYElementHierarchy hierarchyStringForElement:[UIApplication sharedApplication].keyWindow]` – Gautam Oct 24 '16 at 22:37