使用 Appium 和 WebdriverIO 测试移动应用程序:“找不到 /session 的路线”

Tom*_*mas 15 android automated-tests appium webdriver-io react-native

我想建立Android和iOS平台(React Native)移动应用程序的自动化测试流程。为此,我使用AppiumWebdriverIO。作为示例,我使用现有的appium-boilerplate代码库和现成的应用程序来运行测试。我在Android 模拟器中运行该应用程序。基本设置如下所示。

1.阿皮姆

在此输入图像描述

在此输入图像描述

2.WebdriverIO

wdio.shared.conf.js

exports.config = {
    // ====================
    // Runner and framework
    // Configuration
    // ====================
    runner: 'local',
    framework: 'jasmine',
    jasmineNodeOpts: {
        // Updated the timeout to 30 seconds due to possible longer appium calls
        // When using XPATH
        defaultTimeoutInterval: 90000,
        helpers: [require.resolve('@babel/register')],
    },
    sync: true,
    logLevel: 'silent',
    deprecationWarnings: true,
    bail: 0,
    baseUrl: 'http://the-internet.herokuapp.com',
    waitforTimeout: 10000,
    connectionRetryTimeout: 90000,
    connectionRetryCount: 3,
    reporters: ['spec'],

    // ====================
    // Appium Configuration
    // ====================
    services: [
        [
            'appium',
            {
            // For options see
            // https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
                args: {
                    // Auto download ChromeDriver
                    relaxedSecurity: true,
                    // chromedriverAutodownload: true,
                    // For more arguments see
                    // https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
                },
                command: 'appium',
            },
        ],
    ],
    port: 4723,
};
Run Code Online (Sandbox Code Playgroud)

wdio.android.app.conf.js

const { join } = require('path');
const { config } = require('./wdio.shared.conf');

// ============
// Specs
// ============
config.specs = [
    './tests/specs/**/app*.spec.js',
];

// ============
// Capabilities
// ============
// For all capabilities please check
// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities
config.capabilities = [
    {
        // The defaults you need to have in your config
        platformName: 'Android',
        maxInstances: 1,
        // For W3C the appium capabilities need to have an extension prefix
        // http://appium.io/docs/en/writing-running-appium/caps/
        // This is `appium:` for all Appium Capabilities which can be found here
        'appium:udid': 'emulator-5554',
        'appium:deviceName': 'Android SDK build for x86_64',
        'appium:platformVersion': '10.0',
        'appium:orientation': 'PORTRAIT',
        // `automationName` will be mandatory, see
        // https://github.com/appium/appium/releases/tag/v1.13.0
        'appium:automationName': 'Appium',
        // The path to the app
        'appium:app': join(process.cwd(), './apps/Android-NativeDemoApp-0.2.1.apk'),
        // Read the reset strategies very well, they differ per platform, see
        // http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
        'appium:noReset': true,
        'appium:newCommandTimeout': 240,
    },
];

exports.config = config;
Run Code Online (Sandbox Code Playgroud)

3. 步骤

首先我打开 Android 模拟器并启动 Appium 服务器:

在此输入图像描述

在此输入图像描述

然后我使用命令来运行测试npm run android.app。之后,测试用例在后台执行,但模拟器中没有任何反应,并且在终端中我看到消息[HTTP] No route found for /session

在此输入图像描述

我的问题是:为了解决这个问题需要注意什么?因为我不知道该看什么以及如何正确设置配置。谢谢你!

fla*_*me3 31

我通过使用以下命令在终端中启动 Appium 服务器解决了这个问题:

appium --base-path /wd/hub 
Run Code Online (Sandbox Code Playgroud)

并在 Appium 检查器中使用此设置

并在 Appium 检查器中使用此设置

顺便说一句,如果您使用版本 >= 15 和 Appium 1.21 的 iOS 模拟器/设备,它可能仍然无法工作,因为它不支持 iOS 15。您必须安装较旧的 iOS 模拟器才能解决此问题。


Tem*_*olf 14

We were able to resolve this issue by overriding the path variable in the wdio.conf.js:

...
path: '/wd/hub',
port: 4723,
services: ['appium'],
...
Run Code Online (Sandbox Code Playgroud)

Without the path defined it apparently defaults to /session which fails with a 404 as you saw.


小智 0

啊,我确实修好了。我不知道为什么,但它适用于本地安装 Appium npm 包。