ofindley / appium-webdriverio

This is a Appium project with webdriverIO by Orane Findley. This project is accompanied by a video course.
22 stars 31 forks source link

ERROR wdio unable to create session #1

Open TamTamThomas opened 4 years ago

TamTamThomas commented 4 years ago

Hi,

error message is the below: ERROR webdriver: session not created: Unable to create session from { "desiredCapabilities": { "platformName": "Android", "appium:deviceName": "Pixel", "appium:app": ".\u002fUsers\u002fzsolt\u002fappium_js\u002fApiDemos-debug.apk"

However in wdio.conf.js the below is set: capabilities: [{ platformName: 'Android', 'appium:deviceName': 'Pixel', 'appium:app': './Users/zsolt/appium_js/ApiDemos-debug.apk' }],

What could be the problem? I have tried different paths, copied your wdio.conf.js file, read articles but could not figure out the root of this problem. Appium-doctor does not show any missing mandatory dependencies. Android SDK path is set, JAVA HOME path is set.

wdio.config.js:

//let {join} = require('path'); exports.config = { // // ==================== // Runner Configuration // ==================== // // WebdriverIO allows it to run your tests in arbitrary locations (e.g. locally or // on a remote machine). runner: 'local', port: 4723, services: ['appium'], // // ================== // Specify Test Files // ================== // Define which test specs should run. The pattern is relative to the directory // from which wdio was called. Notice that, if you are calling wdio from an // NPM script (see https://docs.npmjs.com/cli/run-script) then the current working // directory is where your package.json resides, so wdio will be called from there. // specs: [ './test/specs/*/.js' ], // Patterns to exclude. exclude: [ // 'path/to/excluded/files' ], // // ============ // Capabilities // ============ // Define your capabilities here. WebdriverIO can run multiple capabilities at the same // time. Depending on the number of capabilities, WebdriverIO launches several test // sessions. Within your capabilities you can overwrite the spec and exclude options in // order to group specific specs to a specific capability. // // First, you can define how many instances should be started at the same time. Let's // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec // files and you set maxInstances to 10, all spec files will get tested at the same time // and 30 processes will get spawned. The property handles how many capabilities // from the same test should run tests. // maxInstances: 1, // // If you have trouble getting all important capabilities together, check out the // Sauce Labs platform configurator - a great tool to configure your capabilities: // https://docs.saucelabs.com/reference/platforms-configurator // capabilities: [{ platformName: 'Android', 'appium:deviceName': 'Pixel', 'appium:app': './Users/zsolt/appium_js/ApiDemos-debug.apk' }], // // =================== // Test Configurations // =================== // Define all options that are relevant for the WebdriverIO instance here // // Level of logging verbosity: trace | debug | info | warn | error | silent logLevel: 'error', // // Set specific log levels per logger // loggers: // - webdriver, webdriverio // - @wdio/applitools-service, @wdio/browserstack-service, @wdio/devtools-service, @wdio/sauce-service // - @wdio/mocha-framework, @wdio/jasmine-framework // - @wdio/local-runner, @wdio/lambda-runner // - @wdio/sumologic-reporter // - @wdio/cli, @wdio/config, @wdio/sync, @wdio/utils // Level of logging verbosity: trace | debug | info | warn | error | silent // logLevels: { // webdriver: 'info', // '@wdio/applitools-service': 'info' // }, // // If you only want to run your tests until a specific amount of tests have failed use // bail (default is 0 - don't bail, run all tests). bail: 0, // // Set a base URL in order to shorten url command calls. If your url parameter starts // with /, the base url gets prepended, not including the path portion of your baseUrl. // If your url parameter starts without a scheme or / (like some/path), the base url // gets prepended directly. baseUrl: 'http://localhost', // // Default timeout for all waitFor* commands. waitforTimeout: 10000, // // Default timeout in milliseconds for request // if Selenium Grid doesn't send response connectionRetryTimeout: 90000, // // Default request retries count connectionRetryCount: 3, // // Test runner services // Services take over a specific job you don't want to take care of. They enhance // your test setup with almost no effort. Unlike plugins, they don't add new // commands. Instead, they hook themselves up into the test process. services: ['selenium-standalone'],

// Framework you want to run your specs with.
// The following are supported: Mocha, Jasmine, and Cucumber
// see also: https://webdriver.io/docs/frameworks.html
//
// Make sure you have the wdio adapter package for the specific framework installed
// before running any tests.
framework: 'mocha',
//
// The number of times to retry the entire specfile when it fails as a whole
// specFileRetries: 1,
//
// Test reporter for stdout.
// The only one supported by default is 'dot'
// see also: https://webdriver.io/docs/dot-reporter.html
reporters: ['spec'],

//
// Options to be passed to Mocha.
// See the full list at http://mochajs.org/
mochaOpts: {
    ui: 'bdd',
    timeout: 60000
},
//
// =====
// Hooks
// =====
// WebdriverIO provides several hooks you can use to interfere with the test process in order to enhance
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
/**
 * Gets executed once before all workers get launched.
 * @param {Object} config wdio configuration object
 * @param {Array.<Object>} capabilities list of capabilities details
 */
// onPrepare: function (config, capabilities) {
// },
/**
 * Gets executed just before initialising the webdriver session and test framework. It allows you
 * to manipulate configurations depending on the capability or spec.
 * @param {Object} config wdio configuration object
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {Array.<String>} specs List of spec file paths that are to be run
 */
// beforeSession: function (config, capabilities, specs) {
// },
/**
 * Gets executed before test execution begins. At this point you can access to all global
 * variables like `browser`. It is the perfect place to define custom commands.
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {Array.<String>} specs List of spec file paths that are to be run
 */
// before: function (capabilities, specs) {
// },
/**
 * Runs before a WebdriverIO command gets executed.
 * @param {String} commandName hook command name
 * @param {Array} args arguments that command would receive
 */
// beforeCommand: function (commandName, args) {
// },
/**
 * Hook that gets executed before the suite starts
 * @param {Object} suite suite details
 */
// beforeSuite: function (suite) {
// },
/**
 * Function to be executed before a test (in Mocha/Jasmine) starts.
 */
// beforeTest: function (test, context) {
// },
/**
 * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
 * beforeEach in Mocha)
 */
// beforeHook: function (test, context) {
// },
/**
 * Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
 * afterEach in Mocha)
 */
// afterHook: function (test, context, { error, result, duration, passed, retries }) {
// },
/**
 * Function to be executed after a test (in Mocha/Jasmine).
 */
// afterTest: function(test, context, { error, result, duration, passed, retries }) {
// },

/**
 * Hook that gets executed after the suite has ended
 * @param {Object} suite suite details
 */
// afterSuite: function (suite) {
// },
/**
 * Runs after a WebdriverIO command gets executed
 * @param {String} commandName hook command name
 * @param {Array} args arguments that command would receive
 * @param {Number} result 0 - command success, 1 - command error
 * @param {Object} error error object if any
 */
// afterCommand: function (commandName, args, result, error) {
// },
/**
 * Gets executed after all tests are done. You still have access to all global variables from
 * the test.
 * @param {Number} result 0 - test pass, 1 - test fail
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {Array.<String>} specs List of spec file paths that ran
 */
// after: function (result, capabilities, specs) {
// },
/**
 * Gets executed right after terminating the webdriver session.
 * @param {Object} config wdio configuration object
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {Array.<String>} specs List of spec file paths that ran
 */
// afterSession: function (config, capabilities, specs) {
// },
/**
 * Gets executed after all workers got shut down and the process is about to exit. An error
 * thrown in the onComplete hook will result in the test run failing.
 * @param {Object} exitCode 0 - success, 1 - fail
 * @param {Object} config wdio configuration object
 * @param {Array.<Object>} capabilities list of capabilities details
 * @param {<Object>} results object containing test results
 */
// onComplete: function(exitCode, config, capabilities, results) {
// },
/**
* Gets executed when a refresh happens.
* @param {String} oldSessionId session ID of the old session
* @param {String} newSessionId session ID of the new session
*/
//onReload: function(oldSessionId, newSessionId) {
//}

}

package.json:

{ "name": "appium_js", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "./node_modules/.bin/wdio wdio.conf.js" }, "author": "Thomas Szabo", "license": "ISC", "dependencies": {}, "devDependencies": { "@wdio/appium-service": "^6.1.0", "@wdio/cli": "^6.1.7", "@wdio/local-runner": "^6.1.7", "@wdio/mocha-framework": "^6.1.6", "@wdio/selenium-standalone-service": "^6.0.16", "@wdio/spec-reporter": "^6.1.5", "@wdio/sync": "^6.1.7", "appium": "^1.17.0", "chai": "^4.2.0" } }

sample.test.js:

describe('Sample', () => { it('Test', () => {

})

})

Thank you for any help on this.

Tom

sumanth-dnbk commented 4 years ago

facing the same issue.

the package version of @wdio/cli in this repo is ^5.16.10 (v5) , this is working correctly but the latest version of @wdio/cli is 6.1.24 (v6) , issue starts occurring

I guess there are some breaking changes between the versions

sumanth-dnbk commented 4 years ago

by default wdio client expects the server to be on 4444 port, but if we want to configure we need to add port in the capabilities section .

So either start the appium sever on 4444 with out specifying any port number on wdio.conf.js or specify port property to be the port number on which appium server is running on

capabilities: [{ port: 4723, platformName: 'Android', 'appium:deviceName': 'Pixel 3a', 'appium:app': './Users/xyz/appium_js/ApiDemos-debug.apk' }],

I also had to install chai in my case.

This changes got my test cases working hope this helps @TamTamThomas

Thiago-Viotto commented 3 years ago

@sumanth-dnbk Worked for me adding port: 4723 in capabalities too. Thanks!

lopocode commented 3 years ago

If you guys were still having issues with running this after updating the port number. Check "Edit Configuration" setting in appium to make sure that "JAVA_HOME" and "ANDROID_HOME" data are present. You can find a guys to getting your JAVA and ANDROID locations on your local machine here and here

Vinto commented 2 years ago

I added path to the config and port in the capabilities:

let { join } = require('path');
exports.config = {
//
//
path: '/wd/hub/',

capabilities: [{
        port: 4723,
        platformName: 'Android',
        'appium:deviceName': 'Pixel 2 API 28',
        'appium:app': join(process.cwd(), './ApiDemos-debug.apk')
}],
//
//
}