module PludoniRspec::SystemTestChromeHelper

Public Instance Methods

console_logs() click to toggle source
# File lib/pludoni_rspec/system_test_chrome_helper.rb, line 2
def console_logs
  page.driver.browser.manage.logs.get(:browser)
end
drop_in_dropzone(file_path) click to toggle source
# File lib/pludoni_rspec/system_test_chrome_helper.rb, line 6
  def drop_in_dropzone(file_path)
    # Generate a fake input selector
    page.execute_script <<-JS
    fakeFileInput = window.$('<input/>').attr(
      {id: 'fakeFileInput', type:'file'}
    ).appendTo('body');
    JS
    # Attach the file to the fake input selector
    attach_file("fakeFileInput", file_path)
    # Add the file to a fileList array
    page.execute_script("var fileList = [fakeFileInput.get(0).files[0]]")
    # Trigger the fake drop event
    page.execute_script <<-JS
    var e = jQuery.Event('drop', { dataTransfer : { files : [fakeFileInput.get(0).files[0]] } });
    $('.uploader-action')[0].dropzone.listeners[0].events.drop(e);
    JS
  end
in_browser(name) { || ... } click to toggle source
# File lib/pludoni_rspec/system_test_chrome_helper.rb, line 33
def in_browser(name)
  old_session = Capybara.session_name
  Capybara.session_name = name
  yield
  Capybara.session_name = old_session
end
screenshot(path = '1') click to toggle source
# File lib/pludoni_rspec/system_test_chrome_helper.rb, line 24
def screenshot(path = '1')
  page.save_screenshot(Rails.root.join("public/screenshots/#{path}.png"))
end
skip_confirm(page) click to toggle source

skip any confirm: “Really delete?”

# File lib/pludoni_rspec/system_test_chrome_helper.rb, line 29
def skip_confirm(page)
  page.evaluate_script('window.confirm = function() { return true; }')
end
wait_until(timeout = 10) { || ... } click to toggle source

wait_until { page.has_content?(“Something”) }

# File lib/pludoni_rspec/system_test_chrome_helper.rb, line 41
def wait_until(timeout = 10, &blk)
  end_time       = Time.zone.now + timeout
  last_exception = nil

  until Time.zone.now >= end_time
    begin
      result = yield
      return result if result
    rescue RSpec::Expectations::ExpectationNotMetError => ex
      last_exception = ex
    end

    sleep 0.01
  end

  msg = "timed out after #{timeout} seconds"
  msg << ":\n#{last_exception.message}" if last_exception

  raise msg
end