Testing Mobile App with Appium & WebdriverIO: "No route found for /session"
Asked Answered
A

4

15

I want to set up the process of automated testing of mobile applications for Android and iOS platforms (React Native) . For this I use Appium and WebdriverIO. As an example, I am using existing appium-boilerplate codebase and a ready-made application for running tests. I run the application in the Android emulator. Basic settings are presented below.

1. Appium

enter image description here

enter image description here

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. Steps

First I open Android emulator and start the Appium server:

enter image description here

enter image description here

Then I use the command to run the tests npm run android.app. After that, the test cases are executed in the background, but nothing happens in the emulator and in the terminal I see the message [HTTP] No route found for /session

enter image description here

My question is: what do need to pay attention to in order to fix this? Because I don't know what to look at and how to set up the configuration correctly. Thank you!

Afrika answered 9/5, 2021 at 14:28 Comment(1)
Maybe you should try to set the path variable in config?Snappish
K
33

I got rid of the problem by using this command to start Appium server in the terminal:

appium --base-path /wd/hub 

And use this setting in the Appium inspector

And use this setting in the Appium inspector

By the way, it might still not work if you use iOS simulator/device with version >= 15 with Appium 1.21 because that doesn't support iOS 15. You have to install an older iOS simulator to solve it.

Kimbro answered 28/10, 2021 at 14:36 Comment(1)
This is mentioned in the Appium Inspector github project readme as well (see: github.com/appium/appium-inspector#important-migration-notes). "[..] If you're using Appium Inspector with an Appium 1.x server, you'll likely need to update the path information in the New Session form back to /wd/hub.[..]"Endless
F
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'],
...

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

Fuzz answered 18/8, 2021 at 16:45 Comment(2)
If coming from github.com/webdriverio/appium-boilerplate or similar setups you can avoid this issue by not starting your own server as stated below in Matheus's answer.Goodhumored
@Goodhumored that's a fair point. That being said, this is necessary (afaik) if you want to have it connect to a pre-running appium server.Fuzz
J
4

Do not run appium server alone.

use directly the webdriver command to run the tests.

Example for android: npm run android.app

Jonna answered 6/7, 2021 at 14:25 Comment(1)
For a lot of people this is probably the issue. Going from the appium-boilerplate, you can hack it to work above by modifying the path and starting your own appium server as stated in the accepted answer, however, it "just works" if you let the command above start the server.Goodhumored
F
0

Ah, I did fixed it. I don't know why, but it works with locally install Appium npm package.

Flapper answered 28/6, 2021 at 21:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.