[英]Capybara tests don't work, while actual app works fine. React front-end in Rails 5
Specs : Rails 5.2, Ruby 2.5.1, Yarn 1.91.1, React-Rails 2.6.0, selenium-webdriver 3.14, chromedriver 77, capybara gem 3.29, Ubuntu 18.04 Specs : Rails 5.2, Ruby 2.5.1, Yarn 1.91.1, React-Rails 2.6.0, selenium-webdriver 3.14, chromedriver 77, capybara gem 3.29, Ubuntu 18.04
Issue : I created a questionnaire using react components in a Rails app which works when run in development mode.问题:我在 Rails 应用程序中使用反应组件创建了一份问卷,该应用程序在开发模式下运行时有效。 I can click the yes or no button then a callback function renders the new question text.
我可以单击是或否按钮,然后回调 function 呈现新的问题文本。 However my selenium integration tests don't pick this up.
但是我的 selenium 集成测试并没有选择这个。 The
page
object continues to have the same text for the first question so I receive an error like this object
page
的第一个问题仍然有相同的文本,所以我收到这样的错误
Failure/Error: expect(question.text).to include('last question') expected "first question" to include "last question"
The test itself looks like this in features/questionnaire.rb测试本身在 features/questionnaire.rb 中看起来像这样
RSpec.feature "Onboarding Questionnaire", type: :feature, js:true do
(...)
it...
question = find('h3.question')
expect(question.text).to include('first question')
yes = find('#yes')
yes.click
sleep 5
question = find('h3.question')
expect(question.text).to include('last question')
The problem arises after yes.click
.问题出现在
yes.click
之后。 I thought at first my animations were causing the issue, but I removed those and it is just using setState in my callback function.起初我以为是我的动画导致了这个问题,但我删除了这些,它只是在我的回调 function 中使用了 setState。
Here is my react callback function这是我的反应回调 function
saveAnswer(e) {
questionnaire = this
++questionnaire.state.page
questionnaire.setState({page: questionnaire.state.page})
}
Here is my driver config这是我的驱动程序配置
Capybara.javascript_driver =:selenium_chrome_headless
Now using sleep
works as desired.现在使用
sleep
按需要工作。 Here are the changes I made.这是我所做的更改。
1) I removed the deprecated gem chromedriver-helper
and replaced it with webdrivers
1)我删除了已弃用的 gem
chromedriver-helper
并将其替换为webdrivers
2) Added require 'webdrivers'
to the rails_helper.rb file. 2) 在 rails_helper.rb 文件中添加了
require 'webdrivers'
。
3) Found error in my react code (which wasn't showing up in development or being logged in chrome webdriver) of questionnaire = this
which I changed to var questionnaire = this
. 3)在我的react代码中发现错误(未显示在开发中或未登录chrome webdriver)的
questionnaire = this
我更改为var questionnaire = this
。
Integration tests now pass fine using selenium_chrome_headless
现在使用
selenium_chrome_headless
可以很好地通过集成测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.