RSpec + Capybara: How do I test a Bootstrap progress bar

ぃ、小莉子 提交于 2019-12-24 13:39:20

问题


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.

Thanks!


回答1:


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')

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"]')



回答2:


You can also do cool things like this:

it 'reports the status of dropdowns (expanded/collapsed) to non-visual agents', js: true do
  within '#sign_in_panel' do
    expect {
      click_link 'Sign in'
    }.to change { find('a.dropdown-toggle')['aria-expanded'] }.from('false').to 'true'
  end
end


来源:https://stackoverflow.com/questions/26428141/rspec-capybara-how-do-i-test-a-bootstrap-progress-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!