“onPrepare”挂钩中的服务失败

问题描述 投票:0回答:1

我正在使用 Appium 和 WebDriverIO 运行 Android 应用程序测试用例。我遇到以下错误:

Execution of 1 workers started at 2024-02-26T10:08:46.718Z

2024-02-26T10:08:47.749Z ERROR @wdio/appium-service: info

2024-02-26T10:08:47.750Z ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: info
    at Socket.<anonymous> (file:///home/runner/work/e2e-tests/node_modules/@wdio/appium-service/build/launcher.js:172:28)
    at Object.onceWrapper (node:events:633:26)

    at Socket.emit (node:events:518:28)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
Continue...

依赖关系


"@wdio/allure-reporter": "^8.32.2",
   "@wdio/appium-service": "^8.32.3",
   "@wdio/cli": "^8.32.3",
   "@wdio/local-runner": "^8.32.3",
   "@wdio/mocha-framework": "^8.32.3",
   "@wdio/spec-reporter": "^8.32.2",
   "appium": "^2.5.1",
    "appium-uiautomator2-driver": "^3.0.1"

配置文件

const path = require('path');
exports.config = {

    runner: 'local',
    specs: [],
    exclude: [],
    maxInstances: 10,
    capabilities: {
        phone1: {
            port: 4442,
            path: '/',
            capabilities: {
                platformName: 'android',
                'appium:automationName': 'uiautomator2',
                'appium:deviceName': 'Pixel 3a',
                'appium:platformVersion': '14',
                'appium:udid': 'emulator-5554',
                'appium:adbExecTimeout': 50000,
                'appium:noReset': false,
                'appium:dontStopAppOnReset': true,
                'appium:fullReset': false,
                'appium:systemPort': 8200,
                'appium:appWaitDuration': '2000000',
                'appium:app': path.join(process.cwd(), '../app/build/outputs/apk/debug.apk'),
                'appium:autoGrantPermissions': true,
                'appium:uiautomator2ToastWaitTimeout': 7000,
                'appium:waitforTimeout': 30000,
                'appium:newCommandTimeout': 600
            }
        }
    },

    logLevel: 'error',
    bail: 0,
    baseUrl: '',
    waitforTimeout: 100000,
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    services: [
        [
            'appium',
            {
                command: 'appium',
                args: {
                    port: 4442
                }
            }
        ]
    ],
    framework: 'mocha',
    watch: true,
    reporters: [
        [
            'allure',
            {
                outputDir: 'allure-results',
                disableWebdriverStepsReporting: true,
                disableWebdriverScreenshotsReporting: false
            }
        ]
    ],
    mochaOpts: {
        ui: 'bdd',
        timeout: 600000
    },
    afterTest: async function (test, context, { error, result, duration, passed, retries }) {
        if (error !== undefined) {
            await phone1.takeScreenshot();
        }
    }
};

收到此错误后,测试用例运行完全正常。我不明白为什么它显示为错误而不只是信息。

Error: info at Socket.<anonymous>

有人可以帮我解决这个错误吗?

更多信息: 这仅在安装项目后第一次发生,当我再次尝试时,效果很好。

webdriver-io appium-android
1个回答
0
投票

您遇到的错误似乎来自

onPrepare
挂钩期间的 Appium 服务。该钩子在所有工作程序启动之前执行一次,通常用于设置和配置测试环境。

在您的配置中,您正在使用带有

appium
包的 Appium 服务,并且 Appium 服务的初始化过程中似乎可能存在问题。您可以采取以下一些步骤来排查和解决问题:

  1. 检查Appium日志:

    • 运行测试时,检查 Appium 服务器生成的日志。日志可能会提供有关初始化期间任何问题的更详细信息。
    • 您可以提高配置中的日志级别以获得更详细的日志:
      logLevel: 'verbose', // or 'debug'
      
  2. 更新依赖项:

    • 确保您的所有依赖项(包括 Appium)都是最新的。您可以通过运行以下命令来执行此操作:
      npm update
      
  3. 重新安装Appium:

    • 全局卸载Appium并重新安装:
      npm uninstall -g appium
      npm install -g appium
      
  4. 检查配置:

    • 检查您的 Appium 配置并确保所有设置均正确,尤其是 APK 和其他功能的路径。
    • 验证 Appium 服务器是否使用指定端口 (4442) 正确启动。
  5. 重试:

    • 由于您提到该错误仅在安装项目后第一次发生,并且在后续尝试中运行良好,因此这可能是一个暂时性问题。
    • 尝试多次运行测试,看看问题是否仍然存在。
  6. 重建项目:

    • 如果问题仍然存在,请尝试清理并重建您的项目。可能存在一些初始设置或缓存问题。
  7. 检查网络和权限:

    • 确保不存在阻止 Appium 启动的网络问题。
    • 确保 Appium 具有访问所需端口和执行命令所需的权限。
  8. Appium医生:

    • 运行 Appium Doctor 检查是否有任何缺失的依赖项或配置问题:
      appium-doctor
      
  9. 社区支持:

    • 检查 Appium 和 WebDriverIO 社区,了解与您的特定版本相关的任何报告的问题或解决方案。

更改配置后请记住重新启动 Appium 服务器和测试执行环境。

如果问题仍然存在,提供 Appium 日志中的更多详细信息或任何其他错误消息将有助于进一步分析。

© www.soinside.com 2019 - 2024. All rights reserved.