Class: Marta::OptionsAndPaths::SettingMaster
- Inherits:
-
Object
- Object
- Marta::OptionsAndPaths::SettingMaster
- Defined in:
- lib/marta/options_and_paths.rb
Overview
It is believed that no user will use it
We are storing vars in a special class
Constant Summary collapse
- @@folder =
Hash.new
- @@tolerancy =
Hash.new
- @@learn =
Hash.new
- @@engine =
Hash.new
- @@base_url =
Hash.new
- @@cold_timeout =
Hash.new
- @@port =
Hash.new
- @@server =
Hash.new
Class Method Summary collapse
-
.base_url ⇒ Object
Marta knows what web application she is trying to test.
- .clear ⇒ Object
-
.cold_timeout ⇒ Object
Time setting for Marta.
-
.engine ⇒ Object
engine (analog of browser) is a setting too.
-
.gem_libdir ⇒ Object
Marta knows where is she actually is.
-
.iframe_locate ⇒ Object
Marta locates iframes sometimes.
-
.iframe_switch_to ⇒ Object
Marta is switching to iframes sometimes.
-
.learn_option ⇒ Object
Checking default learn option status.
-
.learn_status ⇒ Object
Marta knows does she learn or not.
-
.pageobjects_folder ⇒ Object
Marta knows where are her saved generated pageobjects.
- .parameter_check_and_set(where, value, default, expected_class) ⇒ Object
-
.parameter_set(what, value, default) ⇒ Object
Marta is changing parameters by the same scheme.
-
.port ⇒ Object
Marta knows the server port.
-
.server ⇒ Object
Marta stores the server as a setting.
-
.set_base_url(value) ⇒ Object
Marta uses a simple rule to set the basic url.
-
.set_cold_timeout(value) ⇒ Object
Marta uses simple rule to set the cold timeout.
-
.set_engine(value) ⇒ Object
Marta is setting engine by pretty comlex rules.
-
.set_folder(value) ⇒ Object
Marta uses simple rules to set the folder.
-
.set_learn(value) ⇒ Object
Marta uses simple rules to set the laearn mode.
-
.set_port(value) ⇒ Object
Marta sets port.
-
.set_server ⇒ Object
We are storaging server instance as a setting.
-
.set_tolerancy(value) ⇒ Object
Marta uses simple rules to set the tolerancy value.
-
.thread_id ⇒ Object
Getting uniq id for process thread.
-
.tolerancy_value ⇒ Object
Marta knows how hard she should search for elements.
Class Method Details
.base_url ⇒ Object
Marta knows what web application she is trying to test
80 81 82 |
# File 'lib/marta/options_and_paths.rb', line 80 def self.base_url @@base_url[thread_id] end |
.clear ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 ⇒ Object
Time setting for Marta. She will wait that time before active search
85 86 87 |
# File 'lib/marta/options_and_paths.rb', line 85 def self.cold_timeout @@cold_timeout[thread_id] end |
.engine ⇒ Object
engine (analog of browser) is a setting too
75 76 77 |
# File 'lib/marta/options_and_paths.rb', line 75 def self.engine @@engine[thread_id] end |
.gem_libdir ⇒ Object
Marta knows where is she actually is.
205 206 207 208 209 |
# 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 ⇒ Object
Marta locates iframes sometimes
107 108 109 110 111 112 113 |
# 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 ⇒ Object
Marta is switching to iframes sometimes
116 117 118 119 120 121 122 |
# 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 ⇒ Object
Checking default learn option status
51 52 53 |
# File 'lib/marta/options_and_paths.rb', line 51 def self.learn_option ENV['LEARN'].nil? ? false : true end |
.learn_status ⇒ Object
Marta knows does she learn or not.
56 57 58 59 60 61 62 |
# 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 ⇒ Object
Marta knows where are her saved generated pageobjects
65 66 67 |
# 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) ⇒ Object
164 165 166 167 168 169 170 171 |
# 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) ⇒ Object
Marta is changing parameters by the same scheme.
100 101 102 103 104 |
# 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 ⇒ Object
Marta knows the server port.
90 91 92 |
# File 'lib/marta/options_and_paths.rb', line 90 def self.port @@port[thread_id] end |
.server ⇒ Object
Marta stores the server as a setting.
95 96 97 |
# File 'lib/marta/options_and_paths.rb', line 95 def self.server @@server[thread_id] end |
.set_base_url(value) ⇒ Object
Marta uses a simple rule to set the basic url.
174 175 176 |
# 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) ⇒ Object
Marta uses simple rule to set the cold timeout
179 180 181 |
# 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) ⇒ Object
Marta is setting engine by pretty comlex rules
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# 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) ⇒ Object
Marta uses simple rules to set the folder
143 144 145 |
# 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) ⇒ Object
Marta uses simple rules to set the laearn mode
148 149 150 151 152 153 154 155 156 157 |
# 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) ⇒ Object
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,…)
185 186 187 188 189 190 191 192 193 |
# 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 ⇒ Object
We are storaging server instance as a setting
196 197 198 199 200 201 202 |
# 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) ⇒ Object
Marta uses simple rules to set the tolerancy value
160 161 162 |
# File 'lib/marta/options_and_paths.rb', line 160 def self.set_tolerancy(value) @@tolerancy = parameter_set(@@tolerancy, value, 100000) end |
.thread_id ⇒ Object
Getting uniq id for process thread
46 47 48 |
# File 'lib/marta/options_and_paths.rb', line 46 def self.thread_id Thread.current.object_id end |
.tolerancy_value ⇒ Object
Marta knows how hard she should search for elements
70 71 72 |
# File 'lib/marta/options_and_paths.rb', line 70 def self.tolerancy_value @@tolerancy[thread_id] end |