Riddler February 2016

Angular material select for capybara

Can I make select in RoR RSpec + Capybara? Usually i use:

select 'something', from: 'select_name'

But for angular's md-select is doesn't work. Capybara show error:

Capybara::ElementNotFound: Unable to find select box "select_id"

Answers


Riddler February 2016

I simple add a custom md_select method to Capybara.

def md_select name, from: ''
  puts 'md_select `from:` param is required. For example `md_select select_value, from: select_name`' if from.blank?

  find(:xpath, "//md-select[@name='#{from}']").click
  find(:xpath, "//md-select-menu/md-content/md-option/div[text()='#{name}']").click
end

And now we can use it in RSpec:

md_select select_value, from: 'select_name'

Post Status

Asked in February 2016
Viewed 3,919 times
Voted 10
Answered 1 times

Search




Leave an answer