ruby-on-rails - 使用带有导轨的黄瓜进行自动化测试时出错
问题描述
我从自动化测试领域开始,在运行我的一项测试时出现以下错误。测试将填写输入类型的日期时间字段,其中包含机器停止的开始时间。我在用 Ruby on Rails 和 Ext Js 编写的系统上运行 Cucumber 和 Capybara。
Error: wrong number of arguments (given 1, expected 0) (ArgumentError)
贝娄是我的 env.rb 项目:
require 'capybara'
require 'capybara/cucumber'
require 'report_builder'
require 'selenium-webdriver'
require 'webdrivers/chromedriver'
Capybara.javascript_driver = :webkit
Capybara.configure do |config|
config.default_driver = :selenium_chrome
config.default_max_wait_time=10
config.app_host='http://localhost:3000/'
end
我的 example.feature 是这样的:
Scenario: start of the machine stop
Given that I accessed the system
And marked 'Yes' in 'Did the machine stop?'
And I fill the start of the machine stop with '2020-05-12 16:00:00' #UTC
When saving the form
Then the success message should appear
我的 steps.rb 如下所示:
And("I fill the start of the machine stop with {string}") do
@machine_stop = machine_stop
@MD.machine_stop_start(@machine_stop)
end
我的页面.rb:
class Machine_downtime
include Capybara::DSL
def machine_stop_start
find('input[id="datetimefield-1312-inputEl"]').click
end
end
我已经进行了谷歌搜索以找到可能的解决方案,但我没有找到任何类似的案例。我试图查看 Cucumber 文档,但没有找到任何特定于我的问题或 Rails 的内容。我可以在步骤中停止使用字符串并使用表格,但在这种情况下我有更多场景,我想继续使用字符串,以便于维护并避免更改超过 100 个测试场景。
我感谢任何可以帮助我解决问题的人。
Ps Ruby on Rails 在不同的项目上运行。
解决方案
更新:
我在 machine_stop_start 方法中插入了我在步骤中创建的变量,并且不再发生错误。
class Machine_downtime
include Capybara::DSL
def machine_stop_start (machine_stop)
find('input[id="datetimefield-1312-inputEl"]').click
end
end
现在我可以单击所需的字段,但没有填充所需的信息。我会尝试找出我可能做错了什么。
推荐阅读
- java - 当我使用 AES 加密或解密文件时,文件末尾有奇怪的字符,这可能是缓冲区问题还是 AES 问题?
- c++ - 将子字符串提取到最后一个分隔符 C++
- python - 如何在python中制作数据类型整数
- xml - 是否可以在kafka中发布xml?
- angular - 总是重定向到主页的路由
- reactjs - 如何将导出功能添加到 React highcharts 中的自定义按钮?
- apache-commons - Apache Commons Collections 是否有 ListValuedTreeMap?
- python - 将图形从python复制到word
- terraform - 使用 vCloud Director 提供程序在 Terraform 中创建新资源
- r - R: 看不到 Psych 包的源代码