Error "dyld: Library not loaded: @rpath/XCTest.framework/XCTest" displays When deploying WebDriverAgent into real device

Are you able to run the test against a simulator?

@dduphorn - Yes, I can run against simulator without issue.

I’ll try running against a real device sometime today. I have to wait until a developer gets in, because I need a certified APP.

When I build my own in Xcode I’m unable to open it successfully on a real device.

I’ll post my findings.

Thanks, @dduphorn. I sat down with an iOS dev yesterday and tried to get this straightened out and he’s also at a loss. He thought he knew how to fix it but nothing ended up working. I’ve already been down the path of uninstalling everything and reinstalling it, but I haven’t included Xcode in that process. So I’m going to try again to start from scratch and see if it helps.

I’ll keep you posted as well.

Update: Didn’t help. Still getting the same error.

If it’s helpful, I’ll also mention that WebDriverAgentRunner does get installed on the device when I try to run tests.

@chiwhitesox56
@hung.nguyen201087

I just wanted to update you that I’m still trying to figure it out. I’m also struggling to run on a real IOS Device.

When I run: xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=c8be317ecec81cd9b8d06b47bcb575a7f46ced57’ test

Testing failed:
Signing for “WebDriverAgentRunner” requires a development team. Select a development team in the project editor.
Code signing is required for product type ‘UI Testing Bundle’ in SDK ‘iOS 10.2’
** TEST FAILED **

I got passed the above by.

  1. Open Xcode
  2. File Open
  3. Navigated to: /Users/[User]/node_modules/appium-xcuitest-driver/WebDriverAgent
  4. Selected: WebDriverAgent.xcodeproj
  5. Click the General link in Xcode
  6. Select WebDriverAgentLib (Under Target)
  7. Check: Automatically manage signing
  8. Added: My Team
  9. Selected: WebDriverAgentRunner (Under Target)
  10. Check: Automatically manage signing
  11. Added: My Team
  12. Open Terminal and re ran: xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=c8be317ecec81cd9b8d06b47bcb575a7f46ced57’ test
  13. Got Successful Message

writeDictToFile:1278 ==== Successfully wrote Manifest cache to /var/folders/h8/vkp1j5193d5g9kpmbyd3f3700000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/1192305d407e59dac528a7de89efab56/c8be317ecec81cd9b8d06b47bcb575a7f46ced57/ManifestCache.plist
Test Suite ‘All tests’ started at 2017-01-21 14:05:05.232
Test Suite ‘WebDriverAgentRunner.xctest’ started at 2017-01-21 14:05:05.236
Test Suite ‘UITestingUITests’ started at 2017-01-21 14:05:05.238
Test Case ‘-[UITestingUITests testRunner]’ started.
t = 0.00s Start Test at 2017-01-21 14:05:05.243
t = 0.01s Set Up

  1. Executed the automated script and failed launching with the below error.

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not initialize ios-deploy make sure it is installed and works on your system (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 378 milliseconds
Build info: version: ‘2.52.0’, revision: ‘4c2593c’, time: ‘2016-02-11 19:03:33’
System info: host: ‘Darins-MacBook-Pro.local’, ip: ‘10.0.0.8’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.2’, java.version: ‘1.7.0_79’
Driver info: io.appium.java_client.ios.IOSDriver

  1. Enter: which ios-deploy and I get the below
    /Users/[user]/.nvm/versions/node/v6.0.0/bin/ios-deploy

**I got past the above by running brew install ios-deploy from the /Users/[User]/node_modules/appium-xcuitest-driver/WebDriverAgent *Not sure if you need to execute from here.

When I executed the automated script:

Testing failed:
Signing for “WebDriverAgentRunner” requires a development team. Select a development team in the project editor.
Code signing is required for product type ‘UI Testing Bundle’ in SDK ‘iOS 10.2’

read pavanbachu
After you are done setting up the config file rebuild the APP.
Try executing again.

@dduphorn: Sorry to reply late. Now I need to run command line to build successfully WebDriverAgent first.

@chiwhitesox56
@dduphorn

I did the following steps:

  1. Access /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
  2. open ‘WebDriverAgent.xcodeproj’
  3. Select ‘Automatically manage signing’
  4. Select Team
  5. Change bundle id for both WebDriverAgentLib & WebDriverAgentRunner to make it register with new Signing Certificate
  6. Open Terminal and execute command:
    xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=11156f93ade4dfb2935fc0706843747c2ed54ac6’ test

Result:

2017-01-22 01:38:41.739 xcodebuild[12300:128081] Error Domain=com.apple.platform.iphoneos Code=-12 “Unable to launch com.apple.test.WebDriverAgentRunner-Runner” UserInfo={NSLocalizedDescription=Unable to launch com.apple.test.WebDriverAgentRunner-Runner, NSUnderlyingError=0x7fe53247a840 {Error Domain=DTXMessage Code=1 “(null)” UserInfo={DTXExceptionKey=The operation couldn’t be completed. Unable to launch com.apple.test.WebDriverAgentRunner-Runner because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user. : Failed to launch process with bundle identifier ‘com.apple.test.WebDriverAgentRunner-Runner’}}}
2017-01-22 01:38:41.739 xcodebuild[12300:128081] Error Domain=IDETestOperationsObserverErrorDomain Code=5 “Early unexpected exit, operation never finished bootstrapping - no restart will be attempted” UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted}

Testing failed:
Test target WebDriverAgentRunner encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)

I think this is the root cause that I cannot run appium test on real device

@hung.nguyen201087, @dduphorn - Thank you for sharing what you’ve done. I’ll do the same in a separate post. I’m still struggling to get tests running on a real device as well.

@dduphorn - I don’t have a file called “WebAgent.xcworkspace” in my Resources folder. I only have a file called “WebDriverAgent.bundle”

Do you see errors and or warnings when you open WebDriverAgent.xcodeproj in Xcode?

Yeah, I’m not sure what the WebAgent.xcworkspace came from now. I tried so many different things, I would ignore that part until I can figure out what I was trying to do.

I don’t get a error opening WebDriverAgent.xcodeproj. What is your error.

I just got my code to execute on a real device!

1 Like

Here are the steps that I followed:

  1. Opened WebDriverAgent.xcodeproj from /Users/[me]/node_modules/appium-xcuitest-driver/WebDriverAgent
  2. Set active scheme to my real device
  3. Checked “Automatically manage signing” and selected my team for WebDriverAgentLib and WebDriverAgentRunner. I did this for IntegrationApp, UnitTests and IntegrationTests too.
  4. Went to WebDriverAgentLib → General → LinkedFrameworks and Libraries and linked XCTest.framework to project. I also checked the Target Membership for WebDriverAgentRunner with XCTest.framework selected
  5. Grabbed the Configurations folder from GitHub and added it to the WebDriverAgent folder. (I did this because I was getting an error saying that “ProjectSettings.xcconfig” did not exist. I got it from here: WebDriverAgent/Configurations at 952847f8c2bbe54ebdb9137b47e3c7343f988668 · facebookarchive/WebDriverAgent · GitHub)
  6. Cleaned project and built WebDriverAgentLib and WebDriverAgentRunner, and verified that both build successfully

When I run the command line test against the device (xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=85460f322cff23dfdb2f5b94504b0fd64f8ef712' test), WebDriverAgentRunner does get installed on the device. However, I get the following failure message:

writeDictToFile:1278 ==== Successfully wrote Manifest cache to /var/folders/d3/d4s4vkts3lxbb4mzh38v2mm1mdml4l/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/e177ee3a0f93eba6745c3f9c1bef6164/85460f322cff23dfdb2f5b94504b0fd64f8ef712/ManifestCache.plist
dyld: Library not loaded: @rpath/XCTest.framework/XCTest
> Referenced from: /var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/XCTRunner
> Reason: no suitable image found. Did find:
> /private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of ‘/private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest’
> /private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of ‘/private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest’
2017-01-23 09:55:52.290 xcodebuild[15014:2262160] Error Domain=IDETestOperationsObserverErrorDomain Code=5 “Early unexpected exit, operation never finished bootstrapping - no restart will be attempted” UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted}

Testing failed:
Test target WebDriverAgentRunner encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)
** TEST FAILED **

According to the full log, it seems that the following points are true:

  • The logs are showing that the Signing Identity and Provisioning Profile are found
  • The error seems to be associated with WebDriverAgentRunner because that’s the header it falls under in the output displayed in the terminal
  • My XCTest.framework library is either not being unloaded. It it unclear whether it is being found or not

A few questions:

  • @hung.nguyen201087 - In your steps, I see that step 5 says that you changed the bundle id for WebDriverAgentLib and WebDriverAgentRunner. Can you please explain those changes a bit more?
  • @hung.nguyen201087, @dduphorn - Are you still getting the dyld: Library not loaded: @rpath/XCTest.framework/XCTest error? I’ve tried several different methods of pointing to XCTest.framework and I continue to get this error. If you’re not getting this error, can you please tell me how you’re pointing to XCTest.framework?

Edit: I also tried linking to XCTest.framework under WebDriverAgentRunner → Build Phases. It did not work - same error.

You got it working? That’s great!

I’m not getting an error in WebDriverAgent.xcodeproj at the moment. I was just going to see if I could help you if you were getting one.

After you updated the WebDriverAgentLib and the WebDriverAgentRunner signings did you created the Config.xcconfig file with the correct Development Team id?

If you did, did you try to clean and build a new App?

Below are the only Capabilities that I have set:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“newCommandTimeout”, 60 * 5);
capabilities.setCapability(“platformName”,“iOS”);
capabilities.setCapability(“deviceName”,strIOSDeviceName);
capabilities.setCapability(“fullReset”, true); //Not currently unistalling app
capabilities.setCapability(“automationName”,“XCUITest”);
capabilities.setCapability(“udid”,strIOSUdid);
capabilities.setCapability(“xcodeConfigFile”,"/Users/[user]/.nvm/versions/node/v6.0.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Config.xcconfig");
File f = new File(strIOSPath);
if(f.exists()) {capabilities.setCapability(“app”,strIOSPath);}
else{String strErrorMsg = “The IOS application path didn’t exists (”+strIOSPath+")";Reporter.log(""+strErrorMsg+"");Assert.fail(strErrorMsg);return null;}
capabilities.setCapability(“launchTimeout”, 60000);
capabilities.setCapability(“sendKeyStrategy”,“setValue”);

I don’t know what you did in step 2, and I didn’t do 4 & 5.

Based on the research that I’ve done and just by studying the content of the logs, I think this “Library not loaded” error is actually a code signing issue - especially since you didn’t have to make any changes to the XCTest.framework configuration in Xcode to get tests running on a real device

From terminal test log:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of ‘/private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest’

My Appium real device log shows the same error as above, but also includes " xcodebuild exited with code '65' and signal 'null'" which is indicative of a code signing issue.

A few questions for you, @dduphorn:

  1. The certificate that your private key is associated with - is it a Developer or a Distribution certificate?
  2. Am I understanding correctly from your capabilities that you did not set the following: realDeviceLogger, keychainPath, keychainPassword
  3. Does your development team ID match the ID listed next to the certificate in Keychain Access? (This may not apply if you’re not dealing with the keychain, but I thought that was required.)

For Step 2, I just meant that I made sure I had my real device selected as shown below. Sorry for the confusion there.

Thanks a lot for your help.

  1. The certificate that your private key is associated with - is it a Developer or a Distribution certificate? Answer Developer

  2. Am I understanding correctly from your capabilities that you did not set the following: realDeviceLogger, keychainPath, keychainPassword? Answer Correct

  3. Does your development team ID match the ID listed next to the certificate in Keychain Access? (This may not apply if you’re not dealing with the keychain, but I thought that was required.) ? The Developer gave me the team Id and I added it to my Config.xcconfig file which once created appears under the WebDriverAgent. When I click on the Config.xcconfig file make sure you have the Target Membership set to include WebDriverAgentLib & WebDriverAgentRunner.

  4. Yes, make sure you have the real device selected above

  5. Click Play and make sure Build Successful message appears

  6. Next open up your application project so you can clean and rebuild the app. Again make sure you select the real device.

Remember to add this to you capabilities
capabilities.setCapability(“xcodeConfigFile”,"/Users/[User]/.nvm/versions/node/v6.0.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Config.xcconfig");

We will figure it out :slight_smile:

1 Like

Thanks so much for your detailed explanation. I have to switch focus for a day or two, but I’ll get back to you and update this post after I’ve reviewed my configurations.

Did you ever resolve your issue.

I think I ran into the one you were facing, and I think it was caused because Carthage was already installed on my machine in a different location. It messed up everything.

DD

@dduphorn - I haven’t resolved my issue yet because work is pulling me in a different direction. I do want to get back on this and get it resolved though.

Do your Appium server logs tell you that Carthage is found? I’m asking because while I was working on this, I know I ended up with multiple installations of Carthage and I was wondering whether that would be a problem. According to the logs Carthage was found, so I figured it wasn’t an issue.

Thanks for the follow-up. I’ll get back on this as soon as I can.

@chiwhitesox56

I did not see anything in the logs, but I did notice the appium-xcuitest-driver was getting installed in a different director.

When Carthage was not installed appium-xcuitest-driver appeared in the following directory.

/Users/[User]/.nvm/versions/node/v6.0.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver

When Carthage was previously install it appeared

/Users/mpsadmin/node_modules/appium-xcuitest-driver

I might of missed a step, but when it appeared in the 2nd one it messed everything up.

DD