by
3 7
0
4
1,441
0
Top 1% !
Popular
Famous
Specified
Created
Modified Nov 10, 2016

Published on:

No tags for this snippet yet.
BrowserChrome
LanguageRuby
SourceGitHub
SourceMyGists

cucumber setup with docker chrome standalone

cucumber setup with docker chrome standalone: 
driver.rb
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/2897452/cucumber-setup-with-docker-chrome-standa?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
require 'selenium/webdriver' ### # Important details: # - Capybara server is run on the host container at 0.0.0.0:4100 # - Test code determines the host's advertised IP address e.g. 172.1.1.1 # - Capybara Instructions execute on selenium/standalone-chrome container via api call to http://127.0.0.1:4444/wd/hub and gives it urls such as http://dummy.com.172.1.1.1.nip.io:4100 to visit the server on the host container. # - This works on an OSX host with manually running the selenium container with docker run -p 4444:4444 selenium/standalone-chrome:3.0.1-germanium # # # Interaction (host ip 172.1.1.1) # - host api call to selenium -> http://127.0.0.1:4444/wd/hub # - selenium browser visit -> 172.1.1.1:4100 # $remote = true $browser = :chrome # $browser = :firefox $wait_time = 5 $default_driver = :selenium # establish capabilities desired_capabilities = begin if $browser == :firefox Selenium::WebDriver::Remote::Capabilities.firefox(loggingPrefs: {browser: 'ALL'}) else # Tell selenium we want all messages by default - we'll sort them out with our own +ConsoleMessages+ class prefs = { # http://peter.sh/experiments/chromium-command-line-switches/ # No change with the following # ---------------------------------- # --js-flags="--max-old-space-size=500" # --disable-backing-store-limit # --diagnostics # --disable-extensions # --enable-leak-detection --crash-on-failure # Not yet tried but might be interesting # --------------------------------------- # --diagnostics # --disable-background-networking # --disable-background-timer-throttling # --disable-backing-store-limit # switches: %w(--disable-notifications --enable-leak-detection --crash-on-failure), loggingPrefs: { browser: 'ALL' #, # performance: 'ALL' }, chromeOptions: { prefs: { credentials_enable_service: false, # disable saved passwords profile: { password_manager_enabled: false # disable saved passwords } } } } Selenium::WebDriver::Remote::Capabilities.chrome(prefs) end end # For debugging selenium itself: # Selenium::WebDriver.logger.level = :debug if $remote == true # http://stackoverflow.com/questions/35821718/how-to-configure-capybara-to-run-tests-in-a-dockerized-selenium-grid Capybara.register_driver $default_driver do |app| # noinspection RubyArgCount Capybara::Selenium::Driver.new(app, { browser: :remote, url: 'http://127.0.0.1:4444/wd/hub', # selenium hub accessible url desired_capabilities: desired_capabilities }) end else # Register chrome browser for the :selenium driver, can be triggered below with @show Capybara.register_driver $default_driver do |app| # noinspection RubyArgCount Capybara::Selenium::Driver.new(app, { browser: $browser, desired_capabilities: desired_capabilities }) end end # Make the server available on the network. default is 127.0.0.1 which is private Capybara.server_host = '0.0.0.0' Capybara.server_port = 4100 Capybara.server = :puma cuke_log "Capybara running on #{Capybara.server_host}:#{Capybara.server_port} Process: #{Process.pid}" ENV['CIRCLE_NODE_INDEX'] = '9' unless ENV['CIRCLE_NODE_INDEX'].presence # default the node for local testing # first time around, we need this set. Capybara.default_driver = $default_driver Capybara.default_max_wait_time = $wait_time # # If the @show tag is present on a non-mac environment, ignore it, # otherwise allow the combination of @javascript @show to trigger the # :selenium driver (which is :chrome browser as configured above) # Before do |scenario| @scenario = scenario raise 'Scenario should not have @javascript tag, it really messes up truncation' if has_tag(scenario, '@javascript') # reset the default driver Capybara.current_driver = $default_driver Capybara.javascript_driver = $default_driver Capybara.default_max_wait_time = $wait_time # reset in case a scenario upped it # OLD, but if we need to exec a script to clear storage or cache, do it here. # page.driver.execute_script('window.localStorage.clear()') if should_show(scenario) # for some reason, just using the `using_driver` doesn't get us all the way there, so set/reset the `javascript_driver` as necessary. Capybara.current_driver = :selenium Capybara.javascript_driver = :selenium # needed for @show with chrome, as it doesn't seem to explicitly set the javascript driver end # cuke_log "Using #{Capybara.current_driver}/#{Capybara.javascript_driver}/#{Capybara.default_driver} wait: #{Capybara.default_max_wait_time}" end After do |scenario| # problem on @show with backgrounds: https://github.com/cucumber/cucumber/issues/52 # cuke_log "Done #{Capybara.current_driver}/#{Capybara.javascript_driver}/#{Capybara.default_driver} - resetting driver and sessions." Capybara.use_default_driver Capybara.reset_sessions! end def selenium? Capybara.current_driver == :selenium end
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus