google/EarlGrey

EarlGrey v2 whitebox testing fails to load bundle

Jamagas opened this issue · 14 comments

MacOS Catalina 10.15.6 (19G73)
Xcode 11.5; Xcode 12.2

EarlGrey v2 blackbox testing works fine.

EarlGrey v2 whitebox testing with bundle do not work, because bundle fails to load and gives this runtime error while running UI tests. I tried Xcode 11.5. and Xcode 12.2, and different simulators, still same.

Exact crash:
libc++abi.dylib: terminating with uncaught exception of type NSException *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An error: Error Domain=NSCocoaErrorDomain Code=4 "The bundle “EG2Bundle” couldn’t be loaded because its executable couldn’t be located." UserInfo={NSLocalizedFailureReason=The bundle’s executable couldn’t be located., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSBundlePath=/Users/bb8894/Library/Developer/CoreSimulator/Devices/C2D384BF-3CA2-4DD2-8303-5D7F712A3509/data/Containers/Bundle/Application/05E96F60-5109-45AC-B075-B9C39C76E16B/EarlGrey2Example.app/EarlGreyHelperBundles/EG2Bundle.bundle, NSLocalizedDescription=The bundle “EG2Bundle” couldn’t be loaded because its executable couldn’t be located.} was seen when loading the distant object categories bundle' terminating with uncaught exception of type NSException CoreSimulator 732.18.0.2 - Device: iPhone 11 (C2D384BF-3CA2-4DD2-8303-5D7F712A3509) - Runtime: iOS 13.7 (17H22) - DeviceType: iPhone 11'

Bundle path is correct and bundle is copied correctly, but when tests tries to load bundle it fails with error above.

I tried to google, but without luck, found this stackoverflow issue https://stackoverflow.com/questions/61575439/earlgrey-2-white-box-setup-simulator-crash-on-test-run , but it has no answer

Sadly I cannot share code of my actual project that I'm working on, but I found repo on github that if I run I get exact same error https://github.com/Simon-Kaz/EarlGrey2Example/tree/WhiteboxBundleAdded
And it was for sure working for this guy at some point, because he wrote blog post about it https://medium.com/assertqualityassurance/earlgrey2-setting-up-white-box-testing-capability-e90af19a3fee

Crash
image

Bundle load function which fails and throws that error
image

We haven't yet had an effort to support EG 2 with CocoaPods for host app bundles. Happy to work with you if you join the slack channel.

@tirodkar project setup with EG 2 is done manually, based on setup guide without CocoaPods. So on my side it is not CocoaPods problem for sure.

I have same issue on

Same issue happens also on colleagues macbook pro, so it is not specific to my mac as such.

EG 2 blackbox testing on other hand works fine. This problem occurs when adding whitebox testing part. Also error happens at runtime, just when simulator launches and tries to run EG 2 tests.

Maybe you could try to run tests on EarlGrey2ExampleUITests target in EG 2 example project to see for yourself?

I can check the same project tomorrow, but we have our FunctionalTests xcodeproject in Tests/Functional/FunctionalTests.xcodeproj which works with White-boxing.

https://github.com/google/EarlGrey/blob/earlgrey2/docs/white-boxing-setup-guide.md#setup-a-helper-bundle

These steps need to be followed to ensure that whiteboxing is added.

I'm blocked by the same issue. Appreciate any help? @tirodkar
@Jamagas Did you find any solution?

@Jamagas any update on checking with the FunctionalTests project? @radhap perhaps you could also test this as well?

I tried it and keep getting

Showing All Errors Only
Unable to resolve build file: XCBCore.BuildFile (The workspace has a reference to a missing target with GUID '9ac443564d3c9acfe7074ca27dc9cfb00f6eb7f5343191a95c9c8839125f8e41')

@tirodkar, @radhap Tests/Functional/FunctionalTests.xcodeproj indeed works. But that don't help for fresh setup.

I didn't had time yet to check what is the difference versus fresh setup via https://github.com/google/EarlGrey/blob/earlgrey2/docs/white-boxing-setup-guide.md#setup-a-helper-bundle which don't work.

It is definitely something different or extra done than in setup guide.

Got it. I'll re-do the steps again to see if anything might have to be updated. Wanted to make sure there wasn't anything wrong in the Xcode setup at all.

@tirodkar were you able to find the missing steps in white box testing? This really has blocked our work!

@Jamagas I've got the issue for why you might have issues with your setup. Did you add a Copy Files phase in your tests along with AppFramework for the HelperBundle?

https://github.com/google/EarlGrey/blob/earlgrey2/docs/white-boxing-setup-guide.md#embed-the-bundle-into-your-application-under-test

You have to make sure the Copy Files points correctly to your App target's .app file - $(TARGET_BUILD_DIR)/../../YOUR_APP.app/EarlGreyHelperBundles. There's slight updates to be added to the documentation, but the steps seem to be accurate in it. I'll link the PR here so you can give your comments.

@radhap

Unable to resolve build file: XCBCore.BuildFile (The workspace has a reference to a missing target with GUID '9ac443564d3c9acfe7074ca27dc9cfb00f6eb7f5343191a95c9c8839125f8e41')

This is a workspace integrity issue and something to do with the Xcode Setup itself from what I can see. Can you repro it with a vanilla target and add the Github project here?

@tirodkar you faced different issue than I have
Here is vanilla project https://github.com/Jamagas/SampleTool
I'm reproducing same issue in it. Hope this vanilla project will help you reproduce issue on your side.

Only deviation from setup guide is User Header Search Paths which are pointing to $(SRCROOT)/EarlGrey recursively, but that should not matter.

Also bridging header I added not manually but added objC file and then used pop up dialog asking to add it. This generated also CLANG_ENABLE_MODULES = YES; and SWIFT_OPTIMIZATION_LEVEL = "-Onone";, but that should not matter either.

@Jamagas your problem is that you do not have any source files added, hence the Bundle is technically empty and can't be loaded.

Jamagas/SampleTool#1 fixes your problem and I can run the tests.

@Jamagas any update?

@tirodkar yes it solves my issue 🙂 thanks a lot 🙂
Tested your changes and problem is gone