LoginSignup
20
20

More than 5 years have passed since last update.

Capybaraのメソッドメモ

Last updated at Posted at 2014-11-10

自分が日本語で検索したときに、情報が拾えなくって困ったので、
使ったものや必要なものをメモとして残しておきます。
随時更新していきます。
参考:Class: Capybara::Session — Documentation for jnicklas/capybara (master)

情報表示

body

htmlと同じ

html => String

現状のDOMのスナップショットを返す(JSで変更されたかもしれない)

source

htmlと同じ

current_url => String

現状のページのURLを返す

current_host => String

現状のページのhostを返す

current_path =>

ブラウザ動作

execute_script(script) => Object

JavaScriptを実行して値を返す

evaluate_script(scripr) => Object

JavaScriptを実行する

visit(url) => Object

URLへ移動する

session.visit('/foo')
session.visit('http://google.com')

go_back => Object

ブラウザの履歴を戻る

go_forward => Object

ブラウザの履歴を進む

未分類

within

within(:xpath, '//div[@id="delivery-address"]') do
fill_in('Street', :with => '12 Main Street')
end

within_fieldset

within_table

within_frame

current_window => Capybara::Window

windows => ArrayCapybara::Window

開いている全てのWindowを取得。
順番は定義されていない。

open_new_window

switch_to_window

Windowの切り替え

switch_to_window(&block) => Capybara::Window
switch_to_window(window) => Capybara::Window
window = switch_to_window { title == 'Page title' }

within_window

window_opened_by

save_page(path = nil) => String

スクリーンショットの保存

save_and_open_page

save_screenshot

save_and_open_screenshot

reset_session!

response_headers

status_code => Integer

HTTP のステータスコード

current_scope

20
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
20