module Utils
Public Instance Methods
I18n_first(text)
click to toggle source
# File lib/cuculungwa/utils.rb, line 38 def I18n_first(text) text = I18n.t(text, raise: I18n::MissingTranslationData) return text rescue I18n::MissingTranslationData return text end
click(element)
click to toggle source
# File lib/cuculungwa/utils.rb, line 2 def click(element) if @app.config['capybara']['browser'] == 'phantomjs' element.trigger('click') else element.click end end
finished_all_ajax_requests?()
click to toggle source
# File lib/cuculungwa/utils.rb, line 52 def finished_all_ajax_requests? page.evaluate_script('jQuery.active').zero? end
set_app(app)
click to toggle source
# File lib/cuculungwa/utils.rb, line 10 def set_app(app) Capybara.app_host = @app.config['project']['default_host'][app] end
set_environment_and_app(environment, app)
click to toggle source
# File lib/cuculungwa/utils.rb, line 14 def set_environment_and_app(environment, app) Capybara.app_host = @app.config['project'][environment][app] end
wait_for_ajax()
click to toggle source
# File lib/cuculungwa/utils.rb, line 45 def wait_for_ajax sleep 1 Timeout.timeout(Capybara.default_wait_time, Timeout::Error) do loop until finished_all_ajax_requests? end end
wait_for_expected_result(timespan = @app.config['capybara']['default_wait_time'], exception_type = RSpec::Expectations::ExpectationNotMetError) { || ... }
click to toggle source
# File lib/cuculungwa/utils.rb, line 18 def wait_for_expected_result(timespan = @app.config['capybara']['default_wait_time'], exception_type = RSpec::Expectations::ExpectationNotMetError) # Default setting: get default wait time from config.yml start_time = Time.now loop do begin yield break rescue exception_type => e # Expectations were not met, check if we timed out, otherwise try one more time after 10ms if Time.now > start_time + timespan puts 'Timeout.' raise e end sleep 0.01 end end # for debug purpose # puts "Waiting for expected result took #{Time.now - _then}s." end