我在cucumber / capybara / site_prism上使用不同的登录凭据进行了大量测试,这些测试非常混乱。我想尽可能地统一他们;这个解决方案似乎很好https://blog.jayway.com/2012/04/03/cucumber-data-driven-testing-tips/
但是在遵循这个例子时,我会在第一行步骤定义
中遇到这个问题Your block takes 1 argument, but the Regexp matched 2 arguments.
显然,我误解了应该如何处理哈希;有人可以帮忙吗?我的代码少了测试数据 黄瓜
Given I login as "ad" with the following data:
|role|usern |userpass |
|ad |adcccount |adpassword |
|ml |mlaccount |mlpassword |
步骤定义
Given /^I login as "(ad|ml)" with the following data:/ do |user|
temp_hash = {}
if (user == "ad")
temp_hash = $ad
elsif (user == "ml")
temp_hash = $ml
end
usern = temp_hash["usern"]
userpass = temp_hash["userpass"]
@app = App.new
@app.login.load
@app.login.username.set usern
@app.login.password.set userpass
@app.login.btn_login.click
end
答案 0 :(得分:0)
您收到该错误,因为匹配的第二个参数是data_table。您的步骤定义需要
Given /^I login as "(ad|ml)" with the following data:/ do |user, data_table|
...
如果你查看你链接的文章中的Given /I create new user named "(user_1|user_2|user_3)" with the following data:/ do |user, data_table|
步骤,你可以看到同样的事情,虽然那并没有在data_table中使用多个条目所以我不是100%肯定是什么你试图在你的例子中做。
答案 1 :(得分:0)
Given /^I login as "(ad|ml)" with the following data:/ do |login_role, data|
temp_hash = {}
data.hashes.each do |hash|
if hash[:role] == login_role
temp_hash[:role] = hash[:role]
temp_hash[:usern] = hash[:usern]
temp_hash[:userpass] = hash[:userpass]
end
end
usern = temp_hash[:usern]
userpass = temp_hash[:userpass]
@app = App.new
@app.login.load
@app.login.username.set usern
@app.login.password.set userpass
@app.login.btn_login.click
expect(@app.dashboard).to be_displayed
end