Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test:system (capybara) オレオレチートシート

ツール

https://github.com/mugi-uno/nezumi

入力

    fill_in 'staff_password', with: 'password'
    click_on 'LOGIN'
    find_button('発注する').click # findでみつかるまでwaitが入る模様 -> see https://www.rubydoc.info/github/jnicklas/capybara/Capybara%2FNode%2FFinders:find_button

セレクタ

page.all('div', text: /\Aテキスト\z/)
assert_selector('div', text: /\Aテキスト\z/, count: 1)
page.all('tr.order-record').count
assert_selector('.order-record', count: 2)

子ノードをセレクトしたい

within でスコープを区切る

    element = page.all('tr.order-record')[0]
    within(element) do
      page.all('td').each_with_index do |e, i|
        pp [i, e.text]
      end
    end

ネストもできる (https://github.com/gongo/maizebox/blob/master/examples/runner.rb)

within(:css, 'aside') do
  within(:css, 'li.first-child') do
    page.attention_here
  end

  within(:css, 'li.third-child') do
    page.attention_to(find(:css, 'img'))
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.