Unable to launch app on IOS Simulator - WebDriver Agent error - ios

I have installed Appium and XCode and am trying to launch an app on the simulator. The app works when I open the simulator manually and click on the app.
My capabilities look as follows:
File app = new File ("/Users/me/Desktop/myapp.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName", "iPhone 8");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
The error I get is:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: "Command 'Scripts/bootstrap.sh -d' exited with code 1". (WARNING: The server did not provide any stacktrace information)
I followed the instructions given in the answer to this question:
Unable to launch ipa file in IOS 10 real Device using appium 1.6.0
When I build the WebDriverAgent through XCode, it builds without any problems, but as soon as I try to launch through IntelliJ or Appium Desktop, it gives me that error.

So I eventually managed to get it working, here are some of the errors that I encountered and how I fixed them:
Unable to launch WebDriverAgent because of xcodebuild failure: "Command 'Scripts/bootstrap.sh -d' exited with code 1
Solution: looking at the Appium server log, I noticed that it was unable to write to a directory. The problem was that my Appium app was sitting in Downloads. Once I moved it to Applications, this problem was fixed.
XCode build failed with exit code 65
Solution: the problem here was with my Provisioning Profiles (I opened the app in XCode and went to the General tab to see these).
I had created a personal apple account, but I didn't have the certificates needed to run the app. I had to get one of our iOS developers to invite me to their team, downloaded certificates and then ticked the "Automatically manage signing" check box -- there were a couple of other steps with the certificates that I can't remember.
It was connecting to the simulator, it launched WebDriverManager, but then wouldn't launch my app (it just hung).
Solution: I had made a mistake in my capabilities, I had it set as:
capabilities.setCapability("bundleId", "com.facebook.WebDriverAgentLib");
Which was the bundleID for WebDriverAgent, I updated it with the bundleID for my app:
capabilities.setCapability("bundleId", "myapp");
(Bundle ID can be found by going to the app in finder, right clicking and selecting "Show Package Contents". Open the "Info.plist" file and there you'll find the Bundle ID for the app.

Related

Xcode 14 is not getting attached to Simulator in Debug mode

While debugging any iOS application, Xcode builds and run successfully, also launches a simulator but it is not able to attach debugger from Xcode 14 to Simulator iOS app.
It throws an error in Xcode:
Xcode console says:
Could not attach to pid : “75997” Domain: IDEDebugSessionErrorDomain
Code: 3 Failure Reason: attach failed (Not allowed to attach to
process. Look in the console messages (Console.app), near the
debugserver entries, when the attach failed. The subsystem that
denied the attach permission will likely have logged an informative
message about why it was denied.) User Info: {
DVTRadarComponentKey = 855031;
IDERunOperationFailingWorker = DBGLLDBLauncher;
RawUnderlyingErrorMessage = "attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the
debugserver entries, when the attach failed. The subsystem that
denied the attach permission will likely have logged an informative
message about why it was denied.)"; }
Tried with re-installing Xcode and Command line tools, but issue persists.
Steps:
Build and run app with Debug executables true
Simulator gets launched
Error on Xcode and it gets disconnected from simulator
Is there a possibility that it can be blocked by any other app, if so how to identify ?
I solved the issue by doing the steps below:
SOLUTION 1:
Edit the scheme
Select Run
Select Build Configuration "Debug"
Select "Wait for the executable to be launched"
Close
Run the app
see the screenshot here
You will receive an error message when you run the app again.
Close the app.
Edit the scheme again and change "Wait for the executable to be launched" to "Automatically".
Now your simulator will work as expected.
SOLUTION 2:
Delete your app folder in Derived Data
/Users/[your username]/Library/Developer/Xcode/DerivedData/
Search your app name folders and delete them.
SOLUTION 3:
Open the terminal and run:
sudo DevToolsSecurity -enable
This command enables the Developer Mode. After running the command you will receive this message: [Developer mode is now enabled].
Sometimes it's happen, when you are trying to build too fast after a build has started.
First of all, quit your current simulator, delete derived data and clean the project, wait until whole processing is complete. Then do some changes / editing if required (as we clean all data) and try running on a different simulator.
Check certificates in key-chain access, if you found any untrusted certificates in key-chain access remove it.
Also if you are using beta version just make sure it is downloaded from Apple official website.
Came here to share my (strange) solution if anybody crosses the same problem with no answers working. In my case, no solution from this nor other SO answers to similar questions worked (cleaning, rebuilding project, updating, clearing derived data..)
My setup is:
Macbook M1 2022 + Xcode Version 14.2 (14C18)
This Xcode version could not attach to any of my apps (fresh new or previously developed) on different simulators (11, 12, 14) with iOS versions 13.7 - 16.2.
Editing scheme solution from answer above was not working also so I ended up in leaving scheme as:
Build configuration: Release
Debug executable Deselected(!)
Launch Automatically
And magically debugging app in Xcode started working even though it's release version with debug option deselected.. Selecting Debug executable again makes Xcode not possible in attaching to app process
Just to clarify: above steps actually makes app to run as in DEBUG mode - Xcode attaches to pid, I can do console logs and breakpoints. This Xcode version behaves opposite than options selected

Could not run build/ios/iphoneos/Runner.app on

I was running the app on my iPhone using Xcode and android studio. It worked fine. But I downloaded the same app through the app store on the same phone. And now when I run it on android studio, it shows the following error:
Launching lib/main.dart on iPhone in debug mode... Automatically
signing iOS for device deployment using specified development team in
Xcode project: 59HZQ7G7DK Running Xcode build... Xcode build done.
29.2s Installing and launching... Could not run build/ios/iphoneos/Runner.app on
5bde4016fc......5f1439d5ef0. Try launching Xcode and
selecting "Product > Run" to fix the problem: open
ios/Runner.xcworkspace
Error launching application on iPhone.
Running on Xcode shows the following error message
I tried deleting the app and rerunning it using android studio but the same error still appears.
Any idea how to resolve this?
-------------------Edit Below----------------------
I then followed this and deleted "Iphone Developer" and "Apple Worldwide Developer Relations Certification Authority".
However, after deleting, another error message appears when running on xcode as shown:
Command PhaseScriptExecution failed with a nonzero exit code
I then went over to the Member Center on the Apple Developer website to download the apple development cert but now it shows the same error message as the first error message shown above.
I then deleted all my provisioning profiles following this. Restarted the phone and rerun and the problem is resolved.

Unable to run WebDriverAgent on the real device using Appium Desktop

I am unable to run WebDriverAgent on a real device using Appium Desktop. I have attached gist for the error log.
I have tried some solution from github/appium but it did not solve my issue.
server log
https://gist.github.com/guowang94/ec923da6a3b77aca06a902c450200238
appium.app error message
https://gist.github.com/guowang94/ef2c5bb5bcc617baa2af19418e9a8b8e
I expect the WebDriverAgent to be running in the real device so that I can proceed to my next task but I am unable to install and run WebDriverAgent on the real device
Your logs have both the problem:
An empty identity is not valid when signing a binary for the product type 'UI Testing Bundle'. (in target 'WebDriverAgentRunner')
which indicates incorrect XCode configuration with regards to signing the WebDriverAgentRunner-Runner.app
and the solution:
Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65 .... Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md
If the official guide is not clear you can follow steps from the Configuring Appium Environment for iOS Real Device article.
You can also consider Appium Studio which makes the process of setting up Appium testing on real iOS devices much easier.

is 'APP' capability REQUIRED for WDA installation?

I'm trying to run an appium script with a real iOS device. I am currently getting this error:
Encountered internal error running command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: "xcodebuild failed with code 65". Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
Apparently this error is associated with security issues at noted here, but I've already completed that step and it's still not working. So then I thought maybe this is b/c my appium script does NOT set the 'APP' capability. 'APP' capability is of course is the full path to the application that is under test. The appium documentation here obviously doesn't indicate which settings are required if any. My question is will the Webdriver Agent not get installed on the device if the 'APP' capability is not set and thus throwing the error above?
You can right-click on the appium app (which is in ur application folder) you are using > show package contents > search for .xcodeproj > you will see a couple of projects including web driver. Now open web driver agent Xcode project and use an apple developer account to code sign it.
If you have already done this, then please update your question with appium capabilities that you have set.

Appium iOS tests not running

I'm attempting to setup an automated testing environment using appium, however I'm running into trouble. The issue I'm seeing is that appium is extracting the zip containing the .app directory, but then claiming that it can't find the .app. My platform is mac. The exact error is below:
info: Unzipping /var/folders/0s/0kz_6kb13f35wxwjxkff9sdw0000gn/T/appium-app113922-2258-1ap6o7i.zip
info: Testing zip archive: /var/folders/0s/0kz_6kb13f35wxwjxkff9sdw0000gn/T/appium-app113922-2258-1ap6o7i.zip
info: Zip archive tested clean
info: Unzip successful
info: Got configuration error, not starting session
error: Failed to start an Appium session, err was: App zip unzipped OK, but we couldn't find a .app bundle in it. Make sure your archive contains the .app package and nothing else
info: Responding to client with error: {"status":6,"value":{"message":"A session is either terminated or not started","origValue":"App zip unzipped OK, but we couldn't find a .app bundle in it. Make sure your archive contains the .app package and nothing else"},"sessionId":null}
I'm not sure if I'm doing something wrong in my code, below is the contents of my setup() method (which is basically copied from the official example).
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "8b0949a1d3fe5d7283cc46ca5470acd67d6c5d7b");
File app = new File("/Users/user/path/to/zip");
capabilities.setCapability("version", "7.0");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Things to consider:
Your .zip should contain only the .app
The .app should be built in XCode with the same dev certificate that is used on the device (iPhone)
For me it worked this way: I built an .app from source in XCode and uploaded to the device. Then in Appium I just specified the Bundle ID (in XCode Window>Organizer>Apps if I remember it right) of the app.
For anyone with a similar problem: I fixed this issue by specifying the .app file but specifying the UDID of the device at the command line when running appium instead of in the test code. I think that specifying the 'device' capability causes an error (possibly makes appium think that it's android testing, despite writing out that it's looking for a .app)

Resources