【问题标题】:Testing Mobile App with Appium & WebdriverIO: "No route found for /session"使用 Appium 和 WebdriverIO 测试移动应用程序:“找不到 /session 的路由”
【发布时间】:2021-07-31 04:06:50
【问题描述】:

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

1. Appium

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,
};

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;

3.步骤

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

然后我使用命令运行测试npm run android.app。之后,测试用例在后台执行,但模拟器中什么也没有发生,在终端中我看到了消息[HTTP] No route found for /session

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

【问题讨论】:

  • 也许你应该尝试在配置中设置路径变量?

标签: android react-native automated-tests appium webdriver-io


【解决方案1】:

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

appium --base-path /wd/hub 

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

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

【讨论】:

    【解决方案2】:

    我们能够通过覆盖 wdio.conf.js 中的 path 变量来解决此问题:

    ...
    path: '/wd/hub',
    port: 4723,
    services: ['appium'],
    ...
    

    如果没有定义路径,它显然默认为/session,如您所见,它会以 404 失败。

    【讨论】:

    • 如果来自github.com/webdriverio/appium-boilerplate 或类似设置,您可以通过不启动您自己的服务器来避免此问题,如下面的 Matheus 回答中所述。
    • @nicholascm 这是一个公平的观点。话虽如此,如果您想让它连接到预运行的 appium 服务器,这是必要的(afaik)。
    【解决方案3】:

    不要单独运行 appium 服务器。

    直接使用 webdriver 命令运行测试。

    安卓示例:npm run android.app

    【讨论】:

    • 对于很多人来说,这可能是问题所在。从 appium-boilerplate 开始,您可以通过修改路径并按照接受的答案中所述启动您自己的 appium 服务器来破解它,但是,如果您让上面的命令启动服务器,它“就可以工作”。跨度>
    【解决方案4】:

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

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 2014-12-03
      • 1970-01-01
      • 2021-10-11
      • 2021-11-27
      • 2017-05-14
      • 2021-09-07
      • 2019-12-07
      • 2019-11-16
      相关资源
      最近更新 更多