0

Code

    let label_interactable_matcher = grey_allOf([grey_accessibilityLabel("お知らせ"), GREYMatchers.matcherForInteractable()])
    let action = GREYActions.actionForTap()
    EarlGrey.selectElement(with: label_interactable_matcher).atIndex(0).perform(action)

Exception

Exception Name: NoMatchingElementException Exception Reason: Cannot find UI element. Exception with Action: { "Action Name": "Tap", "Element Matcher": "(((respondsToSelector(isAccessibilityElement) && isAccessibilityElement) && accessibilityLabel('お知らせ')) && interactable)", "Recovery Suggestion": "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element." }

Exception Details: Error Trace: [ { "Description": "Interaction cannot continue because the desired element was not found.", "Error Domain": "com.google.earlgrey.ElementInteractionErrorDomain", "Error Code": "0", "File Name": "GREYElementInteraction.m", "Function Name": "-[GREYElementInteraction matchedElementsWithTimeout:error:]", "Line": "124", "TestCase Class": "MyAppTests.Myunittest", "TestCase Method": "testExample" } ]

View Hierarchy

ECKit_iOS.IconButton:0x7f86af9aea00; AX=Y; AX.label='お知らせ'; AX.frame={{351, 81}, {55, 50}}; AX.activationPoint={378.5, 106}; AX.traits='UIAccessibilityTraitButton'; AX.focused='N'; frame={{0, 0}, {55, 50}}; alpha=1> -UIButtonLabel:0x7f86aed75130; AX=Y; AX.label='お知らせ'; AX.frame={{362, 115}, {33, 10}}; AX.activationPoint={378.5, 120}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{11, 34}, {33, 10}}; alpha=1; UIE=N; text='お知らせ'>

Screenshot At Failure

enter image description here

Concerns

  1. There is a contradiction between view hierarchy & exception being printed
  2. If the exception is "NoMatchingElementException" why would Recovery Suggestion says "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element"
  3. In my existing app after the installation if I add a new XCTestCase in UNIT TESTING TARGET, app show in black background(I was expecting it in white).
  4. For the splash screen suggestion in FAQ, the swift implementation solution seems difficult to implement(app module should be imported in testing module & rootViewController class
  5. Running the app by play button in unit testing target vs directly launching the app. Unexpected black background appears instead of white one. enter image description here
  6. We can't use autogenerated code from UI Testing Target in Unit Test Target & Management of UI tests become difficult if we opt for both Xcode's UI Testing & EarlGrey
  7. Screenshot At Failure(Black screen) is contradicting with View Hierarchy
Anand
  • 216
  • 3
  • 10

1 Answers1

0
  • There is a contradiction between view hierarchy & exception being printed.

Can you explain this a bit further as to what the contradiction is?

  • If the exception is "NoMatchingElementException" why would Recovery Suggestion says "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element"

Often times, elements can be in the hierarchy but cannot be interactable. For eg. an element that is partially hidden or is not accessible.

  • In my existing app after the installation if I add a new XCTestCase in UNIT TESTING TARGET, app show in black background(I was expecting it in white).

You might want to check just what the test host is in xcode for the test target.

  • For the splash screen suggestion in FAQ, the swift implementation solution seems difficult to implement(app module should be imported in testing module & rootViewController class

For EG 1, this should work fine since both the app and the test are in the same process.

  • Our existing app is shown in black background after I add & run a new test case in Unit Testing Target.

Does it work fine for a UI Test? Is the test host set correctly?

  • We can't use autogenerated code from UI Testing Target in Unit Test Target & Management of UI tests become difficult if we opt for both Xcode's UI Testing & EarlGrey

EG 1 is XCTest Unit Test based tool and cannot use UI Test stuff. EG 2, which we are working on getting released soon allows you to use XCUITest commands.

  • Screenshot At Failure(Black screen) is contradicting with View Hierarchy.

I'm not sure about this and it seems like an app side issue. You should ping us on slack and speak about this in more detail there.

gran_profaci
  • 8,087
  • 15
  • 66
  • 99
  • 1) Exception is "NoMatchingElementException" & View hierarchy shows the element is present for the same label 2) Are you saying "let matcher = grey_allOf([grey_accessibilityLabel("お知らせ"), GREYMatchers.matcherForInteractable(), grey_sufficientlyVisible()])" would resolve the issue? 3) I verified "Unit testing target -> Build Settings" has EarlGrey copy files(EarlGrey.framework). What do you mean by checking test host? 4) I can't check in Unit testing target like if vc is App.ViewController { //I need to make ViewController as public } if vc is ViewController {//ViewController undefined } – Anand Jul 06 '18 at 11:32
  • 5) Please share screenshot showing how correctly set test host should look like 6) Are you saying with EG 1(I am not sure what EG 1 or EG 2 are. Please share what version you are referring to), apps would end up mixing both Unit tests(if app has any) & UI test in one target. With EG 2 you can run Unit tests & UI tests separately as they belong to different targets. By the way is EG 2 stable? and what is its version number? For EG 2 implementation are you spinning a server locally to intercept network request from app(since XCUITests run from different process right) – Anand Jul 06 '18 at 11:47
  • 7) It shouldn't be an app side issue because EG has recorded blank screen at failure & at the same time it has got view hierarchy being printed. If screen is blank how would it print view hierarchy? – Anand Jul 06 '18 at 11:47
  • 2) "let matcher = grey_allOf([grey_accessibilityLabel("お知らせ"), GREYMatchers.matcherForInteractable(), grey_sufficientlyVisible()])" didn't resolve the issue. – Anand Jul 10 '18 at 06:16