黄瓜测试表中元素的顺序
我想运行一个测试来测试元素的顺序 我希望订单按日期升序。
这是我的黄瓜特征场景和最后一句话的步骤。
Scenario: Order of the events should be Ascending
Given I am signed into an account called "Gorilla Tech" as a customer
When I follow "Register"
And I follow "Events"
And I follow "Register new event"
Then I should see the header "Use the form below to register a new event"
And I fill in "Title" with "Apefest 2010"
And I fill in "Event at" with "2010-01-07"
And I fill in "Add a note" with "This was truly awesome"
Then I press "Create"
Then I follow "Register new event"
And I fill in "Title" with "Monkeyfest 2010"
And I fill in "Event at" with "2010-01-08"
And I fill in "Add a note" with "Yeah"
Then "Apefest 2010" should appear before "Monkeyfest 2010"
Then /"(.*)" should appear before "(.*)"/ do |first_example, second_example|
response.body.should =~ /#{first_example}.*#{second_example}/
end
我这里确实有两个问题。第一个是我如何正确指定我的测试?我可以指定上面的测试不同且更正确吗?
我想要做的是在 2 个不同的日期下注册 2 个不同的事件。该事件稍后将作为列表显示在网页上。然后我想检查事件是否按日期排序。我希望最新日期的活动出现在顶部。
这是我想要测试的集合的代码。在某种程度上,我想检查下面 div 中的集合是否按日期升序排列。
<div id="feeds">
<table>
<caption><%= t('events.all') %></caption>
<thead>
<tr>
<th><%= Event.t(:title) %></th>
<th><%= Event.t(:event_at) %></th>
<th></th>
</tr>
</thead>
<tbody>
<%= render :partial => 'event', :collection => @events %>
</tbody>
</table>
</div>
<%= will_paginate(@events) %>
I want to run a test that tests the order of the elements
I want the order to be ascending by date.
Here is my cucumber feature scenario and the step for the last sentence.
Scenario: Order of the events should be Ascending
Given I am signed into an account called "Gorilla Tech" as a customer
When I follow "Register"
And I follow "Events"
And I follow "Register new event"
Then I should see the header "Use the form below to register a new event"
And I fill in "Title" with "Apefest 2010"
And I fill in "Event at" with "2010-01-07"
And I fill in "Add a note" with "This was truly awesome"
Then I press "Create"
Then I follow "Register new event"
And I fill in "Title" with "Monkeyfest 2010"
And I fill in "Event at" with "2010-01-08"
And I fill in "Add a note" with "Yeah"
Then "Apefest 2010" should appear before "Monkeyfest 2010"
Then /"(.*)" should appear before "(.*)"/ do |first_example, second_example|
response.body.should =~ /#{first_example}.*#{second_example}/
end
I really have two problems here. The first one is how do i specify my test correctly? Can i specify my test above different and more correct?
What i want to do is to register 2 different events under 2 different dates. The event will later appear as a list on the webpage. Then i want to check if the events are in order by date . I want the event with the newest date to appear on the top.
here is the code with the collection i want to test. In some way i want to check if the collection in the div below has the an ascending order by date.
<div id="feeds">
<table>
<caption><%= t('events.all') %></caption>
<thead>
<tr>
<th><%= Event.t(:title) %></th>
<th><%= Event.t(:event_at) %></th>
<th></th>
</tr>
</thead>
<tbody>
<%= render :partial => 'event', :collection => @events %>
</tbody>
</table>
</div>
<%= will_paginate(@events) %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您编写步骤定义的方式很好,您只需将多行 (m) 开关添加到您的模式中即可。 :)
The way you wrote your step definition is fine you just need to add the multiline (m) switch to your pattern. :)
我也许会建议使用表格对您的步骤进行一些整合。
我建议:
您当前的解决方案的缺点是不太精确,在整个响应正文中您可能会在另一位置找到一个示例中的文本。我建议使用 XPATH 达到您的疼痛阈值,或者使用(我假设您使用 Watir)(或变体)类。
您可以通过迭代行(并指定包含事件名称的列;这里我假设第一个)来从表中收集所有事件名称...
然后断言事件存在并且它们在数组。
I would perhaps propose some consolidation to your steps by using a table.
I would suggest:
Your current solution has the trade off of not being very precise, looking in the entire response body you may find text from one example in another location. I would suggest the use of XPATH up to your pain threshold or utilizing, I am assuming your using Watir (or variant), the classes.
You could collect all the event names from the table by iterating over the rows (and specifying the column that contains the event name; here I assume the first one)...
Then assert that the events exist and they are in the desired order within the array.
为什么不直接使用 nth-child 选择器呢?
Why not just use the nth-child selector?