来自先前 Capybara js 规范的 XHR 请求在下一个规范中出现(并失败)

XHR request from previous Capybara js spec surfacing (and failing) in next spec

我们使用 Chrome Headless with Capybara 和 Selenium 进行三个 js 功能测试。

当一个特定的 js 测试(使用 xhr)跟随另一个也使用 xhr(参见 https://github.com/thredded/thredded/tree/separate-out-js-from-non-js-in-ci for the code or https://travis-ci.org/thredded/thredded/jobs/302376004 示例 运行).

服务器错误总是在下一个规范 "User creates new topic with title and content" 中出现,但 url 显然来自上一个规范 "User replying to a topic starts a quote-reply (js)"。

显而易见的是,在规范末尾的请求和 DatabaseCleaner.clean 之后发生的请求之间存在竞争条件。然而,我的理解是 Capybara 2.7+ [1] after_each 应该发生在 reset_session! 之后,这应该可以防止这个精确的问题。无论如何,我很确定页面中没有任何内容可以创建此请求(我们有一个特定的 wait/test for the completion of this ajax request)。

这发生在 3 个不同的数据库和 3 个不同的 rails 版本(4.2、5.0、5.1)上。 我们已经升级到最新的 Capybara。

已尝试禁用 turbolinks,在有问题的规范结束时加入大量(10 秒)睡眠...也已尝试手动重置会话。

一定是漏了什么。有什么指点吗?

[1] https://github.com/teamcapybara/capybara/pull/1637 referenced from https://bibwild.wordpress.com/2016/02/18/struggling-towards-reliable-capybara-javascript-testing/

更新:添加了对 xhr 的引用,因为另一个(新的)js 规范有问题,而且它不是前两个请求(登录表单和 post 登录)显示错误,但第一个显示错误的 xhr 请求。在新情况下,正在请求的 xhr 在后续规范中使用 POST 请求,即使它最初是使用 GET

请求的

看起来这是一个 chromedriver 错误。

我们通过将 chromedriver(在 travis 上)升级到 v2.33 (linux) 来解决这个问题。 https://travis-ci.org/thredded/thredded/builds/302431113

上一版本为v2.31。奇怪的是,我们无法通过 2.31 (mac) 在本地解决这个问题。