Module: Spree::Backend::TestingSupport::CapybaraUtils
- Defined in:
- lib/spree/backend/testing_support/capybara_utils.rb
Instance Method Summary collapse
- #click_icon(type) ⇒ Object
- #column_text(num) ⇒ Object
- #disable_html5_validation ⇒ Object
- #wait_for(options = {}, &block) ⇒ Object
-
#wait_for_ajax(delay = Capybara.default_max_wait_time) ⇒ Object
delay in seconds.
- #wait_for_turbo(timeout = nil) ⇒ Object
- #wait_for_turbo_frame(selector = 'turbo-frame', timeout = nil) ⇒ Object
- #within_row(num, &block) ⇒ Object
Instance Method Details
#click_icon(type) ⇒ Object
5 6 7 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 5 def click_icon(type) first(".icon-#{type}").click end |
#column_text(num) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 17 def column_text(num) if RSpec.current_example.[:js] find("td:nth-child(#{num})").text else all('td')[num - 1].text end end |
#disable_html5_validation ⇒ Object
45 46 47 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 45 def disable_html5_validation page.execute_script('for(var f=document.forms,i=f.length;i--;)f[i].setAttribute("novalidate",i)') end |
#wait_for(options = {}, &block) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 49 def wait_for( = {}, &block) = { error: nil, seconds: 5 }.merge() Selenium::WebDriver::Wait.new(timeout: [:seconds]).until(&block) rescue Selenium::WebDriver::Error::TimeoutError [:error].nil? ? false : raise([:error]) end |
#wait_for_ajax(delay = Capybara.default_max_wait_time) ⇒ Object
delay in seconds
26 27 28 29 30 31 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 26 def wait_for_ajax(delay = Capybara.default_max_wait_time) Timeout.timeout(delay) do active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active') active = page.evaluate_script('typeof jQuery !== "undefined" && jQuery.active') until active.nil? || active.zero? end end |
#wait_for_turbo(timeout = nil) ⇒ Object
33 34 35 36 37 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 33 def wait_for_turbo(timeout = nil) if has_css?('.turbo-progress-bar', visible: true, wait: 1.seconds) has_no_css?('.turbo-progress-bar', wait: timeout.presence || 5.seconds) end end |
#wait_for_turbo_frame(selector = 'turbo-frame', timeout = nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 39 def wait_for_turbo_frame(selector = 'turbo-frame', timeout = nil) if has_selector?("#{selector}[busy]", visible: true, wait: 1.seconds) has_no_selector?("#{selector}[busy]", wait: timeout.presence || 5.seconds) end end |
#within_row(num, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/spree/backend/testing_support/capybara_utils.rb', line 9 def within_row(num, &block) if RSpec.current_example.[:js] within("table.table tbody tr:nth-child(#{num})", match: :first, &block) else within(all('table.table tbody tr')[num - 1], &block) end end |