我是自动化测试的新手,没有Ruby或任何其他编程语言的经验。但是,我现在的老板希望我开始自动化小型任务。我偶然发现的问题是试图将哈希值传递到注册表单的字段中。
这是我的小黄瓜方案:
when语句的左侧是我要在其中传递特定值的字段的名称。前两个是输入字段。最后一个哈希值“ age”是一个下拉列表。
有人可以通过给我一个示例红宝石方法来帮助我,该方法可以根据上述信息填写此类注册表格?
P.S。我使用的自动化框架包括Ruby,Cucumber和Watir Webdriver。
答案 0 :(得分:0)
以下代码未经测试,但是类似的东西应该对您有用。
# Step definition
Given /^I enter the following credentials$/ do |table|
# .drop(1) is to get rid of your first row with titles
table.drop(1).each_pair do |setting, value|
browser.element(name: setting).to_subtype.set(value) }
end
end
请谨慎使用小黄瓜代替编码。它应着重于要实现的目标,而不是要实现的目标。
我建议以下情况:
Given RegularJohn is on the create account page
When he submits the create account form with his information
Then the successfully created message should display
请注意,在您的代码中,您需要RegularJohn
是一个配置变量,其中填充了预期的信息信息。
尝试测试失败时,可以使用其他变量,例如BadEmailAndy
。这样,您就可以保持可读性,可维护性和可理解性。