class Marta::OptionsAndPaths::SettingMaster

We are storing vars in a special class

@note It is believed that no user will use it

Public Class Methods

base_url() click to toggle source

Marta knows what web application she is trying to test

# File lib/marta/options_and_paths.rb, line 80
def self.base_url
  @@base_url[thread_id]
end
clear() click to toggle source
# File lib/marta/options_and_paths.rb, line 26
def self.clear
  @@folder[thread_id] = nil
  @@tolerancy[thread_id] = nil
  @@learn[thread_id] = nil
  if @@engine[thread_id].class == Watir::Browser
    @@engine[thread_id].quit
  end
  @@engine[thread_id] = nil
  @@base_url[thread_id] = nil
  @@cold_timeout[thread_id] = nil
  @@port[thread_id]
  @@port[thread_id] = nil
  @@server[thread_id]
  if @@server[thread_id].class == Marta::Server::MartaServer
    @@server[thread_id].server_kill
  end
  @@server[thread_id] = nil
end
cold_timeout() click to toggle source

Time setting for Marta. She will wait that time before active search

# File lib/marta/options_and_paths.rb, line 85
def self.cold_timeout
  @@cold_timeout[thread_id]
end
engine() click to toggle source

engine (analog of browser) is a setting too

# File lib/marta/options_and_paths.rb, line 75
def self.engine
  @@engine[thread_id]
end
gem_libdir() click to toggle source

Marta knows where is she actually is.

# File lib/marta/options_and_paths.rb, line 205
def self.gem_libdir
  t = ["#{Dir.pwd}/lib/#{Marta::NAME}",
       "#{Gem.dir}/gems/#{Marta::NAME}-#{Marta::VERSION}/lib/#{Marta::NAME}"]
  File.readable?(t[0])? t[0] : t[1]
end
iframe_locate() click to toggle source

Marta locates iframes sometimes

# File lib/marta/options_and_paths.rb, line 107
def self.iframe_locate
  if !engine.nil?
    if engine.class == Watir::IFrame
      engine.locate
    end
  end
end
iframe_switch_to() click to toggle source

Marta is switching to iframes sometimes

# File lib/marta/options_and_paths.rb, line 116
def self.iframe_switch_to
  if !engine.nil?
    if engine.class == Watir::IFrame
      engine.switch_to!
    end
  end
end
learn_option() click to toggle source

Checking default learn option status

# File lib/marta/options_and_paths.rb, line 51
def self.learn_option
  ENV['LEARN'].nil? ? false : true
end
learn_status() click to toggle source

Marta knows does she learn or not.

# File lib/marta/options_and_paths.rb, line 56
def self.learn_status
  if @@learn[thread_id].nil?
    learn_option
  else
    @@learn[thread_id]
  end
end
pageobjects_folder() click to toggle source

Marta knows where are her saved generated pageobjects

# File lib/marta/options_and_paths.rb, line 65
def self.pageobjects_folder
  @@folder[thread_id]
end
parameter_check_and_set(where, value, default, expected_class) click to toggle source
# File lib/marta/options_and_paths.rb, line 164
def self.parameter_check_and_set(where, value, default, expected_class)
  if (value.nil?) or (value.class == expected_class)
    where = parameter_set(where, value, default)
  else
    raise ArgumentError, "The value should be a #{expected_class}."\
                         " Not a #{value}:#{value.class}"
  end
end
parameter_set(what, value, default) click to toggle source

Marta is changing parameters by the same scheme.

# File lib/marta/options_and_paths.rb, line 100
def self.parameter_set(what, value, default)
  what[thread_id] = !value.nil? ? value : what[thread_id]
  what[thread_id] = what[thread_id].nil? ? default : what[thread_id]
  what
end
port() click to toggle source

Marta knows the server port.

# File lib/marta/options_and_paths.rb, line 90
def self.port
  @@port[thread_id]
end
server() click to toggle source

Marta stores the server as a setting.

# File lib/marta/options_and_paths.rb, line 95
def self.server
  @@server[thread_id]
end
set_base_url(value) click to toggle source

Marta uses a simple rule to set the basic url.

# File lib/marta/options_and_paths.rb, line 174
def self.set_base_url(value)
  parameter_check_and_set(@@base_url, value, "", String)
end
set_cold_timeout(value) click to toggle source

Marta uses simple rule to set the cold timeout

# File lib/marta/options_and_paths.rb, line 179
def self.set_cold_timeout(value)
  parameter_check_and_set(@@cold_timeout, value, 10, Integer)
end
set_engine(value) click to toggle source

Marta is setting engine by pretty comlex rules

# File lib/marta/options_and_paths.rb, line 125
def self.set_engine(value)
  if (engine.class == Watir::Browser) and
     (value.class == Watir::Browser) and
     (engine != value)
       engine.quit if engine.exists?
  end
  iframe_locate
  @@engine = parameter_set(@@engine, value, nil)
  iframe_switch_to
  if engine.nil?
    browser = Watir::Browser.new(:chrome,
              switches: ["--load-extension=#{gem_libdir}/marta_app"])
              browser.goto "127.0.0.1:#{SettingMaster.port}/welcome"
    @@engine = parameter_set(@@engine, value, browser)
  end
end
set_folder(value) click to toggle source

Marta uses simple rules to set the folder

# File lib/marta/options_and_paths.rb, line 143
def self.set_folder(value)
  @@folder = parameter_set(@@folder, value, 'Marta_s_pageobjects')
end
set_learn(value) click to toggle source

Marta uses simple rules to set the laearn mode

# File lib/marta/options_and_paths.rb, line 148
def self.set_learn(value)
  @@learn = parameter_set(@@learn, value, learn_option)
  if learn_status
    warn "Be carefull. If browser was not started by Marta."\
    " Learn mode will not work properly"
  else
    # We are switching server off if we do not really need it
    SettingMaster.server.server_kill
  end
end
set_port(value) click to toggle source

Marta sets port. If it is not defined and there are number of threads Marta will use ports from 6260 one by one (6260, 6261, 6262,…)

# File lib/marta/options_and_paths.rb, line 185
def self.set_port(value)
  i = 0
  if value.nil?
    while Server::MartaServer.port_check(6260 + @@port.size + i)
      i += 1
    end
  end
  parameter_check_and_set(@@port, value, 6260 + @@port.size + i, Integer)
end
set_server() click to toggle source

We are storaging server instance as a setting

# File lib/marta/options_and_paths.rb, line 196
def self.set_server
  if SettingMaster.server.nil?
    @@server[thread_id] = Server::MartaServer.new(SettingMaster.port)
  elsif !Server::MartaServer.port_check(SettingMaster.port)
    @@server[thread_id] = Server::MartaServer.new(SettingMaster.port)
  end
end
set_tolerancy(value) click to toggle source

Marta uses simple rules to set the tolerancy value

# File lib/marta/options_and_paths.rb, line 160
def self.set_tolerancy(value)
  @@tolerancy = parameter_set(@@tolerancy, value, 100000)
end
thread_id() click to toggle source

Getting uniq id for process thread

# File lib/marta/options_and_paths.rb, line 46
def self.thread_id
  Thread.current.object_id
end
tolerancy_value() click to toggle source

Marta knows how hard she should search for elements

# File lib/marta/options_and_paths.rb, line 70
def self.tolerancy_value
  @@tolerancy[thread_id]
end