webdriverio / appium-boilerplate

Boilerplate project to run WebdriverIO tests with Appium to test native applications on iOS and Android
MIT License
453 stars 261 forks source link

I can't run local android test #124

Closed anggastika closed 2 years ago

anggastika commented 2 years ago

Hello, I have done :

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):

Please help and give me best practice to run test

Thank You

christian-bromann commented 2 years ago

Can you provide some logs that WebdriverIO generates?

anggastika commented 2 years ago

How to generate logs from WebdriverIO ? sorry I am newbie

@christian-bromann

wswebcreation commented 2 years ago

Hi @anggastika

There are a few things:

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

samaysimantbarik commented 2 years ago

Hi Team,

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

image

christian-bromann commented 2 years ago

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?

samaysimantbarik commented 2 years ago

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.

christian-bromann commented 2 years ago

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

samaysimantbarik commented 2 years ago

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

christian-bromann commented 2 years ago

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!

wswebcreation commented 2 years ago

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

christian-bromann commented 2 years ago

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

wswebcreation commented 2 years ago

It's in here @christian-bromann https://github.com/webdriverio/appium-boilerplate#automating-chrome-or-safari

christian-bromann commented 2 years ago

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?!

samaysimantbarik commented 2 years ago

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

wswebcreation commented 2 years ago

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)

samaysimantbarik commented 2 years ago

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.

wswebcreation commented 2 years ago

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:

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

muhammedInan commented 1 year ago

I'd like to reopen the ticket because I'm having the same problem, even though I've tried your solutions and the error persists.

exports.config = {

runner: 'local',

port: 4723,

specs: [
    './features/Android/*.feature'
],
exclude: [
    // 'path/to/excluded/files'
],

maxInstances: 10,

capabilities: [{
    'appium:acceptInsecureCerts': true,
    "appium:platformName": "Android",
    "appium:platformVersion": "10",
    "appium:deviceName": "deviceId",
    'appium:app': '...apk',
    'appium:appPackage': 'app',
    'appium:appActivity': 'Launch',
    'appium:automationName': 'UiAutomator2',
    'appium:language': 'en',
    'appium:locale': 'UK',
    'appium:newCommandTimeout': 240,
    'appium:fullReset': true,
    'appium:autoAcceptAlerts': true,
    'appium:autoGrantPermissions': true,
    'appium:deviceOrientation': 'portrait',
    'appium:unicodeKeyboard': true,
    'appium:resetKeyboard': true,
    'appium:ignoreHiddenApiPolicyError': true,
    'appium:fullContextList': true,
    'appium:networkSpeed': 'full',
    'appium:chromedriverExecutableDir': './node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/',
     'appium:chromeOptions': {
         args: [
             '--disable-popup-blocking',
             '--disable-notifications'
         ],
         'w3c': false
     },
}, ],

// Level of logging verbosity: trace | debug | info | warn | error | silent
logLevel: 'info',
//
// Set specific log levels per logger
// loggers:
// - webdriver, webdriverio
// - @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service
// - @wdio/mocha-framework, @wdio/jasmine-framework
// - @wdio/local-runner
// - @wdio/sumologic-reporter
// - @wdio/cli, @wdio/config, @wdio/utils
// Level of logging verbosity: trace | debug | info | warn | error | silent
// logLevels: {
//     webdriver: 'info',
//     '@wdio/appium-service': 'info'
// },

bail: 0,

baseUrl: 'http://localhost',

waitforTimeout: 12000,

connectionRetryTimeout: 120000,

connectionRetryCount: 3,

services: [
       [
       'appium',
       //'chromedriver',
        {
        command: "appium",
         args: {
           address: 'localhost',
           baseUrl: '/wd/hub',
           port: 4723,
           relaxedSecurity: true,
           log: "./appium.log",
        },

        },
],
],

//services: ['appium', 'chromedriver'],

// services: ['appium'], // Framework you want to run your specs with. // The following are supported: Mocha, Jasmine, and Cucumber // see also: https://webdriver.io/docs/frameworks // // Make sure you have the wdio adapter package for the specific framework installed // before running any tests. framework: 'cucumber',

// specFileRetries: 1,

// specFileRetriesDelay: 0,

reporters: ['spec'],

cucumberOpts: {
    // <string[]> (file/dir) require files before executing features
    require: ['./step-definitions/Android/*.js'],
    // <boolean> show full backtrace for errors
    backtrace: false,
    // <string[]> ('extension:module') require files with the given EXTENSION after requiring MODULE (repeatable)
    requireModule: [],
    dryRun: false,
    failFast: false,
    snippets: true,
    source: true,
    strict: false,
    tagExpression: '',
    timeout: 60000,
    ignoreUndefinedDefinitions: false
},
muhammedInan commented 1 year ago

the error in question

ERROR webdriver: RequestError: connect ECONNREFUSED 127.0.0.1:4723 [0-0] at ClientRequest. (file:///Users/qaicf/kara-automation/node_modules/got/dist/source/core/index.js:790:107) [0-0] at Object.onceWrapper (node:events:626:26) [0-0] at ClientRequest.emit (node:events:523:35) [0-0] at ClientRequest.emit (node:domain:489:12) [0-0] at Socket.socketErrorListener (node:_http_client:495:9) [0-0] at Socket.emit (node:events:511:28) [0-0] at Socket.emit (node:domain:489:12) [0-0] at emitErrorNT (node:internal/streams/destroy:151:8) [0-0] at emitErrorCloseNT (node:internal/streams/destroy:116:3) [0-0] at processTicksAndRejections (node:internal/process/task_queues:82:21) [0-0] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1574:16) [0-0] 2023-07-04T14:08:26.384Z ERROR @wdio/runner: Error: Failed to create session. [0-0] Unable to connect to "http://127.0.0.1:4723/", make sure browser driver is running on that address. [0-0] If you use services like chromedriver see initialiseServices logs above or in wdio.log file as the service might had problems to start the driver.