segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.54k stars 1.08k forks source link

Nightmare is simply not starting #1586

Open aaronik opened 4 years ago

aaronik commented 4 years ago

Similar to #1515, except their fix is not working for me.

I also tried npm cache clean --force, still to no avail.

uname -a
Linux hyperion 5.3.0-24-generic #26-Ubuntu SMP Thu Nov 14 01:33:18 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

node --version
v12.13.1

npm --version
6.13.2

The code I'm running is straight from the example:

const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })

nightmare
  .goto('https://duckduckgo.com')
  .type('#search_form_input_homepage', 'github nightmare')
  .click('#search_button_homepage')
  .wait('#r1-0 a.result__a')
  .evaluate(() => document.querySelector('#r1-0 a.result__a').href)
  .end()
  .then(console.log)
  .catch(error => {
    console.error('Search failed:', error)
  })

My package.json:

{
...
  "dependencies": {
    "nightmare": "^3.0.2"
  }
}

I'd copy the output of what I've run but there simply is none. The command node index.js instantly finishes with no output and no error code. (echo $? returns 0)

aaronik commented 4 years ago

Aha, I discovered the debug flag, now the output is:

DEBUG=nightmare node index.js 
  nightmare queuing process start +0ms
  nightmare queueing action "goto" for https://duckduckgo.com +1ms
  nightmare queueing action "type" +0ms
  nightmare queueing action "click" +0ms
  nightmare queueing action "wait" +0ms
  nightmare queueing action "evaluate" +0ms
  nightmare running +0ms
  nightmare electron child process exited with code 127: command not found - you may not have electron installed correctly +7ms
  nightmare electron child process not started yet, skipping kill. +1ms

which is pretty clearly saying that electron is not installed. However I do have nightmare installed, as the docs suggested, so I thought electron was supposed to come with it. The process really should at least return an error code, if not a helpful message, when this happens.

I'm still stuck though, because I don't know how to get electron installed correctly. Can you help? Thanks!

ethanfrey commented 4 years ago

I had the same issue (on ubuntu 18.04). I think I got a step closer...

Running yarn run electron got me:

electron: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory
error Command failed with exit code 127.

I then tried:

sudo apt -y install libgconf2-4

and now electron starts up fine, and I can run some scripts. Running tests (copied from the homepage) still hangs for me somehow (but at least it hangs after "run", without an electron error).

Hope this helps.

ethanfrey commented 4 years ago

Ahh... also found the selector is off in the sample test. Try:

.click('#search_form_homepage_top .js-search-button')

Then everything worked

aaronik commented 4 years ago

Seems like there are many hidden steps required to even get this running. I've decided to go with nightwatch.js for my testing needs since this library seems pretty rickety.