rhysd / wdio-appium-service

No longer need to launch Appium manually for Webdriver.io
MIT License
9 stars 8 forks source link

Got Fatal error: spawn appium ENOENT for appium as service integrated #2

Open techyguy78 opened 7 years ago

techyguy78 commented 7 years ago

Hi Christian,

As we discussed earlier, I'm trying to execute appium as integrated service and got the fatal error, "Fatal error: spawn appium ENOENT"

Below is the configuration wdio.conf.js: browserName: 'safari', deviceName: 'iPhone Simulator', appiumVersion: '1.5.3', platformName: 'iOS', port:'4723', //app: "safari", platformversion: '9.1', deviceOrientation:'portriat'

     services: ['sauce','appium'],

package.json: "wdio-appium-service": "^0.2.0",

rhysd commented 7 years ago

Where global or local do you install appium command?

techyguy78 commented 7 years ago

Hi, Good morning !

First attempt I did it with local and second attempt i did it with global

rhysd commented 7 years ago

First and second, which one failed? or both? It seems that it failed to find appium command at initialization. And please let me know your OS and Node.js version. It's important to reproduce an issue.

techyguy78 commented 7 years ago

cleaned everything and started fresh. I have, appium version 1.6.0 MAC OS Version 10.11.6 node: v6.6.0

sudo npm install -g wdio-appium-service --save-dev /usr/local/lib ├── UNMET PEER DEPENDENCY appium@>=1.4 └── wdio-appium-service@0.2.2

npm WARN wdio-appium-service@0.2.2 requires a peer of appium@>=1.4 but none was installed.

I see appium integrated service require v1.4 but I have v1.6

rhysd commented 7 years ago

It means version >= 1.4 so v1.6 is OK. If you installed appium in global, please ignore unmet peer dependency. It's not related to this problem and it should work well. Is appium command in your $PATH? Can you try appium command from command line?

techyguy78 commented 7 years ago

yes, appium command works fine from commandline

$appium --show-ios-log

[Appium] Welcome to Appium v1.6.0 [Appium] Non-default server args: [Appium] showIOSLog: true [Appium] Deprecated server args: [Appium] --show-ios-log => --default-capabilities '{"showIOSLog":true}' [Appium] Default capabilities, which will be added to each request unless overridden by desired capabilities: [Appium] showIOSLog: true [Appium] Appium REST http interface listener started on 0.0.0.0:4723

Problem when I ran appium as integrated service with below config, browserName: 'safari', deviceName: 'iPhone Simulator', appiumVersion: '1.5.3', platformName: 'iOS', port:'4723', platformversion: '9.1', deviceOrientation:'portriat'

services: ['sauce','appium'],

I got the error as

ERROR: Couldn't connect to selenium server iphonesimulator.ios Error: Couldn't connect to selenium server

rhysd commented 7 years ago

Hmm, so appium command exists but child_process.spawn('appium') causes ENOENT. weird...

techyguy78 commented 7 years ago

Yes Rhysd, Any clue for me to move forward ?

techyguy78 commented 7 years ago

A service failed in the 'onPrepare' hook Error: Appium exited before timeout (Exit code: 1) at ChildProcess.exitCallback (/Users/node_modules/wdio-appium-service/build/launcher.js:91:28) at ChildProcess.g (events.js:291:16) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

Continue...

ERROR: Couldn't connect to selenium server iphonesimulator.ios.safari

Error: Couldn't connect to selenium server

[iPhone Simulator iOS undefined #0a] Session ID: undefined [iPhone Simulator iOS undefined #0a] Spec: /Users/PageTest.js [iPhone Simulator iOS undefined #0a] Running: iPhone Simulator on iOS undefined executing safari [iPhone Simulator iOS undefined #0a] [iPhone Simulator iOS undefined #0a] [iPhone Simulator iOS undefined #0a] [iPhone Simulator iOS undefined #0a] Check out job at https://saucelabs.com/tests/undefined [iPhone Simulator iOS undefined #0a]

rhysd commented 7 years ago

Could you check you can execute your script in local before in SauceLabs? I guess it's related to SauceLabs but I've not try yet...

techyguy78 commented 7 years ago

okay let me try now

techyguy78 commented 7 years ago

Started appium server:

appium [Appium] Welcome to Appium v1.6.0 [Appium] Appium REST http interface listener started on 0.0.0.0:4723

When I run the test in local got the below error in console,

ERROR: Couldn't connect to selenium server iphonesimulator.ios.safari Error: Couldn't connect to selenium server

error in local server:

HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"deviceName":"iPhone Simulator","appiumVersion":"1.6.0","platformName":"iOS","app":"safari","platformversion":"9.1","deviceOrientation":"portriat","requestOrigins":{"url":"http://webdriver.io","version":"4.2.16","name":"webdriverio"}}} [MJSONWP] Calling AppiumDriver.createSession() with args: [{"javascriptEnabled":true,... [Appium] Creating new IosDriver session [Appium] Capabilities: [Appium] javascriptEnabled: true [Appium] locationContextEnabled: true [Appium] handlesAlerts: true [Appium] rotatable: true [Appium] deviceName: 'iPhone Simulator' [Appium] appiumVersion: '1.6.0' [Appium] platformName: 'iOS' [Appium] app: 'safari' [Appium] platformversion: '9.1' [Appium] deviceOrientation: 'portriat' [Appium] requestOrigins: { url: 'http://webdriver.io', version: '4.2.16', name: 'webdriverio' } [BaseDriver] The following capabilities were provided, but are not recognized by appium: javascriptEnabled, locationContextEnabled, handlesAlerts, rotatable, appiumVersion, platformversion, deviceOrientation, requestOrigins. [BaseDriver] Session created with session id: 26535aea-211e-4b69-8fff-f50f3f6dae5e [debug] [iOS] Xcode version set to 8.0 [iOS] SessionNotCreatedError: A new session could not be created. Details: Appium's IosDriver does not support xcode version 8.0. Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead. at IosDriver.createSession$ (lib/driver.js:120:28) at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40) at GeneratorFunctionPrototype.invoke as _invoke at GeneratorFunctionPrototype.prototype.(anonymous function) as next at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37) at process._tickCallback (internal/process/next_tick.js:103:7) { SessionNotCreatedError: A new session could not be created. Details: Appium's IosDriver does not support xcode version 8.0. Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead. at IosDriver.createSession$ (lib/driver.js:120:28) at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40) at GeneratorFunctionPrototype.invoke as _invoke at GeneratorFunctionPrototype.prototype.(anonymous function) as next at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37) at process._tickCallback (internal/process/next_tick.js:103:7) jsonwpCode: 33 }

my wdio.conf:

host: 'localhost', port:4723, capabilities: [ { //browserName: 'safari', deviceName: 'iPhone Simulator', appiumVersion: '1.6.0', platformName: 'iOS', app: "safari", platformversion: '9.1', deviceOrientation:'portriat' } ],

rhysd commented 7 years ago

Thank you for the detail. The 'Couldn't connect to the session' error often occur due to failing to start appium server. Then I found that you need to add appium configuration to your wdio.conf.

Please refer test configuration.

https://github.com/rhysd/wdio-appium-service/blob/master/test/integration/wdio.conf.js#L70

techyguy78 commented 7 years ago

Thank you, I have added appium configuration and executed the script. Got the below error in console,

ERROR: A new session could not be created. Details: Appium's IosDriver does not support xcode version 8.0. Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead. iphonesimulator.ios.safari

rhysd commented 7 years ago

The error derives from your XCode environment. But I wonder Appium v1.6 supports XCode 8...

rhysd commented 7 years ago

Did you also install Appium v1.5 somewhere in your system? wdio-appium-service may wrongly find the v1.5 appium executable.

techyguy78 commented 7 years ago

I have only v1.6, not sure how its referring v1.5 ?

lj9142 commented 7 years ago

Hello @rhysd , I am using the cucumber framework and i am also getting this error, i only have v1.6 on my computer and i have added all the things you suggested but i am trying to set this up for an android emulator on windows rather than iOS. Is there anything else you can suggest for resolving this issue?

lj9142 commented 7 years ago

This is the error i am getting: image

And here are the details from my config file: image

rahulmr commented 7 years ago

I am facing the same issue. Is it because I have appium@1.5.3 installed globally? Does wdio-appium-service supports only appium@1.6.3 ?

I am really stuck because of this. Any bypass?

rahulmr commented 7 years ago

Still same issue with appium@1.6.3 when installed locally as well as globally.

rahulmr commented 7 years ago

Hello All, Any updates on this?

rahulmr commented 7 years ago

Updates: [Resolved] ::

I was able to resolve this issue on my windows 7 machine by making some changes in the wdio.conf.js file.

Here are the things to be done:

  1. Add host and port entries in exports.config and they should match the appium server args.

    exports.config = {
    
    host: '127.0.0.1',
    port: 4723,
    ...
    }
  2. Add capabilities as below
    exports.config = {
    ...
    ...
    maxInstances: 1,
    capabilities: [
    {
            browserName: '',
            appiumVersion: '1.6.3',
            avd: 'AVDTest',
            deviceName: 'Android Emulator',
            platformVersion: '6.0',
            platformName: 'android',
            app: 'https://github.com/appium/sample-code/blob/master/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk?raw=true',
            waitforTimeout: 30000,
            commandTimeout: 30000
        }
    ],
    ...
    }
  3. Add proper appium server args like below
    exports.config = {
    ...
    ...
    services: ['appium'],
    appium: {
        waitStartTime: 6000,
        command: 'appium.cmd',
        logFileName: 'appium163.log',
        args: {
            address: '127.0.0.1',
            port: 4723,
            commandTimeout: '7200',
            sessionOverride: true,
            debugLogSpacing: true
        }
    },
    ...
    }

This way I was able to resolve the issue. appium does not work on windows, the command should be appium.cmd. I install appium locally using npm install appium@1.6.3 --save . Note: you need latest node version and npm version should at least 4.0.5 to install appium@1.6.3

Just in case, someone needs, so added the above details. It seems that wdio-appium-service was only or majorly tested on mac or may be Linux. Thanks

lavanyamercy commented 7 years ago

Github project where I tried: https://github.com/lavanyamercy/wdioAppium

1) I have followed the above wdio.conf.js. exports.config = { host: '127.0.0.1', port: 4723,

capabilities: [{ browserName: 'chrome', appiumVersion: '1.6.3', deviceName: 'Samsung Galaxy S7 Device', deviceOrientation: 'portrait', platformName: 'Android' }],

services: ['appium'], appium: { waitStartTime: 6000, command: 'appium', logFileName: 'appium163.log', args: { address: '127.0.0.1', port: 4997, debugLogSpacing: true } } 2) I'm using mac and following are the versions: "wdio-appium-service": "0.2.3", "webdriverio": "4.6.2" globally installed appium of version1.6.3

3) command used: npm run _wdio still getting the following error: A service failed in the 'onPrepare' hook Error: Appium exited before timeout (Exit code: 1) at ChildProcess.exitCallback (/Users/lmani/Documents/appiumtest/node_modules/wdio-appium-service/build/launcher.js:94:28) at ChildProcess.g (events.js:291:16) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

Continue... ERROR: Couldn't connect to selenium server samsunggalaxys7device.android Error: Couldn't connect to selenium server

Can you help what am I missing?

rahulmr commented 7 years ago

@lavanyamercy as mentioned if you are on windows, command should be appium.cmd and it is better to install in local workspace npm install appium Also, port number should be same 4723 , I see that you are using different ports.

rahulmr commented 7 years ago

@lavanyamercy one more tip appium takes lot of time to start a server for the first time in a local workspace. So, you might have to put sleep in onPrepare

lavanyamercy commented 7 years ago

Thank you, it worked.

One more issue I'm facing is MJSONWP] Encountered internal error running command: Error: session not created exception from unknown error: failed to close UI debuggers (Session info: chrome=56.0.2924.87)

(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.11.6 x86_64) at Chromedriver.callee$2$0$ (../../lib/chromedriver.js:177:15)

Attaching the screenshot. image

Can you help fixing this one.

rahulmr commented 7 years ago

Can you update your repository with your latest code with the fix I mentioned? Also, check whether drivers are downloaded properly and use the latest versions. What OS you are using Mac or Windows?

ptthuong commented 7 years ago

@rahulmr I used your solution on Windows, Appium was able to start successfully. But appium process cannot be killed after running, so the following error is logged when I run test 2nd time. =Appium log= [Appium] Welcome to Appium v1.6.3 (REV 21b764179cdb46e763d8182fa4e4a89e5295974a) [Appium] Non-default server args: [Appium] address: '127.0.0.1' [Appium] sessionOverride: true [Appium] debugLogSpacing: true [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. Error: listen EADDRINUSE 127.0.0.1:4723 at Object.exports._errnoException (util.js:1022:11) at exports._exceptionWithHostPort (util.js:1045:20) at Server._listen2 (net.js:1259:14) at listen (net.js:1295:10) at net.js:1405:9 at _combinedTickCallback (internal/process/next_tick.js:77:11) at process._tickCallback (internal/process/next_tick.js:98:9)

I guess onComplete () in wdio-appium-service doesn't work. Can you help me with this issue?

rahulmr commented 7 years ago

@ptthuong yup same issue with me here. I had to create my own script to kill process with PID and put it in onComplete of wdio.conf.js file but better solution was to create a separate task in package.json. I have created stop.js file and am using node-netstat (here) to determine PID of the process using port 4723.

ptthuong commented 7 years ago

@rahulmr Thanks, I will try this

aaronbriel commented 7 years ago

Hi everybody, I've written an npm module that starts and stops appium programmatically on windows or mac. It addresses the issues discussed in this thread, including the timing issue. It's called appium-controller....

rahulmr commented 7 years ago

@aaronbriel how are we going to use this in wdio as a service? Any example could be beneficial. I saw one good plugin like wdio-chromedriver-service here

aaronbriel commented 7 years ago

@rahulmr I'll have to build that out. I posted here just to help out if the service wasn't working for people. For example, one approach is an npm script in package.json like: "appium-controller --start && wdio && appium-controller --stop".

sumeetp4 commented 6 years ago

Hi @rahulmr , I followed the same steps as you mentioned. Just that I have latest appium 1.7.2 installed.

I am getting same error error

Here is my config file exports.config = { host:'127.0.0.1', port: 4723, .... .. maxInstances: 1,

capabilities: [
    {
      appiumVersion: '1.7.2',
      platformName: 'Android',
        platformVersion: '6.0.1',
        appPackage: 'com.disney.wdw.android',
        appActivity: 'com.disney.wdpro.park.activities.LoaderActivity',
        deviceName: 'Moto G5 Plus',
        udid: 'ce10160a2c22571404',
        unicodeKeyboard: true,
        resetKeyboard: true,
      waitforTimeout: 30000,
      commandTimeout: 30000
  },

.....

services: ['appium'], appium: { waitStartTime: 6000, command: 'appium.cmd', logFileName: 'appium163.log', args: { address: '127.0.0.1', port: 4723, commandTimeout: '7200', sessionOverride: true, debugLogSpacing: true } },

Also I did install appium locally like npm install appium

Any help?

rahulmr commented 6 years ago

@sumeetp4 It seems to me like npm i has not worked for you as expected. can you try to delete the node_modules directory and again do npm i --no-optional --allow-root command and try it again. Also remove the global install of appium using npm uninstall -g appium and then do npm i appium@1.7.2

evanjmg commented 5 years ago

On mac, I keep getting this. It only works when I run the server separately.

> AppiumDemo@0.1.0 test:e2e /Users/evangillogley/Desktop/dev/android/AppiumDemo
> TS_NODE_PROJECT=./e2e/tsconfig.e2e.json ./node_modules/.bin/wdio ./e2e/local.conf.js

A service failed in the 'onPrepare' hook
Error
    at ChildProcess.exitCallback (/Users/evangillogley/Desktop/dev/android/AppiumDemo/node_modules/wdio-appium-service/build/launcher.js:95:28)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)

Continue...
askeet-engine commented 5 years ago

I got the same error and solved it with npm install -g appium

janlazo commented 5 years ago

@rhysd When will you publish the next release for the appium.cmd fix on Windows?

walternolak commented 5 years ago

Hi everybody, I've written an npm module that starts and stops appium programmatically on windows or mac. It addresses the issues discussed in this thread, including the timing issue. It's called appium-controller....

Hi, Is there any way to save the appium logs with this service? if not, exists a workaround for this? Thanks!

aaronbriel commented 5 years ago

Hi everybody, I've written an npm module that starts and stops appium programmatically on windows or mac. It addresses the issues discussed in this thread, including the timing issue. It's called appium-controller....

Hi, Is there any way to save the appium logs with this service? if not, exists a workaround for this? Thanks!

The default appium log path is set to logs/ . See https://github.com/aaronbriel/appium-controller/blob/master/src/bin/appium-controller.ts for all defaults.

walternolak commented 5 years ago

Hi everybody, I've written an npm module that starts and stops appium programmatically on windows or mac. It addresses the issues discussed in this thread, including the timing issue. It's called appium-controller....

Hi, Is there any way to save the appium logs with this service? if not, exists a workaround for this? Thanks!

The default appium log path is set to logs/ . See https://github.com/aaronbriel/appium-controller/blob/master/src/bin/appium-controller.ts for all defaults.

Got it! Thanks for sharing it 👍

sudhanshu5533 commented 5 years ago

@rahulmr @walternolak Guys, I want to start two appium servers in one go. I want to handle two android application both are different in functionality. I am using WebdriverIO, Please suggest how to enable two appium sessions in wdio.conf.js.

rahulmr commented 5 years ago

@rahulmr @walternolak Guys, I want to start two appium servers in one go. I want to handle two android application both are different in functionality. I am using WebdriverIO, Please suggest how to enable two appium sessions in wdio.conf.js.

@sudhanshu5533 I don't think single wdio.conf.js would resolve your purpose. Coz if you want 2 running appium instances then you will need 2 host address like 127.0.0.2 and 127.0.0.3 and different ports 4747 and 4848 something like these. Also, you will have to spawn or fork 2 nodejs processes. One more thing which comes to my mind, are you trying to launch the 2 apps on same android device? If yes, you need check their behavior since I think Appium will work with 1 app at a time. Second, if you are thinking of 2 android devices then I guess it should work. Sorry, I cannot share any working example as I am no longer working on WebDriverIO due to time constraints.