Module: PludoniRspec::SystemTestChromeHelper
- Defined in:
- lib/pludoni_rspec/system_test_chrome_helper.rb
Instance Method Summary collapse
- #console_logs ⇒ Object
- #drop_in_dropzone(file_path) ⇒ Object
- #in_browser(name) ⇒ Object
- #local! ⇒ Object
- #screenshot(path = '1') ⇒ Object
-
#skip_confirm(page) ⇒ Object
skip any confirm: “Really delete?”.
-
#wait_until(timeout = 10, &blk) ⇒ Object
wait_until { page.has_content?(“Something”) }.
Instance Method Details
#console_logs ⇒ Object
2 3 4 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
33 34 35 36 37 38 |
# 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 |
#local! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pludoni_rspec/system_test_chrome_helper.rb', line 62 def local! uri = URI.parse(page.current_url) puts "--- Connect with local browser:" puts " 1. Open a SSH tunnel with port forwarding to the test server:" puts "\nssh #{ENV['LOGNAME']}@pludoni.com -L 8080:localhost:#{uri.port}\n" puts " 2. Open in Browser: " uri.port = nil uri.scheme = nil uri.host = nil puts "\nhttp://localhost:8080#{uri}\n" puts " Afterwards, you can close the SSH session" end |
#screenshot(path = '1') ⇒ Object
24 25 26 |
# 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"), full: true) end |
#skip_confirm(page) ⇒ Object
skip any confirm: “Really delete?”
29 30 31 |
# 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, &blk) ⇒ Object
wait_until { page.has_content?(“Something”) }
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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.}" if last_exception raise msg end |