Drone CI:为什么 运行 使用 Selenium 的 npm 脚本在完成之前就退出了?

Drone CI: Why does running a npm script that uses Selenium exits before it finished?

我有无人机设置,我的管道 运行 如下:

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

我的package.json中的自动化脚本如下:

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

所以它 运行 是一个 Javascript 文件,这个文件创建一个 selenium driver 并将其启动到页面等

如果我手动 运行 脚本,它将 运行 我的 selenium 测试并在所有测试结束后完成,如预期的那样。

但是当 drone 运行 时,它会在整个 javascript 执行完后立即退出管道步骤,即使仍然有异步任务(来自 selenium driver) 运行宁。这使我的测试提前结束并且无法正确报告结果。

我做错了什么?

我不知道 selenium 是如何工作的,但是一旦 Drone returns 调用命令,它就认为它完成了。要等待异步任务(即子进程)完成,您需要自己实现。假设 selenium 进程被称为 selenium,这样的事情可能会起作用:

      - npm run automation && while ps -C selenium > /dev/null 2>&1; do sleep 1; done

我找到了那个问题的答案:

如果你碰巧使用任何类型的 setTimeout 或其他异步的东西,我不知道为什么,但它会使 selenium 做出奇怪的反应,导致我的行为。

我修改了我的代码以正确使用 driver.wait 和其他类型的 selenium 异步调用,所以我从不使用手动超时。

我的理论是,如果 selenium 没有检测到任何新的驱动程序指令并且没有 driver.wait 或 promises 等待,它将假定程序已完成。出于某种原因,即使节点仍然 运行,这也会让无人机检测到退出信号。