Capybaraã2.1.0ã«ãªã£ã¦ãã¾ãå¾®å¦ã«æåãå¤ãã£ãã®ã§èª¿ã¹ã¦ã¿ã
ä¹ ã ã«ããã°æ¸ãã
ä½æ°ãªãbundle updateããããcapybaraã2.1.0ã«ãªã£ã¦ã¦ããã¹ããè½ã¡ãããã«ãªã£ãã
ã¾ãæåãå¤ãã£ããããã®ã§ãã°ã°ã£ã¦ç¢ºèªãã¦ã¿ãã
Introducing Capybara 2.1ãåç
§ããã¨å¤§ä½åãããã©ãä¸å¿æ¥æ¬èªã§ãã£ããæ¸ãã¦ããã
ã»ã¬ã¯ã¿ã«ãããããã®å³å¯æ§ãå¤æ´ã«ãªã£ã
capybara2.0ãããfindã¡ã½ããã§DOMãæ¢ããæã«è¤æ°ãããããã¨ä¾å¤ãåãããã«ãªã£ããã
2.1.0ããã¯ãããã³ã°ã®ã«ã¼ã«ãconfigureã§æå®ã§ããããã«ãªã£ãã
Capybara.configure do |config| config.match = :prefer_exact end
ãããã³ã°ã®ç¨®é¡ã¯ä»¥ä¸ã®åã¤
- :one
- :first
- :prefer_exact
- :smart
:one
2.0ã¨åãã«ã¼ã«ãè¤æ°ãããããã¨ä¾å¤ã«ãªãã
:first
ãããµããªãããããããããä¸ã§æåã®ä¸ã¤ã使ãã
:prefer_exact
1.xç³»ã¨åãã«ã¼ã«ãè¤æ°ãããããå ´åãæ£ç¢ºã«ããããã¦ãããã®ãåªå ããã
:smart
2.1ããã®ããã©ã«ããå¾è¿°ããexactãªãã·ã§ã³ã«ä¾åãã¦æåãå¤åããã
exactãªãã·ã§ã³
å
ã
ãcapybaraã§findããclick_linkã§æååãå
ã«ãããã³ã°ããããã¨ãé¨åä¸è´ã§ãããããã¦ããã
2.1ããã¯ããã©ã«ãã§ã¯å®å
¨ä¸è´ã§ãªãã¨ãããããªãããã«ãªã£ã¦ããã
find, click_link, fill_inã¯ã:exactãªãã·ã§ã³ã§æåãå¶å¾¡ã§ããããã«ãªã£ã¦ãããã
ã°ãã¼ãã«ãªã³ã³ãã£ã°ãè¨å®ããäºã§ãããã©ã«ãã®æåã2.0以åã¨åæ§ã«è¨å®ã§ããã
Capybara.configure do |config| config.exact_option = true end # or Capybara.exact = true
å¯è¦æ§ã«ããæåã®å¤å
å
ã
ãhiddenãªè¦ç´ ãç¡è¦ãããªãã·ã§ã³ãCapybaraã«ã¯ç¨æããã¦ããããããã¯ããã©ã«ãã§falseã«ãªã£ã¦ããã
hiddenãªè¦ç´ ãè¦ããã®ã¯æ··ä¹±ãå¼ã¶ãããã®ã§ã2.1ããã¯ããã©ã«ãã®è¨å®ãtrueã«å¤ãã£ããã¤ã¾ããè¨å®ãã¦ãªãã¨hiddenãªè¦ç´ ã¯å¼ã£æãããªããªãã
ãããã©ããªãã ãããlinkã¨ããªããããªãã ãã©ãDOMã®ç¶æ³ã調ã¹ãå ´åã¯è¦ããæ¹ããããã¨ããããã§ãã©ã£ã¡ãè¯ãã¨ãè¨ããªãã¨æããã ãã
å
ã®æåã«æ»ãæã«ã¯ä»¥ä¸ã®ããã«ããã
Capybara.ignore_hidden_elements = false
å¯è¦æ§ã«ããtextã¡ã½ããã®æåã®å¤å
1.xç³»ã ã¨ãããããã«ã¼ã«ã決ã¾ã£ã¦ããªãã¦ãdriverã«ãã£ã¦æåãç°ãªã£ã¦ããã
2.0ç³»ã«ãªã£ã¦ãhiddenãªDOMã«å«ã¾ããtextã¯ä½ãè¿ããªããªã£ãã
2.1ç³»ããã¯ãignore_hidden_elementsã«æåãä¾åããããã«ãªã£ãã
ã¾ããtextã¡ã½ããã«å¼æ°ã渡ããããã«ãªããåå¥ã«æåãä¸æ¸ãã§ããããã«ãªã£ã¦ããã
find("#thing").text # depends on Capybara.ignore_hidden_elements find("#thing").text(:all) # all text find("#thing").text(:visible) # only visible text
ignore_hidden_elementsã®è¨å®ã«é¢ãããã2.0ã¨æåãåãã«ã§ããããã«ã
Capybara.visible_text_onlyã¨ãããªãã·ã§ã³ãç¨æããããtrueã«è¨å®ããã¨ã常ã«visibleãªtextãè¿ãåä½ã«ãªãã
titleã®å¤ãåããããã«ãªã£ã
titleã®å¤ãåãããã®APIã¨ãããã£ã¼ã追å ãããã
page.title # => "The title" page.has_title?("The title") # => true page.should have_title("The title")
disabledãªãã£ã¼ã«ãã«ã¢ã¯ã»ã¹ãããªãã·ã§ã³ã®è¿½å
find_field, has_field?ãªã©ã®ã¡ã½ãããã:disabledãªãã·ã§ã³ãåããããã«ãªã£ãã
:disabledãtrueã«ã»ããããã¨ãdisabledãªãã£ã¼ã«ãã®ã¿ãæ¤ç´¢å¯¾è±¡ã«ãªãã
ã¨ããããã§ããã£ããã¾ã¨ãã¦è¦ãã
æ£ç¢ºã«ç¥ããã人ã¯åæãèªãã§ãã ããã