webdriverio/appium-boilerplate

I can't run local android test

anggastika opened this issue · 19 comments

Hello,
I have done :

  • clone repo (master branch)
  • put Android-NativeDemoApp-0.4.0.apk on folder ./apps
  • run npm install
  • trial run "npm run android.app"

But :
Screen Shot 2022-03-11 at 14 54 34

This is My wdio.android.app.conf.ts

import { join } from 'path';
import config from './wdio.shared.local.appium.conf';

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

// ============
// 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:deviceName': 'device',
        //'appium:udid' : 'emulator-5554',
        'appium:platformVersion': '11.0',
        'appium:orientation': 'PORTRAIT',
        'appium:automationName': 'UiAutomator2',
        // The path to the app
        'appium:app': join(process.cwd(), './apps/Android-NativeDemoApp-0.4.0.apk'),
        // @ts-ignore
        'appium:appWaitActivity': 'com.wdiodemoapp.MainActivity',
        // 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;

Environment (please complete the following information):

  • Node.js version: [17.6.0]
  • NPM version: [8.5.1]
  • Platform: [Android]
  • Platform version: [11.0]
  • Appium Desktop version : [1.22.x]
  • Emulator/Simulator/Real Device: [Emulator]

Please help and give me best practice to run test

Thank You

Can you provide some logs that WebdriverIO generates?

How to generate logs from WebdriverIO ? sorry I am newbie

@christian-bromann

Hi @anggastika

There are a few things:

  • You are using NodeJS 17, can you revert back to NodeJS 16, there seems to be an issue with Appium and NodeJS 17, see also #122
  • You can run tests with debug logs by altering the logLevel in your main config-file to logLevel: 'debug', this will produce more logs in the console.
  • Best thing to do is not to run all tests, but a single test to see what's happening, you can do that by or altering this piece of code
config.specs = [
   // From
   // './tests/specs/**/app*.spec.ts',
   // to
   './tests/specs/**/app.login.spec.ts',
];

or by using npm run android.app -- --spec=./test/specs/app.login.spec.ts

Based on the three things above you should be able to or run your tests, or be able to provide some logs.

Hope this helps

Hi Team,

I am facing the same problem as well. My node version is 16*

image

I am facing the same problem as well. My node version is 16*

Have you looked into the wdio logs what the issue could be?

Hi @christian-bromann ,

Now it's running. I ran the appium server locally and all good now. may be the appium-service isn't able to spin up the server.
Had to add this line :
image

However, I am interested to know how the context switching works as I am facing similar issue on my repo, unfortunately this repo is also giving me the same error.
image

Wondering if this works on your system.

Maybe Appium expects Chromedriver to be available in your $PATH or the Chromedriver you have has an invalid version.

Okay, That may be the thing. In that case, could you update the Readme with this info.

could you update the Readme with this info

Well I am not quite sure which scenario applies here. If you know please go ahead and raise a PR with a docs fix. Thank you!

There are two things here @samaysimantbarik
You added a basePath option in your config, that is not needed because WDIO and the Appium service start with basePath / instead of /wd/hub
Secondly, Appium comes with the latest version of ChromeDriver, but your devices/emulator could have an older version of Chrome (Chrome and ChromeDriver versions are tied together). Appium can automatically determine the version of ChromeDriver it needs to have and also download it for you if you let is automatically download it for you, that's why you need to start the Appium Server with relaxedSecurity: true

I'ld suggest to create a FAQ document and document these issues with their solutions, then we can close this issue.

There is no information about this relaxedSecurity thingy. Again, thinking about how we can close the issue I thought maybe we create a FAQ and document some of these problem solutions. Maybe folks will stumble upon this through Google. I just wonder what's left for us to do here?!

Hi @wswebcreation ,

Thanks for your response. I am using the latest version of everything( Appium, emulator and chrome).
Still, if I don't explicitly install chromedriver and specify the path, my tests are failing, even with relaxed security.

My service definition:
image

Desired caps:
image

If I remove the chromeDriverExecutablePath, then I get the error, "No chromedriver ..... " .

Can you run the current master against latest appium and emulators(chrome 101) and check if you aren't getting any errors.

Thanks,
Samay

Hi @samaysimantbarik

Can you run your test with

config.services = (config.services ? config.services : []).concat([
    [
        "appium",
        {
            // This will use the globally installed version of Appium
            command: "appium",
            args: {
                // This is needed to tell Appium that we can execute local ADB commands
                // and to automatically download the latest version of ChromeDriver
                relaxedSecurity: true,
                address: "localhost",
                log: "./appium.log",
            },
        },
    ],
]);

and share the appium.log file in a Gist. I want to see what is happening there because it works on my machine (sorry to say that)

Hi @wswebcreation ,

Thanks heaps.

The above works like a charm.

A quick question: Do we have a generic way that works on existing and new appium server ?

The above snippet spins up an appium server and works great for execution.

However, if I want to use Appium inspector and for that I need to use the local appium desktop server, this setup complains.

Log:
2022-05-23 03:22:20:826 [Appium] Welcome to Appium v1.22.3 2022-05-23 03:22:20:827 [Appium] Non-default server args: 2022-05-23 03:22:20:827 [Appium] address: localhost 2022-05-23 03:22:20:827 [Appium] basePath: / 2022-05-23 03:22:20:828 [Appium] logFile: ./appium.log 2022-05-23 03:22:20:828 [Appium] relaxedSecurityEnabled: true 2022-05-23 03:22:20:852 [HTTP] Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.

Hi @samaysimantbarik

Thanks for your response, but what did you change to make it work now? Your code and my code look the same, except for the log-property.

The new Appium Inspector uses a different basePath then a normal Appium server (Appium 1.x versions) would spin up. By default Appium Server uses /wd/hub/, but it needs to be /.
If you've installed Appium globally then you can then start a server with this

appium --base / --relaxed-security --log-timestamp

Where:

  • appium is the start-server command
  • --base / tells Appium to use / instead of the default /wd/hub basePath
  • --relaxed-security means to automatically download the ChromeDriver (amongst other things, see this)
  • --log-timestamp adds a nice timestamp to the logs

Running this will give this give the following logs

appium --base / --relaxed-security --log-timestamp
2022-05-23 05:17:02:697 - [Appium] Welcome to Appium v1.22.3
2022-05-23 05:17:02:699 - [Appium] Non-default server args:
2022-05-23 05:17:02:699 - [Appium]   basePath: /
2022-05-23 05:17:02:700 - [Appium]   logTimestamp: true
2022-05-23 05:17:02:700 - [Appium]   relaxedSecurityEnabled: true
2022-05-23 05:17:02:725 - [Appium] Appium REST http interface listener started on 0.0.0.0:4723

As you can see it will automatically start on port 4723, also the port that Appium Inspector uses.

I'm going to close this issue now because this is not related to this boilerplate anymore, but it's still open for conversation