Skip to content

Instantly share code, notes, and snippets.

@PharaohKJ
Last active March 12, 2019 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PharaohKJ/ba8b6e16bba025ad1a16d26b1e947eb5 to your computer and use it in GitHub Desktop.
Save PharaohKJ/ba8b6e16bba025ad1a16d26b1e947eb5 to your computer and use it in GitHub Desktop.
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