Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running test crashes app in simulator #709

Closed
alj1s opened this issue May 2, 2018 · 10 comments
Closed

Running test crashes app in simulator #709

alj1s opened this issue May 2, 2018 · 10 comments

Comments

@alj1s
Copy link
Contributor

alj1s commented May 2, 2018

I've been struggling to test a particular screen in my application and it's currently causing the test to crash the app in the simulator which results in the test suite hanging.

Here is the test that fails

const { joyride } = require("./utils")

describe("joyride", () => {
  beforeEach(async () => {
    await device.reloadReactNative()
    await joyride()
  })

  it("completing the joyride should take you to the main screen", async () => {
    await element(by.text("GO TO STEP 1")).tap()
    await element(by.id("Step 1-nextStep")).tap()
    await element(by.id("Step 2-nextStep")).tap()
    await element(by.id("Step 3-nextStep")).tap()
    await element(by.id("Step 4-nextStep")).tap()

    await device.disableSynchronization()

    await waitFor(element(by.id("ClientSummary")))
      .toBeVisible()
      .withTimeout(2000)
    await expect(element(by.id("ClientSummary"))).toBeVisible()

    await device.enableSynchronization()
  })
})

The Element with the testID "ClientSummary" is a scrollview that renders underneath a modal view that displays when the screen loads initially.

If I don't disable synchronization the test times out though I can verify the element with the "ClientSummary" testID is present in the screen debugger in XCode.

Also, if instead of waiting for "ClientSummary" to be visible, I wait for "Step 4-nextStep" toBeNotVisible it will not crash but will time out.

Here is the log file:

2018-05-02 13:55:39.131 xenon[38140:7938083] Uncaught exception: we should only have exactly one subview; Stack trace:
0   CoreFoundation                      0x000000010ce281e6 __exceptionPreprocess + 294
1   libobjc.A.dylib                     0x000000010b6e5031 objc_exception_throw + 48
2   CoreFoundation                      0x000000010ce2d472 +[NSException raise:format:arguments:] + 98
3   Foundation                          0x000000010b1be64f -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 165
4   xenon                               0x000000010a80da33 -[RCTScrollView layoutSubviews] + 387
5   UIKit                               0x000000010fd26808 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
6   QuartzCore                          0x000000010f81d61a -[CALayer layoutSublayers] + 177
7   QuartzCore                          0x000000010f82182b _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
8   QuartzCore                          0x000000010f7a829f _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343
9   QuartzCore                          0x000000010f7d5940 _ZN2CA11Transaction6commitEv + 568
10  EarlGrey                            0x0000000120cb2ee8 __61+[GREYVisibilityChecker grey_imageAfterAddingSubview:toView:]_block_invoke + 168
11  EarlGrey                            0x0000000120cb31f4 +[GREYVisibilityChecker grey_prepareView:forVisibilityCheckAndPerformBlock:] + 436
12  EarlGrey                            0x0000000120cb2d36 +[GREYVisibilityChecker grey_imageAfterAddingSubview:toView:] + 774
13  EarlGrey                            0x0000000120cb267c +[GREYVisibilityChecker grey_captureBeforeImage:andAfterImage:andGetIntersectionOrigin:forView:withinRect:] + 3900
14  EarlGrey                            0x0000000120cb1225 +[GREYVisibilityChecker grey_percentViewVisibleOnScreen:withinRect:] + 165
15  EarlGrey                            0x0000000120cb0caf +[GREYVisibilityChecker grey_percentElementVisibleOnScreen:] + 239
16  EarlGrey                            0x0000000120cae475 +[GREYVisibilityChecker percentVisibleAreaOfElement:] + 213
17  EarlGrey                            0x0000000120cd1887 __45+[GREYMatchers matcherForSufficientlyVisible]_block_invoke + 71
18  EarlGrey                            0x0000000120c841b8 -[GREYElementMatcherBlock matches:] + 72
19  EarlGrey                            0x0000000120ca9a55 -[GREYBaseMatcher matches:describingMismatchTo:] + 85
20  EarlGrey                            0x0000000120c6e497 -[GREYAllOf matches:describingMismatchTo:] + 471
21  EarlGrey                            0x0000000120c6e497 -[GREYAllOf matches:describingMismatchTo:] + 471
22  EarlGrey                            0x0000000120ca8059 -[GREYAnyOf matches:describingMismatchTo:] + 297
23  EarlGrey                            0x0000000120ca7ec7 -[GREYAnyOf matches:] + 167
24  EarlGrey                            0x0000000120c7dae6 -[GREYElementFinder elementsMatchedInProvider:] + 1254
25  EarlGrey                            0x0000000120cc1549 -[GREYElementInteraction matchedElementsWithTimeout:error:] + 1641
26  EarlGrey                            0x0000000120cc5ed4 __39-[GREYElementInteraction assert:error:]_block_invoke + 372
27  EarlGrey                            0x0000000120cf4a74 __59-[GREYUIThreadExecutor executeSyncWithTimeout:block:error:]_block_invoke + 68
28  EarlGrey                            0x0000000120ca6c2c __54-[GREYRunLoopSpinner grey_checkConditionInActiveMode:]_block_invoke + 412
29  CoreFoundation                      0x000000010cdcab0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
30  CoreFoundation                      0x000000010cdaf2db __CFRunLoopDoBlocks + 331
31  CoreFoundation                      0x000000010cdaea5e __CFRunLoopRun + 1246
32  CoreFoundation                      0x000000010cdae30b CFRunLoopRunSpecific + 635
33  EarlGrey                            0x0000000120ca695c -[GREYRunLoopSpinner grey_checkConditionInActiveMode:] + 364
34  EarlGrey                            0x0000000120ca5616 -[GREYRunLoopSpinner spinWithStopConditionBlock:] + 422
35  EarlGrey                            0x0000000120cf495f -[GREYUIThreadExecutor executeSyncWithTimeout:block:error:] + 3327
36  EarlGrey                            0x0000000120cc5292 -[GREYElementInteraction assert:error:] + 2114
37  EarlGrey                            0x0000000120cc6bed -[GREYElementInteraction assertWithMatcher:error:] + 125
38  Detox                               0x000000010afb5490 __56+[GREYCondition(Detox) detoxConditionForElementMatched:]_block_invoke + 63
39  EarlGrey                            0x0000000120cc0038 __46-[GREYCondition waitWithTimeout:pollInterval:]_block_invoke + 40
40  EarlGrey                            0x0000000120ca61f2 __77-[GREYRunLoopSpinner grey_drainRunLoopInActiveModeAndCheckCondition:forTime:]_block_invoke + 322
41  EarlGrey                            0x0000000120ca7144 __89-[GREYRunLoopSpinner grey_setupObserverInMode:withBeforeSourcesBlock:beforeWaitingBlock:]_block_invoke + 180
42  CoreFoundation                      0x000000010cdca607 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
43  CoreFoundation                      0x000000010cdca55e __CFRunLoopDoObservers + 430
44  CoreFoundation                      0x000000010cdaea53 __CFRunLoopRun + 1235
45  CoreFoundation                      0x000000010cdae30b CFRunLoopRunSpecific + 635
46  EarlGrey                            0x0000000120ca5d53 -[GREYRunLoopSpinner grey_drainRunLoopInActiveModeAndCheckCondition:forTime:] + 627
47  EarlGrey                            0x0000000120ca56b8 -[GREYRunLoopSpinner spinWithStopConditionBlock:] + 584
48  EarlGrey                            0x0000000120cbfde7 -[GREYCondition waitWithTimeout:pollInterval:] + 967
49  EarlGrey                            0x0000000120cbfa08 -[GREYCondition waitWithTimeout:] + 56
50  CoreFoundation                      0x000000010cdabccc __invoking___ + 140
51  CoreFoundation                      0x000000010cdabb84 -[NSInvocation invoke] + 308
52  Detox                               0x000000010afb81bb +[DTXMethodInvocation invoke:onError:] + 813
53  Detox                               0x000000010afb4538 __35-[TestRunner invoke:withMessageId:]_block_invoke + 127
54  CoreFoundation                      0x000000010cdcab0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
55  CoreFoundation                      0x000000010cdaf2db __CFRunLoopDoBlocks + 331
56  CoreFoundation                      0x000000010cdaf06b __CFRunLoopRun + 2795
57  CoreFoundation                      0x000000010cdae30b CFRunLoopRunSpecific + 635
58  GraphicsServices                    0x0000000115adda73 GSEventRunModal + 62
59  UIKit                               0x000000010fc570b7 UIApplicationMain + 159
60  Detox                               0x000000010afb3b97 __WX_UIApplicationMain + 197
61  xenon                               0x000000010a71afaf main + 111
62  libdyld.dylib                       0x0000000111fe3955 start + 1

Here is the last part of the verbose Detox logs:

 send: {"type":"invoke","params":{"target":{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYConfiguration"},"method":"sharedInstance","args":[]}},"method":"disableSynchronization","args":[]},"messageId":10}
 onMessage: {"type":"invokeResult","messageId":10,"params":{"result":"(null)"}}
  rbx
 send: {"type":"invoke","params":{"target":{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYCondition"},"method":"detoxConditionForElementMatched:","args":[{"type":"Invocation","value":{"target":{"type":"EarlGrey","value":"instance"},"method":"detox_selectElementWithMatcher:","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYMatchers"},"method":"detoxMatcherForBoth:and:","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYMatchers"},"method":"matcherForAccessibilityID:","args":[{"type":"NSString","value":"ClientSummary"}]}},{"type":"Invocation","value":{"target":{"type":"Class","value":"GREYMatchers"},"method":"matcherForSufficientlyVisible","args":[]}}]}}]}}]}},"method":"waitWithTimeout:","args":[{"type":"CGFloat","value":2}]},"messageId":11}
 onMessage: {"type":"AppWillTerminateWithError","messageId":-10000,"params":{"threadNumber":1,"errorDetails":"we should only have exactly one subview\n(\n\t0   CoreFoundation                      0x000000010799d1e6 __exceptionPreprocess + 294\n\t1   libobjc.A.dylib                     0x000000010625a031 objc_exception_throw + 48\n\t2   CoreFoundation                      0x00000001079a2472 +[NSException raise:format:arguments:] + 98\n\t3   Foundation                          0x0000000105d3364f -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 165\n\t4   xenon                               0x0000000105382a33 -[RCTScrollView layoutSubviews] + 387\n\t5   UIKit                               0x000000010a97b808 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515\n\t6   QuartzCore                          0x000000010a64c61a -[CALayer layoutSublayers] + 177\n\t7   QuartzCore                          0x000000010a65082b _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395\n\t8   QuartzCore                          0x000000010a5d729f _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 343\n\t9   QuartzCore                          0x000000010a604940 _ZN2CA11Transaction6commitEv + 568\n\t10  EarlGrey                            0x000000011b828ee8 __61+[GREYVisibilityChecker grey_imageAfterAddingSubview:toView:]_block_invoke + 168\n\t11  EarlGrey                            0x000000011b8291f4 +[GREYVisibilityChecker grey_prepareView:forVisibilityCheckAndPerformBlock:] + 436\n\t12  EarlGrey                            0x000000011b828d36 +[GREYVisibilityChecker grey_imageAfterAddingSubview:toView:] + 774\n\t13  EarlGrey                            0x000000011b82867c +[GREYVisibilityChecker grey_captureBeforeImage:andAfterImage:andGetIntersectionOrigin:forView:withinRect:] + 3900\n\t14  EarlGrey                            0x000000011b827225 +[GREYVisibilityChecker grey_percentViewVisibleOnScreen:withinRect:] + 165\n\t15  EarlGrey                            0x000000011b826caf +[GREYVisibilityChecker grey_percentElementVisibleOnScreen:] + 239\n\t16  EarlGrey                            0x000000011b824475 +[GREYVisibilityChecker percentVisibleAreaOfElement:] + 213\n\t17  EarlGrey                            0x000000011b847887 __45+[GREYMatchers matcherForSufficientlyVisible]_block_invoke + 71\n\t18  EarlGrey                            0x000000011b7fa1b8 -[GREYElementMatcherBlock matches:] + 72\n\t19  EarlGrey                            0x000000011b81fa55 -[GREYBaseMatcher matches:describingMismatchTo:] + 85\n\t20  EarlGrey                            0x000000011b7e4497 -[GREYAllOf matches:describingMismatchTo:] + 471\n\t21  EarlGrey                            0x000000011b7e4497 -[GREYAllOf matches:describingMismatchTo:] + 471\n\t22  EarlGrey                            0x000000011b81e059 -[GREYAnyOf matches:describingMismatchTo:] + 297\n\t23  EarlGrey                            0x000000011b81dec7 -[GREYAnyOf matches:] + 167\n\t24  EarlGrey                            0x000000011b7f3ae6 -[GREYElementFinder elementsMatchedInProvider:] + 1254\n\t25  EarlGrey                            0x000000011b837549 -[GREYElementInteraction matchedElementsWithTimeout:error:] + 1641\n\t26  EarlGrey                            0x000000011b83bed4 __39-[GREYElementInteraction assert:error:]_block_invoke + 372\n\t27  EarlGrey                            0x000000011b86aa74 __59-[GREYUIThreadExecutor executeSyncWithTimeout:block:error:]_block_invoke + 68\n\t28  EarlGrey                            0x000000011b81cc2c __54-[GREYRunLoopSpinner grey_checkConditionInActiveMode:]_block_invoke + 412\n\t29  CoreFoundation                      0x000000010793fb0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12\n\t30  CoreFoundation                      0x00000001079242db __CFRunLoopDoBlocks + 331\n\t31  CoreFoundation                      0x0000000107923a5e __CFRunLoopRun + 1246\n\t32  CoreFoundation                      0x000000010792330b CFRunLoopRunSpecific + 635\n\t33  EarlGrey                            0x000000011b81c95c -[GREYRunLoopSpinner grey_checkConditionInActiveMode:] + 364\n\t34  EarlGrey                            0x000000011b81b616 -[GREYRunLoopSpinner spinWithStopConditionBlock:] + 422\n\t35  EarlGrey                            0x000000011b86a95f -[GREYUIThreadExecutor executeSyncWithTimeout:block:error:] + 3327\n\t36  EarlGrey                            0x000000011b83b292 -[GREYElementInteraction assert:error:] + 2114\n\t37  EarlGrey                            0x000000011b83cbed -[GREYElementInteraction assertWithMatcher:error:] + 125\n\t38  Detox                               0x0000000105b2a490 __56+[GREYCondition(Detox) detoxConditionForElementMatched:]_block_invoke + 63\n\t39  EarlGrey                            0x000000011b836038 __46-[GREYCondition waitWithTimeout:pollInterval:]_block_invoke + 40\n\t40  EarlGrey                            0x000000011b81c5bf __77-[GREYRunLoopSpinner grey_drainRunLoopInActiveModeAndCheckCondition:forTime:]_block_invoke.37 + 431\n\t41  EarlGrey                            0x000000011b81d184 __89-[GREYRunLoopSpinner grey_setupObserverInMode:withBeforeSourcesBlock:beforeWaitingBlock:]_block_invoke + 244\n\t42  CoreFoundation                      0x000000010793f607 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23\n\t43  CoreFoundation                      0x000000010793f55e __CFRunLoopDoObservers + 430\n\t44  CoreFoundation                      0x0000000107923b81 __CFRunLoopRun + 1537\n\t45  CoreFoundation                      0x000000010792330b CFRunLoopRunSpecific + 635\n\t46  EarlGrey                            0x000000011b81bd53 -[GREYRunLoopSpinner grey_drainRunLoopInActiveModeAndCheckCondition:forTime:] + 627\n\t47  EarlGrey                            0x000000011b81b6b8 -[GREYRunLoopSpinner spinWithStopConditionBlock:] + 584\n\t48  EarlGrey                            0x000000011b835de7 -[GREYCondition waitWithTimeout:pollInterval:] + 967\n\t49  EarlGrey                            0x000000011b835a08 -[GREYCondition waitWithTimeout:] + 56\n\t50  CoreFoundation                      0x0000000107920ccc __invoking___ + 140\n\t51  CoreFoundation                      0x0000000107920b84 -[NSInvocation invoke] + 308\n\t52  Detox                               0x0000000105b2d1bb +[DTXMethodInvocation invoke:onError:] + 813\n\t53  Detox                               0x0000000105b29538 __35-[TestRunner invoke:withMessageId:]_block_invoke + 127\n\t54  CoreFoundation                      0x000000010793fb0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12\n\t55  CoreFoundation                      0x00000001079242db __CFRunLoopDoBlocks + 331\n\t56  CoreFoundation                      0x000000010792406b __CFRunLoopRun + 2795\n\t57  CoreFoundation                      0x000000010792330b CFRunLoopRunSpecific + 635\n\t58  GraphicsServices                    0x00000001106f1a73 GSEventRunModal + 62\n\t59  UIKit                               0x000000010a8ac0b7 UIApplicationMain + 159\n\t60  Detox                               0x0000000105b28b97 __WX_UIApplicationMain + 197\n\t61  xenon                               0x000000010528ffaf main + 111\n\t62  libdyld.dylib                       0x000000010cbf7955 start + 1\n)","queueName":"com.apple.main-thread"}}
  rbx
 send: {"type":"reactNativeReload","params":{},"messageId":-1000}

  • Detox: 7.3.4
  • React Native: 0.54.2
  • Node: 9.10.0
  • Device: iOS iPhone 7 11.3 simulator
  • Xcode: 9.3
  • macOS: 10.13.4
@swcisel
Copy link

swcisel commented May 2, 2018

I encountered a similar issue (reloadReactNative followed by tap() would cause tests to time out), and this fixed it for me.

@LeoNatan
Copy link
Contributor

LeoNatan commented May 3, 2018

This doesn’t seem like a Detox issue.

@support
Copy link

support bot commented May 3, 2018

We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the detox tag.

@support support bot closed this as completed May 3, 2018
@alj1s
Copy link
Contributor Author

alj1s commented May 3, 2018

@LeoNatan could you clarify please?

Running the detox tests with an expectation of a visible element causes the app to crash with the exception shown in the issue. This is not a crash that occurs when running the application or when expecting on a different element.

So to me it doesn't seem like it's an issue with the app itself. So it points to either detox or Earl Grey?

@LeoNatan
Copy link
Contributor

LeoNatan commented May 3, 2018

The crash comes from React Native.

we should only have exactly one subview

This comes from https://github.com/facebook/react-native/blob/be379efc9b677eac039a3d241d03aa4bb10d6a64/React/Views/ScrollView/RCTScrollView.m#L515

So it looks to me like incorrect view management on the app part or RN. As far as I know, Earl Grey does not add subviews. If I’m mistaken, we can always reopen the issues.

@alj1s
Copy link
Contributor Author

alj1s commented May 3, 2018

@swcisel - thank you for the suggestion but there is nothing set for the main interface in xcode.

@LeoNatan - thank you for your help.

@LeoNatan
Copy link
Contributor

LeoNatan commented May 3, 2018

Could I ask you to make the simplest project where this reproduces?

@alj1s
Copy link
Contributor Author

alj1s commented May 3, 2018

@LeoNatan done - https://github.com/ximenean/exactlyOneSubviewCrash

If I swap out the ScrollView with a plain View in the Main component or if I remove the waitFor it does not crash.

I don't expect you to look at it any further but this is hopefully useful for you to be aware of.

@LeoNatan
Copy link
Contributor

LeoNatan commented May 3, 2018

The will look at it to see what’s going on.

@jonleighton
Copy link

I'm having the same issue.

This ticket provides a clue:

The crash is triggered when a toBeVisible() is called on RCTScrollView (React ScrollView or ListView).
In order for Earl Grey to test that the view is visible it makes some magic inside the view hierarchy, adding a subview to the view it asserts on, causing react-native to crash with RCTAssert “we should only have exactly one subview”.

I think the magic happens here: https://github.com/google/EarlGrey/blob/24044cf14426e6536ceeec36a6e76076881b4250/EarlGrey/Common/GREYVisibilityChecker.m#L623-L627

@wix wix locked and limited conversation to collaborators Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants