0

I have a drone setup, and my pipeline runs the following:

pipeline:
  test:
    image: node:8.3.0
    commands:
      - npm install --only=dev
      - npm run automation

The automation script in my package.json is as follow:

"automation": "node automation/automation.js"

So it runs a Javascript file, this file creates a selenium driver and launches it to a page etc.

If I run the script manually, it will run my selenium tests and finish once all the of it is ended, as expected.

But when drone runs it, it exits the pipeline step as soon as the entire javascript has been executed, even though there are still asynchronous tasks (from the selenium driver) running. This makes my tests end early and unable to report results properly.

What am I doing wrong?

nialna2
  • 2,056
  • 2
  • 25
  • 33

2 Answers2

0

I don't know how selenium works, but once the command called by Drone returns, it thinks it finished. To wait for asynchronous tasks (i.e. child processes) to finish, you'd need to implement this yourself. Assuming the selenium process is called selenium, something like this could work:

      - npm run automation && while ps -C selenium > /dev/null 2>&1; do sleep 1; done
tkausl
  • 13,686
  • 2
  • 33
  • 50
0

I found the answer to that problem:

If you happen to use any sort of setTimeout or other asynchronous things, I have no idea why but it will make selenium react weirdly, causing the behaviour I had.

I modified my code to properly use driver.wait and other kinds of selenium asynchronous calls everywhere, so that I never use manual timeouts.

My theory is that if selenium doesn't detect any new driver instructions and there are no driver.wait or promises waiting, it will assume the program is done. And for some reason, even though node was still running, this made drone detect an exit signal.

nialna2
  • 2,056
  • 2
  • 25
  • 33