使用水豚测试内容的顺序(序列) [英] Test order(sequence) of content using capybara

查看:54
本文介绍了使用水豚测试内容的顺序(序列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下语法:

page.body.index('Name')

page.body.index('Name') < page.body.index('Phone')

但问题是,如果同一页面上有多个相同内容的字符串,则无法检查特定字符串的索引.

But problem is that if there are multiple strings with same content on same page, then unable to check the index of particular string.

例如.页面有 3 次姓名"和电话"内容,那么如何验证具体内容的顺序.

For ex. Page is having content 'Name' and 'Phone' 3 times, then how specific content's order can be verified.

请建议我们是否可以以相同或其他更好的方式使用 CSS 语法.

Please suggest if we can use CSS syntax for the same or any other better way.

推荐答案

在功能规范中,上述检查整页元素顺序的问题解决如下:

In feature spec, above issue of checking the sequence of elements on full page is solved as below:

映射页面上的所有元素,将其插入一个数组并与预期的元素数组匹配.在预期的数组中,按要求存储元素.

Map all the elements on page, insert it into an array and match it with expected array of elements. In expected array, store elements in order as per the requirement.

下面是上面的解决方案:

Below is the solution for above:

expected_array = ['名称','电话','电子邮件']

expected_array = [ 'Name', 'Phone', 'Email' ]

page.all.map(&:text).should eq expected_array

page.all.map(&:text).should eq expected_array

此外,对于像标题这样的特定元素,可以使用特定的 css 类来完成,如下所示:

Also, for particular elements like headers, it can be done using specific css class as below:

page.find('.h4').map(&:text).should eq expected_array

page.find('.h4').map(&:text).should eq expected_array

这篇关于使用水豚测试内容的顺序(序列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆