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

XCode Version: 8.2.1 (8C1002)
Appium version: v1.6.3

After accessing folder: /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

I execute command:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=11156f93ade4dfb2935fc0706843747c2ed54ac6’ test

Then, I get error:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest
Referenced from: /var/containers/Bundle/Application/E785C49A-ED5F-4971-BBBD-7F39C9E35498/WebDriverAgentRunner-Runner.app/XCTRunner
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/E785C49A-ED5F-4971-BBBD-7F39C9E35498/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of ‘/private/var/containers/Bundle/Application/E785C49A-ED5F-4971-BBBD-7F39C9E35498/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest’
/private/var/containers/Bundle/Application/E785C49A-ED5F-4971-BBBD-7F39C9E35498/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of ‘/private/var/containers/Bundle/Application/E785C49A-ED5F-4971-BBBD-7F39C9E35498/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest’
2017-01-15 22:42:13.586 xcodebuild[46672:740949] 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}
** TEST EXECUTE FAILED **

I invested and did the below solutions, but the error still occurs:

  • Use XCode to Open WebDriverAgent project and choose ‘Team’ & ‘Signing Certificate’ in section ‘Signing’ in tab General for targets ‘WebDriverAgentLib’, ‘WebDriverAgentRunner’, ‘UnitTests’, ‘IntegrationTests’, ‘IntegrationApp’
  • Copy ‘XCTest.framework’, then paste into WebDriverAgent project, link to ‘Frameworks’ under this project
  • Create file ‘Config.xcconfig’ under ‘Configurations’ in this project, content:
    DEVELOPMENT_TEAM = U9THH755P3
    CODE_SIGN_IDENTITY = iPhone Developer
  • In the ‘Framework Search Path’ in Build Settings, add ‘$(PLATFORM_DIR)/Developer/Library/Frameworks’

Could you please support me to resolve this issue?

What are you capabilities?

Do you have this one?
capabilities.setCapability(“automationName”,“XCUITest”);

Yes @dduphorn, I also has the file ‘appium.txt’ with the below content to run with command ‘arc’:

[caps]
platformName = “ios”
app = “./hung7/hung7.ipa”
deviceName = “HungNguyen”
automationName = “XCUITest”
udid = “11156f93ade4dfb2935fc0706843747c2ed54ac6”
xcodeOrgId= “U9THH755P3”
xcodeSigningId = “Iphone Developer”

But for now, I just wanna build WebDriverAgent project, this project is included in appium node module. After we install appium, the project will exist in regular folder path:
/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

The command I used to execute is:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id=11156f93ade4dfb2935fc0706843747c2ed54ac6’ test

And the error I mentioned in the above display. Do you have another solution for this?
Thanks!

What comes back when you do you execute the below in a terminal

which node
which appium

@hung.nguyen201087 - I’m having the exact same issue when I try running this command in the terminal: xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=85460f322cff23dfdb2f5b94504b0fd64f8ef712' test

I tried the same fixes that you tried, and I can’t get around this issue. I can run tests on the simulator, but not on real devices.

@dduphorn -
which node -> /Users/myname/.nvm/versions/node/v7.3.0/bin/node
which appium -> /Users/myname/.nvm/versions/node/v7.3.0/bin/appium

Edit: I also tried downgrading to Appium 1.6.1 as it seemed to work for some people, but that’s not working for me. I get the exact same error, which is exactly the same as what @hung.nguyen201087 reported.

I was successfully able to run agains a real device

Below are my Capabilities, see if yours are similar. Also, I’m using node 6.0.

capabilities.setCapability(“platformName”,“iOS”);
capabilities.setCapability(“udid”,strIOSUdid);
capabilities.setCapability(“deviceName”,strIOSDeviceName+"("+strIOSUdid+")");
capabilities.setCapability(“platformVersion”, “10.2”);
capabilities.setCapability(“automationName”,“XCUITest”);
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;}

My capabilities are similar. They are as as follows:

	capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
	capabilities.setCapability("nativeWebTap", true);
	capabilities.setCapability("platformName", ConfigIOSspk.PLATFORM_NAME);
	capabilities.setCapability("automationName", "XCUITest");
	capabilities.setCapability("platformVersion", ConfigIOSspk.IOS_VERSION);
	capabilities.setCapability("device", ConfigIOSspk.DEVICE);
	capabilities.setCapability("deviceName", ConfigIOSspk.DEVICE_NAME);
	capabilities.setCapability("sendKeyStrategy", "setValue");
	capabilities.setCapability("autoAcceptAlerts", true);
	capabilities.setCapability("xcodeConfigFile", "/Users/myname/node_modules/appium-xcuitest-driver/WebDriverAgent/Config.xcconfig");
	
	if (!ConfigIOSspk.IS_SIMULATOR) { 

		capabilities.setCapability("app", System.getProperty(ConfigIOSspk.USER_DIR) + ConfigIOSspk.APP_FILE_LOCATION_IPA);
		System.out.println(System.getProperty(ConfigIOSspk.USER_DIR) + ConfigIOSspk.APP_FILE_LOCATION_IPA);
		capabilities.setCapability("realDeviceLogger", "/Users/myname/.nvm/versions/node/v7.3.0/lib/node_modules/deviceconsole/deviceconsole");
		capabilities.setCapability("keychainPath", "/Users/myname/Library/Keychains/CindyKeychain.keychain"); 
		capabilities.setCapability("keychainPassword", "mykeychainpassword"); 
		capabilities.setCapability("bundleId", ConfigIOSspk.BUNDLE_ID);
		capabilities.setCapability(MobileCapabilityType.UDID, ConfigIOSspk.UDID);
	
	} else {
		
		capabilities.setCapability("app", System.getProperty(ConfigIOSspk.USER_DIR) + ConfigIOSspk.APP_FILE_LOCATION_APP);
	}

I’ll give node 6.0 a shot. Thanks for your reply.

Update: Unfortunately, switching to node 6.0 did not help. Still getting the exact same error.

@hung.nguyen201087 - If you try to run tests on the real device, what are the errors that you’re getting back from the Appium log?

Edit: The reason that I was asking for the Appium log is because I was also seeing the following code signing error in mine related to WebriverAgentLib:
[Xcode] No signing certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID "GVJ6SAHW84" with a private key was found.

My Config.xcconfig file was using the wrong team id and I fixed it. The Appium log no longer reports the code signing error shown above, but I still get this error:

[Xcode] dyld: Library not loaded: @rpath/XCTest.framework/XCTest
  Referenced from: /var/containers/Bundle/Application/6B366598-C133-45B0-9185-610091A16FC8/WebDriverAgentRunner-Runner.app/XCTRunner
  Reason: no suitable image found.  Did find:
	/private/var/containers/Bundle/Application/6B366598-C133-45B0-9185-610091A16FC8/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of '/private/var/containers/Bundle/Application/6B366598-C133-45B0-9185-610091A16FC8/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest'
	/private/var/containers/Bundle/Application/6B366598-C133-45B0-9185-610091A16FC8/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of '/private/var/containers/Bundle/Application/6B366598-C133-45B0-9185-610091A16FC8/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest'

So it seems that there’s still a code signing issue (code signing blocked mmap() of...) in addition to this XCTest problem.

XCTest.framework is included in my project:

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.