Attempting to run Appium automation scripts on iOS (simulator) on a Mac Mini (M1 chip, if that’s relevant). When I run the tests, they work just fine when the Appium server is started manually (typing “appium” into the terminal and starting it that way). However, when I attempt to start the appium server programmatically, the application under test fails to launch, with the following error:
2021-02-17 03:41:27:256 [W3C] WebDriverAgentRunner-Runner.app (19077) encountered an error (Failed to load the test bundle. If you believe this error represents a bug, please attach the result bundle at /Users/sagolGoru20/Library/Developer/Xcode/DerivedData/WebDriverAgent-gkbkvswlszzhhbevpokpwtrjdxxq/Logs/Test/Test-WebDriverAgentRunner-2021.02.16_22-41-22--0500.xcresult. (Underlying Error: **The bundle “WebDriverAgentRunner” couldn’t be loaded because it doesn’t contain a version for the current architecture. The bundle doesn’t contain a version for the current architecture. Try installing a universal version of the bundle.** dlopen_preflight(/Users/sagolGoru20/Library/Developer/Xcode/DerivedData/WebDriverAgent-gkbkvswlszzhhbevpokpwtrjdxxq/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/WebDriverAgentRunner): no suitable image found. Did find: 2021-02-17 03:41:27:256 [W3C] /Users/sagolGoru20/Library/Developer/Xcode/DerivedData/WebDriverAgent-gkbkvswlszzhhbevpokpwtrjdxxq/Build/Products/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/WebDriverAgentRunner: mach-o, but wrong architecture))
I originally thought that this was an issue with xcode or WDA, but if that were the case, the tests would fail no matter how Appium was started, and as mentioned previously, the tests pass perfectly fine when Appium is started manually (via terminal), so it might be an issue with the PATH or environment variables upon execution from Java, not sure though.
Here is the code I am using to start the server programmatically:
HashMap<String, String> environment = new HashMap(); environment.put("PATH", "/usr/local/bin:" + System.getenv("PATH")); AppiumDriverLocalService server = AppiumDriverLocalService .buildService(new AppiumServiceBuilder() .withEnvironment(environment) .usingDriverExecutable(new File("//opt/homebrew/Cellar/node/15.8.0/bin/node")) .withAppiumJS(new File("//Users/sagolGoru20/.npm-packages/lib/node_modules/appium/build/lib/main.js")) .usingAnyFreePort() .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withLogFile(new File("//Users/sagolGoru20/Programming/JavaProjects/MavenProjects/MobileAutomationProjects/firstAppiumProject/appiumLog.txt")) ); server.start();
As the appium log shows, the server seems to be started fine but then throws the above error, so I think the issue may be with how I’m building the AppiumDriverLocalService object
I followed this tutorial in building AppiumDriverLocalService: https://appiumpro.com/editions/71-starting-an-appium-server-programmatically-using-appiumservicebuilder
Here is the project code. It’s a simple project, I’m just clicking on an “Allow” button (line 26): https://gist.github.com/fida10/bec187a516fc32f907f97725263a7206
Any help would be greatly appreciated.