Class: MixpanelTesting::DockerProvider
- Inherits:
-
Object
- Object
- MixpanelTesting::DockerProvider
- Defined in:
- lib/mixpaneltesting/docker.rb
Instance Method Summary collapse
-
#initialize(browser, version = nil, debug = false) ⇒ DockerProvider
constructor
A new instance of DockerProvider.
- #kill ⇒ Object
- #open_vnc ⇒ Object
- #ready? ⇒ Boolean
- #selenium_uri ⇒ Object
- #start ⇒ Object
- #vnc_uri ⇒ Object
Constructor Details
#initialize(browser, version = nil, debug = false) ⇒ DockerProvider
Returns a new instance of DockerProvider.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mixpaneltesting/docker.rb', line 13 def initialize(browser, version=nil, debug=false) if !['firefox', 'chrome'].include?(browser) raise DockerProviderBrowserNotAvailable, "#{browser} not available" end @log = Logger.new(STDOUT) @docker_uri = URI(ENV['DOCKER_HOST']) @browser = browser @debug = debug @version = version.nil? ? "" : ":#{version}" @image_name = (@debug ? "selenium/standalone-#{@browser}-debug#{@version}" : "selenium/standalone-#{@browser}#{@version}") @threads = [] @log.info ["Creating selenium docker, if you don't see Docker started", "message, try to remove mixpaneltesting docker with:", "docker rm -rf mixpaneltesting"].join('/n') # This settings is fully wired for boot2docker/docker-machines # We should change this to make compatible with other @container = Docker::Container.create( 'Image' => @image_name, 'name' => 'mixpaneltesting', # Name given for helping with debug 'ExposedPorts' => { '4444/tcp' => {}, '5900/tcp' => {}, }, 'HostConfig' => { 'PortBindings' => { '4444/tcp' => [{ 'HostPort' => '4444'}], # Selenium Port '5900/tcp' => [{ 'HostPort' => '5900'}], # VNC Port for everyone } } ) end |
Instance Method Details
#kill ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/mixpaneltesting/docker.rb', line 64 def kill @container.kill! @container.delete(:force => true) @threads.each { |thr| @log.info "Killing thread" thr.exit } end |
#open_vnc ⇒ Object
87 88 89 90 91 |
# File 'lib/mixpaneltesting/docker.rb', line 87 def open_vnc @threads.push Thread.new { `open #{vnc_uri}` } end |
#ready? ⇒ Boolean
74 75 76 77 |
# File 'lib/mixpaneltesting/docker.rb', line 74 def ready? puts selenium_uri Excon.get(selenium_uri).status == 302 rescue false end |
#selenium_uri ⇒ Object
79 80 81 |
# File 'lib/mixpaneltesting/docker.rb', line 79 def selenium_uri "http://#{@docker_uri.host}:4444/wd/hub" end |
#start ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mixpaneltesting/docker.rb', line 51 def start @container.start (1..Settings.timeout).each { |i| sleep 1 @log.info "Waiting to docker ready: #{i}" break if ready? } @log.info "Docker started" open_vnc if @debug end |
#vnc_uri ⇒ Object
83 84 85 |
# File 'lib/mixpaneltesting/docker.rb', line 83 def vnc_uri "vnc://:secret@#{@docker_uri.host}:5900" end |