2017-04-04 1 views
0

これはRspec機能です。Capybara/RspecがSweet Alert Modalでボタンを見つけることができないのにhas_selectorがtrueを返すのはなぜですか?

given (:send_selector){ 'button.confirm'} 

feature "when talent has not applied." do 
    given (:apply_button) { find('button[data-selector="offer-apply-button"]') } 
    before(:each)   { visit offer_path(offer.id)       } 

    scenario "Talent applies to offer with default cv", js: true do 
    apply_button.click 
    expect(page).to have_selector(send_selector) 
    find_button(send_selector).click 
    wait_for_ajax 
    # other expectations 
    end 
end 

これはセレクタを有することが期待を通過するが、それは私もまだpage.find_button(send_selector).clickfind_button(send_selector).trigger('click')を使用して試みたが、最初のfind_button(send_selector).click

有する線に指向誤差

Capybara::ElementNotFound: 
     Unable to find button "button.confirm" 

をスローエラーをスローし、次のliでスクリーンショットをとると、アクションを担当するコントローラが呼び出されず、モーダルがまだ残っているため、2番目のものは何もしないようですne。

私はpoltergeistデバッガを実行し、そのページにはhtmlがあります。

html code from the poltergeist debugger

カピバラから見たように、これは(save_screenshot()メソッドを使用して)モーダルで

enter image description here

答えて

0

場合、誰かに同じ問題を抱えている、それはモーダル後に少し睡眠を追加するだけで正常に動作現れます。この動作は、セレクタがそこにalredyであると期待されているので、まだ不思議です。たとえhave_selector(send_selector, visible: true).present?でもtrueを返します。 http://www.rubydoc.info/gems/capybara/Capybara/Node/Finders#find_button-instance_method - -

scenario "Talent applies to offer with default cv", js: true do 
    apply_button.click 
    expect(page).to have_selector(send_selector) 
    sleep 1          <<-- THIS SOLVED THE PROBLEM 
    find(send_selector).click 
    wait_for_ajax 
    ... 
end 
1

問題はfind_buttonはCSSセレクタを取らないということです、それは(click_buttonと同じと「have_button」かかります)ボタンの名前、ID、タイトル、またはテキストコンテンツを取ります。あなたの答えsleep 1

あなたがsweetalert2を使用した場合

+0

こんにちはトーマス、あなたは正しい、find_buttonはcssセレクタを取らない。それでも、私はこの時間に「スリープ1」なしで投稿したテストを実行し、失敗しました。 – juliangonzalez

+0

@juliangonzalez同じエラーの場合は、おそらくCapybara.default_max_wait_timeを数秒増やす必要があることを意味します。しかし、別のエラー(マウスクリックに関する何かが別の要素に当たった場合)は、モーダルがまだアニメーション化されているので、テストモードでアニメーションを無効にするかスリープ状態にする必要があります。多少の傷みを防ぐ –

0

は、私もその問題に直面したCSSセレクタを取るんfindfind_buttonからスワップので、それが修正された問題を解決するとは何の関係もなかったし、私はそれを解決しました以下のような特徴を持つ。 (それは働いた)

scenario 'destroy a company', js: true do 
    within('.shadow.company-info') do 
     find('a[data-behavior="delete"]').click 
     wait_for_ajax 
     within(page.document.find(:css, '.swal2-buttonswrapper')) do 
      find(:css, '.swal2-confirm').click 
      wait_for_ajax 
      expect(page.document).to have_content I18n.t('delete.success') 
     end 
    end 
end 
関連する問題