Appium IOS 测试在服务器手动启动时运行,但在服务器通过 AppiumDriverLocalService 启动时不运行

时间:2021-02-17 17:04:34

标签: java selenium-webdriver appium qa appium-ios

尝试在 Mac Mini(M1 芯片,如果相关)上的 iOS(模拟器)上运行 Appium 自动化脚本。当我运行测试时,当 Appium 服务器手动启动时它们工作得很好(在终端中输入“appium”并以这种方式启动)。但是,当我尝试以编程方式启动 appium 服务器时,被测应用程序无法启动,并出现以下错误:

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))

这是完整的 appium 日志:https://gist.githubusercontent.com/fida10/44344b223874310cf296d38a95d4268f/raw/316855b619129680eeaa6519a446a436d0699cd6/failedLog.txt

我最初认为这是 xcode 或 WDA 的问题,但如果是这种情况,那么无论 Appium 如何启动,测试都会失败,并且如前所述,当手动启动 Appium 时,测试完全通过(通过终端),因此从 Java 执行时可能是 PATH 或环境变量的问题,但不确定。

这是我用来以编程方式启动服务器的代码:

        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();

如 appium 日志所示,服务器似乎启动正常,但随后抛出上述错误,所以我认为问题可能与我如何构建 AppiumDriverLocalService 对象有关。

我按照本教程构建 AppiumDriverLocalService:https://appiumpro.com/editions/71-starting-an-appium-server-programmatically-using-appiumservicebuilder

这是项目代码。这是一个简单的项目,我只是点击了一个“允许”按钮(第 26 行):https://gist.github.com/fida10/bec187a516fc32f907f97725263a7206

当我注释掉 AppiumDriverLocalService 服务器对象(第 46 到 58 行)并通过取消注释第 60 行启动时,测试正常运行。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

能够通过在 XCode 构建设置中将“仅构建活动架构”下的所有选项设置为“否”来解决它。详情:https://github.com/appium/java-client/issues/1444#issuecomment-781078298

希望这对尝试在带有新 M1 芯片的 Mac 设备上运行 XCUITests 的人有所帮助。