RSpec + Capybara:如何测试Bootstrap进度栏 [英] RSpec + Capybara: How do I test a Bootstrap progress bar

查看:63
本文介绍了RSpec + Capybara:如何测试Bootstrap进度栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RSpec测试具有引导进度栏的页面。如何在Div中测试不同的Aria属性?

I am testing a page that has a bootstrap progress bar using RSpec. How do I test the different Aria attributes in the Div?

<div class="progress-bar progress-bar-success" 
    role="progressbar"  
    aria-valuenow="40"  
    aria-valuemin="0"  
    aria-valuemax="100"  
    style="width: 40%"> 
</div>

感谢您能提供的任何帮助。

I appreciate any help you can provide.

谢谢!

推荐答案

您可以使用 []获取元素的属性值方法。例如:

You can get the attribute values of an element using the [] method. For example:

find('div.progress-bar')['aria-valuenow']
#=> "40"
find('div.progress-bar')['aria-valuemax']
#=> "100"

您可以通过以下方法测试值:

You can test the values by doing:

expect(find('div.progress-bar')['aria-valuenow']).to eq('40')
expect(find('div.progress-bar')['aria-valuemax']).to eq('100')

但是,这将不会使用Capybara的内置等待方法。如果您使用wait方法很重要,则应该执行以下操作:

However, that will not use Capybara's built-in wait methods. If you using the wait methods is important, you should do:

expect(page).to have_css('div.progress-bar[aria-valuenow="40"]')
expect(page).to have_css('div.progress-bar[aria-valuemax="100"]')

这篇关于RSpec + Capybara:如何测试Bootstrap进度栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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