How do you test if a div has a certain css style in rspec/capybara?

前端 未结 4 733
半阙折子戏
半阙折子戏 2020-12-14 16:36

How do you test if a div tag has a certain css style? I\'m trying to test if it has display:none; or display:block.

I tried the following

4条回答
  •  轮回少年
    2020-12-14 17:17

    My way to ensure that element have a certain class:

    let(:action_items) { page.find('div.action_items') }
    
    it "action items displayed as buttons" do
      action_items.all(:css, 'a').each do |ai|
        expect(ai[:class]).to match(/btn/)
      end
    end
    

    or smthing like this

    expect(ai[:style]).to match(/color: red/)
    

    I found it here: http://rubydoc.info/github/jnicklas/capybara/Capybara/Node/Element#%5B%5D-instance_method

提交回复
热议问题