Skip to content

Instantly share code, notes, and snippets.

@bluerabbit
Last active April 22, 2022 01:01
Show Gist options
  • Select an option

  • Save bluerabbit/6227860 to your computer and use it in GitHub Desktop.

Select an option

Save bluerabbit/6227860 to your computer and use it in GitHub Desktop.

Revisions

  1. bluerabbit revised this gist Mar 14, 2017. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,14 @@ uncheck('チェックボックス1')
    attach_file 'file', "#{fixture_path}/xxx.csv"
    ```

    最近はinput type=fileを隠してボタンを上に出してたりすることが多いので、その場合は`visible: false`が必要

    ```ruby
    attach_file 'file', "#{fixture_path}/xxx.csv", visible: false
    ```



    * セレクトボックスで選択

    ```ruby
  2. bluerabbit revised this gist Mar 18, 2016. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -101,6 +101,14 @@ page.should have_css("table#table_id tbody tr", count: 0)
    find('#css_selecter').should be_visible
    ```

    * disabledかを検証する


    ```ruby
    expect(page).to have_checked_field '選択肢1', disabled: true
    expect(page).to have_button '登録', disabled: true
    ```

    * テーブルが存在するか

    ```ruby
  3. bluerabbit revised this gist Jul 31, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -112,8 +112,10 @@ should have_table('table')
    ```ruby
    should have_selector('button', value: '実行')
    should have_selector('h1#title', :content=>'Hello!')
    should have_css('#status.current')
    ```


    * ボタンが存在するか

    ```ruby
  4. bluerabbit revised this gist Nov 18, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -92,6 +92,7 @@ should have_field('id_or_label', with: 'value')

    ```ruby
    all('#table_id tr').should have(0).rows
    page.should have_css("table#table_id tbody tr", count: 0)
    ```

    * 表示・非表示の検証をする
  5. bluerabbit revised this gist Oct 16, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -146,12 +146,13 @@ binding.pry
    find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
    ```

    * xpath引数を使ったfind
    * containsを使う事でclassに複数指定があってもヒットする

    ```ruby
    all(:xpath, "//div[contains(@class, 'target-class-name')]")
    all(:xpath, "//a[contains(@class, 'target-class-name') and contains(text(), 'リンク名')]")
    ```

    - containsを使う事でclassに複数指定があってもヒットする

    * findした要素の値をshouldではなく参照する

    ```ruby
  6. bluerabbit revised this gist Oct 16, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -146,6 +146,12 @@ binding.pry
    find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
    ```

    ```ruby
    all(:xpath, "//div[contains(@class, 'target-class-name')]")
    ```

    - containsを使う事でclassに複数指定があってもヒットする

    * findした要素の値をshouldではなく参照する

    ```ruby
  7. bluerabbit revised this gist Oct 9, 2014. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -69,13 +69,19 @@ should have_content '登録されました'
    should have_no_content 'エラーがしました'
    ```

    * チェックボックス(selectboxまたはradio)がチェックされて(いる|いない)
    * チェックボックス(radio)がチェックされて(いる|いない)

    ```ruby
    have_checked_field
    have_unchecked_field
    ```

    * selectの値を検証する

    ```ruby
    page.should have_select('name', selected: 'selected_value')
    ```

    * inputの値を検証する

    ```ruby
  8. bluerabbit revised this gist Jan 8, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -114,6 +114,7 @@ find('#navigation').should have_button('Sign out')
    ```

    * ある要素が表示されているか

    ```ruby
    should have_selector('#hoge_area', visible: true)
    ```
  9. bluerabbit revised this gist Jan 8, 2014. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -113,6 +113,11 @@ should have_selector('h1#title', :content=>'Hello!')
    find('#navigation').should have_button('Sign out')
    ```

    * ある要素が表示されているか
    ```ruby
    should have_selector('#hoge_area', visible: true)
    ```

    ### debug

    * 現在のページをブラウザで表示
  10. bluerabbit revised this gist Dec 26, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -69,7 +69,7 @@ should have_content '登録されました'
    should have_no_content 'エラーがしました'
    ```

    * チェックボックスがチェックされて(いる|いない)
    * チェックボックス(selectboxまたはradio)がチェックされて(いる|いない)

    ```ruby
    have_checked_field
  11. bluerabbit revised this gist Aug 21, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -56,6 +56,12 @@ current_path.should == '/pages/1'
    page.status_code.should be(200)
    ```

    * タイトルタグの検証
    ```ruby
    page.should have_title('たいとる')
    ```


    * ページ内に期待する文字列が(ある|ない)か確認

    ```ruby
  12. bluerabbit revised this gist Aug 14, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -134,6 +134,13 @@ find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
    find('#id').text
    ```

    * ボタンクリックする時にclick_on以外を使う

    ```ruby
    find('#id').click
    click_button 'id_or_label'
    ```

    ### Link

    * http://rubydoc.info/github/jnicklas/capybara/frames
  13. bluerabbit revised this gist Aug 14, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -59,8 +59,8 @@ page.status_code.should be(200)
    * ページ内に期待する文字列が(ある|ない)か確認

    ```ruby
    have_content
    have_no_content
    should have_content '登録されました'
    should have_no_content 'エラーがしました'
    ```

    * チェックボックスがチェックされて(いる|いない)
    @@ -91,14 +91,14 @@ find('#css_selecter').should be_visible
    * テーブルが存在するか

    ```ruby
    page.should have_table('table')
    should have_table('table')
    ```

    * セレクターを使った検証

    ```ruby
    page.should have_selector('button', value: '実行')
    page.should have_selector('h1#title', :content=>'Hello!')
    should have_selector('button', value: '実行')
    should have_selector('h1#title', :content=>'Hello!')
    ```

    * ボタンが存在するか
  14. bluerabbit revised this gist Aug 14, 2013. 1 changed file with 95 additions and 24 deletions.
    119 changes: 95 additions & 24 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -13,56 +13,127 @@ fill_in 'id_or_label_text', with: 'yamada'
    ```

    * ラジオボタンを選択
    * choose 'ラジオボタン1'

    ```ruby
    choose 'ラジオボタン1'
    ```

    * チェックボックスをチェック/非チェック
    * check('チェックボックス1')
    * uncheck('チェックボックス1')

    ```ruby
    check('チェックボックス1')
    uncheck('チェックボックス1')
    ```

    * ファイルの添付
    * attach_file 'file', "#{fixture_path}/xxx.csv"

    ```ruby
    attach_file 'file', "#{fixture_path}/xxx.csv"
    ```

    * セレクトボックスで選択
    * select('カテゴリ1', from: 'カテゴリ')

    ```ruby
    select('カテゴリ1', from: 'カテゴリ')
    ```

    * ボタンまたはリンクをクリック
    * click_on 'ボタンまたはリンク'

    ```ruby
    click_on 'ボタンまたはリンク'
    ```

    ### 検証
    * 現在のページを確認
    * current_path.should == '/pages/1'

    ```ruby
    current_path.should == '/pages/1'
    ```

    * Http Statusを確認
    * page.status_code.should be(200)

    ```ruby
    page.status_code.should be(200)
    ```

    * ページ内に期待する文字列が(ある|ない)か確認
    * have_content
    * have_no_content

    ```ruby
    have_content
    have_no_content
    ```

    * チェックボックスがチェックされて(いる|いない)
    * have_checked_field
    * have_unchecked_field

    ```ruby
    have_checked_field
    have_unchecked_field
    ```

    * inputの値を検証する
    * should have_field('id_or_label', with: 'value')

    ```ruby
    should have_field('id_or_label', with: 'value')
    ```

    * テーブルの行数を検証する
    * all('#table_id tr').should have(0).rows

    ```ruby
    all('#table_id tr').should have(0).rows
    ```

    * 表示・非表示の検証をする
    * find('#css_selecter').should be_visible

    ```ruby
    find('#css_selecter').should be_visible
    ```

    * テーブルが存在するか
    * page.should have_table('table')

    ```ruby
    page.should have_table('table')
    ```

    * セレクターを使った検証
    * page.should have_selector('button', value: '実行')
    * page.should have_selector('h1#title', :content=>'Hello!')

    ```ruby
    page.should have_selector('button', value: '実行')
    page.should have_selector('h1#title', :content=>'Hello!')
    ```

    * ボタンが存在するか
    * find('#navigation').should have_button('Sign out')

    ```ruby
    find('#navigation').should have_button('Sign out')
    ```

    ### debug

    * 現在のページをブラウザで表示
    * save_and_open_page

    ```ruby
    save_and_open_page
    ```

    * debuggerを起動
    * binding.pry

    ```ruby
    binding.pry
    ```

    ### 使ってはイケナイ(?!)
    * xpath引数を使ったfind
    * find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value

    ```ruby
    find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
    ```

    * findした要素の値をshouldではなく参照する
    * find('#id').text

    ```ruby
    find('#id').text
    ```

    ### Link

    * http://rubydoc.info/github/jnicklas/capybara/frames
    * http://rubydoc.info/github/jnicklas/capybara/frames
  15. bluerabbit revised this gist Aug 14, 2013. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,14 @@ visit '/pages/new'
    ```

    * フォームに値を入力
    * ```ruby
    * fill_in 'id_or_label_text', with: 'yamada'
    * ```

    ```ruby
    fill_in 'id_or_label_text', with: 'yamada'
    ```

    * ラジオボタンを選択
    * choose 'ラジオボタン1'

    * チェックボックスをチェック/非チェック
    * check('チェックボックス1')
    * uncheck('チェックボックス1')
  16. bluerabbit revised this gist Aug 14, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,9 @@ visit '/pages/new'
    ```

    * フォームに値を入力
    * ```ruby
    * fill_in 'id_or_label_text', with: 'yamada'
    * ```
    * ラジオボタンを選択
    * choose 'ラジオボタン1'
    * チェックボックスをチェック/非チェック
  17. bluerabbit revised this gist Aug 14, 2013. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,11 @@
    ### 操作

    * ページに移動
    * visit '/pages/new'

    ```ruby
    visit '/pages/new'
    ```

    * フォームに値を入力
    * fill_in 'id_or_label_text', with: 'yamada'
    * ラジオボタンを選択
  18. bluerabbit created this gist Aug 14, 2013.
    59 changes: 59 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    ### 操作

    * ページに移動
    * visit '/pages/new'
    * フォームに値を入力
    * fill_in 'id_or_label_text', with: 'yamada'
    * ラジオボタンを選択
    * choose 'ラジオボタン1'
    * チェックボックスをチェック/非チェック
    * check('チェックボックス1')
    * uncheck('チェックボックス1')
    * ファイルの添付
    * attach_file 'file', "#{fixture_path}/xxx.csv"
    * セレクトボックスで選択
    * select('カテゴリ1', from: 'カテゴリ')
    * ボタンまたはリンクをクリック
    * click_on 'ボタンまたはリンク'

    ### 検証
    * 現在のページを確認
    * current_path.should == '/pages/1'
    * Http Statusを確認
    * page.status_code.should be(200)
    * ページ内に期待する文字列が(ある|ない)か確認
    * have_content
    * have_no_content
    * チェックボックスがチェックされて(いる|いない)
    * have_checked_field
    * have_unchecked_field
    * inputの値を検証する
    * should have_field('id_or_label', with: 'value')
    * テーブルの行数を検証する
    * all('#table_id tr').should have(0).rows
    * 表示・非表示の検証をする
    * find('#css_selecter').should be_visible
    * テーブルが存在するか
    * page.should have_table('table')
    * セレクターを使った検証
    * page.should have_selector('button', value: '実行')
    * page.should have_selector('h1#title', :content=>'Hello!')
    * ボタンが存在するか
    * find('#navigation').should have_button('Sign out')

    ### debug

    * 現在のページをブラウザで表示
    * save_and_open_page
    * debuggerを起動
    * binding.pry

    ### 使ってはイケナイ(?!)
    * xpath引数を使ったfind
    * find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
    * findした要素の値をshouldではなく参照する
    * find('#id').text

    ### Link

    * http://rubydoc.info/github/jnicklas/capybara/frames