Class: Testcontainers::SeleniumContainer

Inherits:
DockerContainer
  • Object
show all
Defined in:
lib/testcontainers/selenium.rb

Overview

SeleniumContainer class is used to manage containers that runs a automaticates test

Constant Summary collapse

SELENIUM_DEFAULT_PORT =

Default ports used by the container

4444
VNC_DEFAULT_PORT =
5900
SE_VNC_PASSWORD =
1
SELENIUM_IMAGES =

Hash that contains the images for the build of the containers of selenium that runs in the browsers chrome and firefox

{
  firefox: "selenium/standalone-firefox:latest",
  chrome: "selenium/standalone-chrome:latest"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image = nil, capabilities: :firefox, headless: false, vnc_no_password: nil, vnc_password: nil, **kwargs) ⇒ SeleniumContainer

Initializes a new instance of SeleniumContainer

Parameters:

  • image (String) (defaults to: nil)

    is use to define the image for the container

  • capabilities (Symbol) (defaults to: :firefox)

    is use to define the image that are vailable for browser between firefox and chrome

  • port (String)

    is use to define the connection port for the container for Selenium

  • kwargs (Hash)

    the options to pass to the container. See DockerContainer#initialize



26
27
28
29
30
31
32
33
# File 'lib/testcontainers/selenium.rb', line 26

def initialize(image = nil, capabilities: :firefox, headless: false, vnc_no_password: nil, vnc_password: nil, **kwargs)
  image ||= SELENIUM_IMAGES[capabilities]
  super(image, **kwargs)
  @vnc_password = vnc_password
  @vnc_no_password = vnc_no_password
  @headless = headless
  @wait_for ||= add_wait_for(:logs, /Started Selenium/)
end

Instance Attribute Details

#headlessObject (readonly)

Returns the value of attribute headless.



19
20
21
# File 'lib/testcontainers/selenium.rb', line 19

def headless
  @headless
end

Instance Method Details

#portInteger

Returns the port used by the container

Returns:

  • (Integer)

    the port used by the container



45
46
47
# File 'lib/testcontainers/selenium.rb', line 45

def port
  SELENIUM_DEFAULT_PORT
end

#selenium_url(protocol: "http://") ⇒ String

Returns the selenium connection url (e.g host:port/wd/hub)

Parameters:

  • protocol (String) (defaults to: "http://")

    the protocol to use in the string (default: “http://”)

Returns:

  • (String)

    the url used by the container



58
59
60
# File 'lib/testcontainers/selenium.rb', line 58

def selenium_url(protocol: "http://")
  "#{protocol}#{host}:#{mapped_port(port)}/wd/hub"
end

#startSeleniumContainer

Starts the container

Returns:



37
38
39
40
41
# File 'lib/testcontainers/selenium.rb', line 37

def start
  with_exposed_ports([port, vnc_port])
  _configure
  super
end

#vnc_portInteger

Returns the port used by the container of vnc.

Returns:

  • (Integer)

    the port used by the container of vnc



50
51
52
# File 'lib/testcontainers/selenium.rb', line 50

def vnc_port
  VNC_DEFAULT_PORT
end