lib/rspeckled/plugins/capybara.rb in rspeckled-0.0.30 vs lib/rspeckled/plugins/capybara.rb in rspeckled-0.0.31
- old
+ new
@@ -1,6 +1,7 @@
# frozen_string_literal: true
+
##############################################################################
# Capybara Plugin
##############################################################################
#
# This plugin does not attempt to require capybara. It assumes that if you're
@@ -19,25 +20,81 @@
if defined?(Capybara::Driver::Base)
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
- Capybara.javascript_driver = if defined?(Capybara::Webkit)
- :webkit
- else
- :selenium
- end
+ Capybara.register_driver :firefox do |app|
+ Capybara::Selenium::Driver.new(app, :browser => :firefox)
+ end
+ if defined?(Selenium::WebDriver)
+ Selenium::WebDriver.logger.output = 'log/selenium.log'
+ end
+
+ if defined?(Capybara::Webkit)
+ Capybara.javascript_driver = :webkit
+
+ Capybara::Webkit.configure do |config|
+ config.block_unknown_urls
+ config.skip_image_loading
+
+ config.allow_url('*.lvh.me')
+ config.allow_url('*.cloudfront.net')
+ config.allow_url('*.s3.amazonaws.com')
+
+ if defined?(Chamber)
+ config.allow_url("*.#{Chamber.env.http.host}")
+ config.allow_url("*.#{Chamber.env.http.web_client_domain}")
+ end
+ end
+ else
+ Capybara.javascript_driver = :selenium
+ end
+
RSpec.configure do |config|
config.before(:each, :js => true) do
page.driver.reset!
end
+
+ config.before(:each, :js => true, :autofocus => true) do
+ Thread.new do
+ sleep 1.5
+
+ `
+ osascript -e '
+ tell the application named "Firefox"
+ activate
+
+ set theWindow to the first item of windows
+
+ if index of theWindow is not 1 then
+ set index to 1
+ set visible to false
+ set visible to true
+ end if
+ end tell
+ ' > /dev/null
+ `
+ end
+ end
+
+ config.after(:each, :js => true, :autofocus => true) do
+ sleep 10
+ end
+
+ config.before(:each, :js => true, :feature => true, :debug => true) do
+ Selenium::WebDriver.logger.level = :debug if defined?(Selenium::WebDriver)
+ end
+
+ config.after(:each, :js => true, :feature => true, :debug => true) do
+ Selenium::WebDriver.logger.level = :warn if defined?(Selenium::WebDriver)
+ end
end
Capybara.configure do |config|
- config.block_unknown_urls
- config.match = :prefer_exact
+ config.exact = true
+ config.match = :one
config.ignore_hidden_elements = true
config.visible_text_only = true
end
if defined?(Chamber)
@@ -46,5 +103,6 @@
Capybara.server_port = Chamber.env.http.port
end
end
rescue LoadError
end
+# rubocop:enable Style/SymbolProc