Class: Scoutui::Commands::Utils
- Inherits:
-
Object
- Object
- Scoutui::Commands::Utils
- Includes:
- Singleton
- Defined in:
- lib/scoutui/commands/utils.rb
Instance Attribute Summary collapse
-
#hwnds ⇒ Object
Returns the value of attribute hwnds.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#totalCommands ⇒ Object
Returns the value of attribute totalCommands.
-
#useFrameSearch ⇒ Object
Returns the value of attribute useFrameSearch.
Instance Method Summary collapse
- #enableFrameSearch ⇒ Object
- #expandMacro(_text_to_type) ⇒ Object
- #getFrameSearch ⇒ Object
- #getTimeout ⇒ Object
-
#initialize ⇒ Utils
constructor
A new instance of Utils.
- #isAssignments?(_action) ⇒ Boolean
- #isAssignVar?(_action) ⇒ Boolean
- #isClick?(_action) ⇒ Boolean
- #isConnect?(_action) ⇒ Boolean
- #isCSS(_locator) ⇒ Object
- #isDefineCommands?(_action) ⇒ Boolean
- #isDumpVars?(_action) ⇒ Boolean
- #isExecuteCommands?(_action) ⇒ Boolean
- #isExistsAlert?(_action) ⇒ Boolean
- #isFillForm?(_action) ⇒ Boolean
- #isFrame?(_action) ⇒ Boolean
- #isFrameSearch? ⇒ Boolean
- #isGetAlert?(_action) ⇒ Boolean
- #isHighlight?(_action) ⇒ Boolean
- #isLoadData?(_action) ⇒ Boolean
- #isLoadDB?(_action) ⇒ Boolean
- #isLoadJs?(_action) ⇒ Boolean
- #isLoadRequirements?(_action) ⇒ Boolean
- #isMouseOver?(_action) ⇒ Boolean
- #isNavigate?(_action) ⇒ Boolean
- #isPause?(_action) ⇒ Boolean
- #isSelect?(_action) ⇒ Boolean
- #isSelectWindow?(_action) ⇒ Boolean
- #isSleep?(_action) ⇒ Boolean
- #isSubmitForm?(_action) ⇒ Boolean
- #isSwitchFrame? ⇒ Boolean
- #isType?(_action) ⇒ Boolean
- #isUploadFiles?(_action) ⇒ Boolean
- #isValid?(cmd) ⇒ Boolean
- #isVerifyElt?(_action) ⇒ Boolean
- #isVerifyForm?(_action) ⇒ Boolean
- #reset(stanza = nil) ⇒ Object
- #resetFrameSearch ⇒ Object
- #resetTimeout(t = 30) ⇒ Object
- #setCurrentWindow(_w) ⇒ Object
- #setEnableFrameSearch(b) ⇒ Object
- #setTimeout(_t) ⇒ Object
Constructor Details
#initialize ⇒ Utils
Returns a new instance of Utils.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/scoutui/commands/utils.rb', line 15 def initialize @command_list=['pause', 'assignvar', 'assignments', 'existsAlert', 'clickJsAlert', 'dumpvars', 'fillform', 'frame', 'highlight', 'submitform', 'type', 'click', 'loaddata', 'connect', 'loaddb', 'loadjs', 'executecommands', 'definecommands', 'loadrequirements', 'mouseover', 'navigate', 'select', 'select_window', 'sleep', 'uploadfiles', 'verifyelt', 'verifyelement', 'verifyform'] @totalCommands={} @timeout=30 @command_list.each do |c| @totalCommands[c]=0 end @useFrameSearch = false @transList={ '__CHAR10__' => lambda { }, '__CITY__' => lambda { Faker::Address.city.to_s }, '__COMPANY.NAME__' => lambda { Faker::Company.name.to_s }, '__COMPANY.EIN__' => lambda { Faker::Company.ein.to_s }, '__COUNTRY__' => lambda { Faker::Address.country.to_s }, '__DATE__' => lambda { Time.now().to_s }, '__EMAIL__' => lambda { Faker::Internet.email.to_s}, '__DDMMYY__' => lambda { Date.parse(Time.now.to_s).strftime("%d%m%Y") }, '__MM/DD/YY__' => lambda { Date.parse(Time.now.to_s).strftime("%m/%d/%y") }, '__MM/DD/YY\+\d+__' => lambda { |s| Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process s => #{s}" d=s.match(/__MM\/DD\/YY\+(\d+)__/)[1] d=(Date.today + d.to_i).strftime("%m/%d/%y") Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " new date: #{d}" d }, '__MMDDYY__' => lambda { Date.parse(Time.now.to_s).strftime("%m%d%y") }, '__MMDDYY\+\d+__' => lambda { |s| Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process s => #{s}" d=s.match(/__MMDDYY\+(\d+)__/)[1] d=(Date.today + d.to_i).strftime("%m%d%y") Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " new date: #{d}" d }, '__MM/DD/YYYY__' => lambda { Date.parse(Time.now.to_s).strftime("%m/%d/%Y") }, '__MM/DD/YYYY\+\d+__' => lambda { |s| Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process s => #{s}" d=s.match(/__MM\/DD\/YYYY\+(\d+)__/)[1] d=(Date.today + d.to_i).strftime("%m/%d/%Y") Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " new date: #{d}" d }, '__MMDDYYYY__' => lambda { Date.parse(Time.now.to_s).strftime("%m%d%Y") }, '__MMDDYYYY\+\d+__' => lambda { |s| Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process s => #{s}" d=s.match(/__MMDDYYYY\+(\d+)__/)[1] d=(Date.today + d.to_i).strftime("%m%d%Y") Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " new date: #{d}" d }, '__PARAGRAPH__' => lambda { Faker::Lorem.paragraph.to_s }, '__PASSWORD__' => lambda { Faker::Internet.password.to_s }, '__PHONENUMBER__' => lambda { Faker::PhoneNumber.phone_number.to_s }, '__PHONENUMBER.AREACODE__' => lambda { Faker::Config.locale = 'en-US'; Faker::PhoneNumber.area_code.to_s }, '__PHONENUMBER.EXCHANGE__' => lambda { Faker::Config.locale = 'en-US'; Faker::PhoneNumber.exchange_code.to_s }, '__PHONENUMBER.SUBSCRIBER__' => lambda { Faker::PhoneNumber.subscriber_number.to_s }, '__PHONENUMBER.EXT__' => lambda { Faker::PhoneNumber.extension.to_s }, '__NUMBER__' => lambda { Faker::Number.number(5).to_s}, '__NUMBER(1)__' => lambda { Faker::Number.number(1).to_s}, '__NUMBER(2)__' => lambda { Faker::Number.number(2).to_s}, '__NUMBER(5)__' => lambda { Faker::Number.number(5).to_s}, '__NUMBER(8)__' => lambda { Faker::Number.number(8).to_s}, '__NUMBER(10)__' => lambda { Faker::Number.number(10).to_s}, '__NUMBER(1,28)__' => lambda { Faker::Number.between(1, 28).to_s }, '__NUMBER(1, 28)__' => lambda { Faker::Number.between(1, 28).to_s }, '__NUMBER(1,29)__' => lambda { Faker::Number.between(1, 29).to_s }, '__NUMBER(1, 29)__' => lambda { Faker::Number.between(1, 29).to_s }, '__NUMBER(1,30)__' => lambda { Faker::Number.between(1, 30).to_s }, '__NUMBER(1, 30)__' => lambda { Faker::Number.between(1, 30).to_s }, '__NUMBER(1,31)__' => lambda { Faker::Number.between(1, 31).to_s }, '__NUMBER(1, 31)__' => lambda { Faker::Number.between(1, 31).to_s }, '__SENTENCE__' => lambda { Faker::Lorem.sentence.to_s }, '__STREET__' => lambda { Faker::Address.street_address.to_s}, '__STATE__' => lambda { Faker::Address.state.to_s }, '__TIME__' => lambda { Time.now.to_s }, '__TIME.MMDDYY__' => lambda { Time.now.strftime "%m%d%y" }, '__TIME.MMDDYY.HM__' => lambda { Time.now.strftime "%m%d%y.%H%M" }, '__TIME.MMDDYY.HMS__' => lambda { Time.now.strftime "%m%d%y.%H%M%S" }, '__USERNAME__' => lambda { Faker::Internet.user_name.to_s }, '__ZIP__' => lambda { Faker::Address.zip_code.to_s }, } @hwnds = { :current => nil, :previous => nil, :handles => [] } end |
Instance Attribute Details
#hwnds ⇒ Object
Returns the value of attribute hwnds.
12 13 14 |
# File 'lib/scoutui/commands/utils.rb', line 12 def hwnds @hwnds end |
#timeout ⇒ Object
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/scoutui/commands/utils.rb', line 11 def timeout @timeout end |
#totalCommands ⇒ Object
Returns the value of attribute totalCommands.
10 11 12 |
# File 'lib/scoutui/commands/utils.rb', line 10 def totalCommands @totalCommands end |
#useFrameSearch ⇒ Object
Returns the value of attribute useFrameSearch.
13 14 15 |
# File 'lib/scoutui/commands/utils.rb', line 13 def useFrameSearch @useFrameSearch end |
Instance Method Details
#enableFrameSearch ⇒ Object
187 188 189 190 |
# File 'lib/scoutui/commands/utils.rb', line 187 def enableFrameSearch() Scoutui::Logger::LogMgr.instance.debug "EnableFrameSearch(true)" setEnableFrameSearch(true) end |
#expandMacro(_text_to_type) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/scoutui/commands/utils.rb', line 130 def (_text_to_type) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " expandMacro(#{_text_to_type})" if _text_to_type.nil? || _text_to_type.empty? return "" end @transList.each_pair do |_k, _v| if _text_to_type.include?(_k.to_s) _dynamicStr = _v.call.to_s _text_to_type.gsub!(_k.to_s, _dynamicStr) elsif _text_to_type.match(/#{_k.to_s}/) _dynamicStr = _v.call(_text_to_type.to_s) _text_to_type.gsub!(/#{_k.to_s}/, _dynamicStr) end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " expandMacro : #{_text_to_type}" _text_to_type.to_s end |
#getFrameSearch ⇒ Object
179 180 181 |
# File 'lib/scoutui/commands/utils.rb', line 179 def getFrameSearch() @userFrameSearch end |
#getTimeout ⇒ Object
227 228 229 |
# File 'lib/scoutui/commands/utils.rb', line 227 def getTimeout() @timeout.to_i end |
#isAssignments?(_action) ⇒ Boolean
231 232 233 |
# File 'lib/scoutui/commands/utils.rb', line 231 def isAssignments?(_action) !_action.match(/^\s*(assignments)\s*$/).nil? end |
#isAssignVar?(_action) ⇒ Boolean
235 236 237 |
# File 'lib/scoutui/commands/utils.rb', line 235 def isAssignVar?(_action) !_action.match(/assign\(([\w]+)\s*\,(.*)\)\s*$/i).nil? end |
#isClick?(_action) ⇒ Boolean
259 260 261 |
# File 'lib/scoutui/commands/utils.rb', line 259 def isClick?(_action) !_action.match(/click\(/i).nil? end |
#isConnect?(_action) ⇒ Boolean
271 272 273 |
# File 'lib/scoutui/commands/utils.rb', line 271 def isConnect?(_action) !_action.match(/^\s*connect\s*$/i).nil? end |
#isCSS(_locator) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/scoutui/commands/utils.rb', line 196 def isCSS(_locator) rc=nil if _locator.match(/^css\=/i) rc = _locator.match(/\s*(css\=.*)/i)[1].to_s.strip elsif _locator.match(/^#/i) rc=_locator.strip end rc end |
#isDefineCommands?(_action) ⇒ Boolean
287 288 289 |
# File 'lib/scoutui/commands/utils.rb', line 287 def isDefineCommands?(_action) !_action.match(/^\s*definecommand[s]*\s*$/i).nil? end |
#isDumpVars?(_action) ⇒ Boolean
275 276 277 |
# File 'lib/scoutui/commands/utils.rb', line 275 def isDumpVars?(_action) !_action.match(/^\s*dumpvars\s*$/i).nil? end |
#isExecuteCommands?(_action) ⇒ Boolean
283 284 285 |
# File 'lib/scoutui/commands/utils.rb', line 283 def isExecuteCommands?(_action) !_action.match(/^\s*executecommand[s]*\s*$/i).nil? end |
#isExistsAlert?(_action) ⇒ Boolean
243 244 245 |
# File 'lib/scoutui/commands/utils.rb', line 243 def isExistsAlert?(_action) !_action.match(/(exist[s]*_*alert|existAlert|existsAlert|existsJsAlert|existsJsConfirm|existsJsPrompt)\(/i).nil? end |
#isFillForm?(_action) ⇒ Boolean
267 268 269 |
# File 'lib/scoutui/commands/utils.rb', line 267 def isFillForm?(_action) !_action.match(/fillform\(/i).nil? end |
#isFrame?(_action) ⇒ Boolean
247 248 249 |
# File 'lib/scoutui/commands/utils.rb', line 247 def isFrame?(_action) _action.match(/^\s*(frame|switchframe|switch_frame)\s*\(/i) end |
#isFrameSearch? ⇒ Boolean
192 193 194 |
# File 'lib/scoutui/commands/utils.rb', line 192 def isFrameSearch?() @userFrameSearch.is_a?(TrueClass) || (@userFrameSearch.is_a?(String) && @userFrameSearch.match(/true/i)) end |
#isGetAlert?(_action) ⇒ Boolean
263 264 265 |
# File 'lib/scoutui/commands/utils.rb', line 263 def isGetAlert?(_action) !_action.match(/(get_*alert|clickjsconfirm|clickjsprompt|clickjsalert)/i).nil? end |
#isHighlight?(_action) ⇒ Boolean
251 252 253 |
# File 'lib/scoutui/commands/utils.rb', line 251 def isHighlight?(_action) _action.match(/^\s*(highlight)/i) end |
#isLoadData?(_action) ⇒ Boolean
291 292 293 |
# File 'lib/scoutui/commands/utils.rb', line 291 def isLoadData?(_action) !_action.match(/^\s*loaddata\s*$/i).nil? end |
#isLoadDB?(_action) ⇒ Boolean
279 280 281 |
# File 'lib/scoutui/commands/utils.rb', line 279 def isLoadDB?(_action) !_action.match(/^\s*loaddb\s*$/i).nil? end |
#isLoadJs?(_action) ⇒ Boolean
295 296 297 |
# File 'lib/scoutui/commands/utils.rb', line 295 def isLoadJs?(_action) !_action.match(/^\s*loadjs\s*$/i).nil? end |
#isLoadRequirements?(_action) ⇒ Boolean
300 301 302 |
# File 'lib/scoutui/commands/utils.rb', line 300 def isLoadRequirements?(_action) !_action.match(/^\s*loadrequirements\s*$/i).nil? end |
#isMouseOver?(_action) ⇒ Boolean
304 305 306 |
# File 'lib/scoutui/commands/utils.rb', line 304 def isMouseOver?(_action) !_action.match(/mouseover\(/).nil? end |
#isNavigate?(_action) ⇒ Boolean
336 337 338 |
# File 'lib/scoutui/commands/utils.rb', line 336 def isNavigate?(_action) !_action.nil? && _action.match(/(navigate|url)\(/i) end |
#isPause?(_action) ⇒ Boolean
320 321 322 |
# File 'lib/scoutui/commands/utils.rb', line 320 def isPause?(_action) !_action.match(/pause/).nil? end |
#isSelect?(_action) ⇒ Boolean
324 325 326 |
# File 'lib/scoutui/commands/utils.rb', line 324 def isSelect?(_action) !_action.nil? && _action.match(/^\s*select\s*\(/i) end |
#isSelectWindow?(_action) ⇒ Boolean
239 240 241 |
# File 'lib/scoutui/commands/utils.rb', line 239 def isSelectWindow?(_action) !_action.match(/^\s*select_window/i).nil? end |
#isSleep?(_action) ⇒ Boolean
328 329 330 |
# File 'lib/scoutui/commands/utils.rb', line 328 def isSleep?(_action) !_action.nil? && _action.match(/^\s*sleep\s*\(\s*\d+\s*\)\s*$/i) end |
#isSubmitForm?(_action) ⇒ Boolean
312 313 314 |
# File 'lib/scoutui/commands/utils.rb', line 312 def isSubmitForm?(_action) !_action.match(/submitform\(/).nil? end |
#isSwitchFrame? ⇒ Boolean
183 184 185 |
# File 'lib/scoutui/commands/utils.rb', line 183 def isSwitchFrame?() @userFrameSearch.is_a?(String) && @userFrameSearch.match(/^\s*frame\s*\(/i) end |
#isType?(_action) ⇒ Boolean
308 309 310 |
# File 'lib/scoutui/commands/utils.rb', line 308 def isType?(_action) !_action.match(/type[\!]*\(/).nil? end |
#isUploadFiles?(_action) ⇒ Boolean
332 333 334 |
# File 'lib/scoutui/commands/utils.rb', line 332 def isUploadFiles?(_action) !_action.nil? && _action.match(/^\s*uploadfiles\s*$/i) end |
#isValid?(cmd) ⇒ Boolean
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/scoutui/commands/utils.rb', line 340 def isValid?(cmd) rc=true if isPause?(cmd) @totalCommands['pause']+=1 elsif isAssignVar?(cmd) @totalCommands['assignvar']+=1 elsif isAssignments?(cmd) @totalCommands['assignments']+=1 elsif isExistsAlert?(cmd) @totalCommands['existsAlert']+=1 elsif isFrame?(cmd) @totalCommands['frame']+=1 elsif isGetAlert?(cmd) @totalCommands['clickJsAlert']+=1 elsif isHighlight?(cmd) @totalCommands['highlight']+=1 elsif isVerifyElt?(cmd) @totalCommands['verifyelt']+=1 elsif isVerifyForm?(cmd) @totalCommands['verifyform']+=1 elsif isFillForm?(cmd) @totalCommands['fillform']+=1 elsif isSubmitForm?(cmd) @totalCommands['submitform']+=1 elsif isType?(cmd) @totalCommands['type']+=1 elsif isClick?(cmd) @totalCommands['click']+=1 elsif isDumpVars?(cmd) @totalCommands['dumpvars']+=1 elsif isMouseOver?(cmd) @totalCommands['mouseover']+=1 elsif isConnect?(cmd) @totalCommands['connect']+=1 elsif isExecuteCommands?(cmd) @totalCommands['executecommands']+=1 elsif isDefineCommands?(cmd) @totalCommands['definecommands']+=1 elsif isLoadDB?(cmd) @totalCommands['loaddb']+=1 elsif isLoadData?(cmd) @totalCommands['loaddata']+=1 elsif isLoadJs?(cmd) @totalCommands['loadjs']+=1 elsif isLoadRequirements?(cmd) @totalCommands['loadrequirements']+=1 elsif isSelect?(cmd) @totalCommands['select']+=1 elsif isNavigate?(cmd) @totalCommands['navigate']+=1 elsif isSelectWindow?(cmd) @totalCommands['select_window']+=1 elsif isSleep?(cmd) @totalCommands['sleep']+=1 elsif isUploadFiles?(cmd) @totalCommands['uploadfiles']+=1 else rc=false end rc end |
#isVerifyElt?(_action) ⇒ Boolean
255 256 257 |
# File 'lib/scoutui/commands/utils.rb', line 255 def isVerifyElt?(_action) !_action.match(/(verifyelt|verifyelement)\(/i).nil? end |
#isVerifyForm?(_action) ⇒ Boolean
316 317 318 |
# File 'lib/scoutui/commands/utils.rb', line 316 def isVerifyForm?(_action) !_action.match(/verifyform\(/).nil? end |
#reset(stanza = nil) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/scoutui/commands/utils.rb', line 156 def reset(stanza=nil) Scoutui::Utils::TestUtils.instance.setTC(nil) setEnableFrameSearch(false) if stanza.is_a?(Hash) && stanza.has_key?('page') && stanza['page'].has_key?('frames') Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " frames => #{stanza['page']['frames']}"; setEnableFrameSearch(stanza['page']['frames']) # setEnableFrameSearch(!stanza['page']['frames'].to_s.match(/true/i).nil?) end end |
#resetFrameSearch ⇒ Object
170 171 172 |
# File 'lib/scoutui/commands/utils.rb', line 170 def resetFrameSearch() setEnableFrameSearch(false) end |
#resetTimeout(t = 30) ⇒ Object
219 220 221 |
# File 'lib/scoutui/commands/utils.rb', line 219 def resetTimeout(t=30) setTimeout(t) end |
#setCurrentWindow(_w) ⇒ Object
209 210 211 212 213 214 215 216 217 |
# File 'lib/scoutui/commands/utils.rb', line 209 def setCurrentWindow(_w) if @hwnds[:previous].nil? @hwnds[:previous]=_w else @hwnds[:previous]=@hwnds[:current] end @hwnds[:current]=_w end |
#setEnableFrameSearch(b) ⇒ Object
174 175 176 177 |
# File 'lib/scoutui/commands/utils.rb', line 174 def setEnableFrameSearch(b) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " setEnabledFrameSearch(#{b})" @userFrameSearch=b end |
#setTimeout(_t) ⇒ Object
223 224 225 |
# File 'lib/scoutui/commands/utils.rb', line 223 def setTimeout(_t) @timeout=_t.to_i end |