Cucumber:从表中选择一个元素进行删除或添加
我正在使用 ruby on Rails 开发的应用程序中有下表:
我想在 Cucumber 中创建一个测试,在其中从表中选择一个用户并将其删除或编辑。
我不知道它的步骤定义是什么。
我希望能够做这样的事情:
Feature: User Manegement
In order to manage users
As an admin
I want to see a users list and change user properties
Background:
Given the following activated users exists
| name | email |
| Alice Hunter | [email protected] |
| Bob Hunter | [email protected] |
And the following user records
| name | email |
| Jonh Doe | [email protected] |
Scenario: I delete a user from the table
Given I am logged in as admin
When I follow "Administration"
And I follow "User Management"
And I delete "Alice Hunter"
Then I should not see "Alice Hunter"`
有人可以帮忙吗? 谢谢。
@brad
返回的错误:
wrong number of arguments (2 for 1) (ArgumentError)
./features/step_definitions/table_steps.rb:26:in `within'
./features/step_definitions/table_steps.rb:26:in `/^I delete "(.*)"$/'
I have the following table in an application I am developing using ruby on rails:
I want to create a test in cucumber where I select a user from the table and delete it or edit it.
I don't know what is the step definition for that.
I'd like to be able to do something like:
Feature: User Manegement
In order to manage users
As an admin
I want to see a users list and change user properties
Background:
Given the following activated users exists
| name | email |
| Alice Hunter | [email protected] |
| Bob Hunter | [email protected] |
And the following user records
| name | email |
| Jonh Doe | [email protected] |
Scenario: I delete a user from the table
Given I am logged in as admin
When I follow "Administration"
And I follow "User Management"
And I delete "Alice Hunter"
Then I should not see "Alice Hunter"`
Can anyone help?
Thank you.
@brad
The error returned:
wrong number of arguments (2 for 1) (ArgumentError)
./features/step_definitions/table_steps.rb:26:in `within'
./features/step_definitions/table_steps.rb:26:in `/^I delete "(.*)"$/'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
经过一些广泛的搜索和小的重构,我设法解决了这个问题。
我使用了以下步骤:
我也对 webrat 的 RDoc 感兴趣,但我发现的所有内容似乎都乱了。
After some extensive searching and minor refactoring, I managed to solve the problem.
I have used the following step:
I am also insterested in webrat's RDoc, but everything I find seems out of order.
我有一个遗留应用程序,对于有用的链接 ID 甚至类(即 class="deleteLink")来说不太好。我必须找到 href 中具有“删除”的链接。显然这很容易出错,但目前可以使用。这是代码。
xpath 中有点混乱,但这是我最终可以开始工作的。我正在使用 Cucumber/Rspec/Capybara/Selenium 来测试 Java 应用程序。
I have a bit of a legacy app that isn't being nice with regard to useful link ids or even classes (i.e. class="deleteLink"). I have to find the link that has 'delete' in the href. Obviously this is error prone but it's working for now. Here's the code for that.
It's a little messy in the xpath, but it's what i could finally get to work. I'm using Cucumber/Rspec/Capybara/Selenium to test a Java app BTW.
我假设删除部分让您感到困惑,因为其他内容相当标准(设置给定和以下链接等...)
那么,您使用什么作为浏览器抽象?韦拉特?水豚?看起来好像您有一个“删除”链接,执行这样的操作是否足够?
我相信像“不应该看到”这样的东西可能是通过生成的 webrat/capybara 步骤来支持的。
这是您要找的吗?
I'm going to assume it's the deleting part that is messing you up as the other stuff is fairly standard (setting up givens and following links etc...)
So, what are you using as your browser abstraction? Webrat? Capybara? It appears as if you have a 'delete' link, is it sufficient to do something like this?
And I believe something like "should not see" is probably supported out of the box with generated webrat/capybara steps.
Is this what you're looking for?
我遇到了同样的问题,并研究了“我遵循“abcd””到 click_link() 的翻译,我发现有一个可选的 : 方法。所以我定义了这个:
并且有效......然后我决定使其更通用,而不仅仅是“删除”:
效果很好。我也用“我按照“mylink”作为 get”进行了尝试,并且有效,因此方法部分似乎相当灵活。
I had the same problem, and looking into the translation of 'I follow "abcd"' to click_link(), I found there's an optional :method. So I defined this:
and that worked... Then I decided to make it more general, not just "as delete":
Works great. I tried it with 'I follow "mylink" as get' too, and that worked, so the method part seems to be suitably flexible.
根据下面布拉德的回答,我选择了:
Following on Brad's answer below I went with: