class Scoutui::Commands::Utils

Attributes

hwnds[RW]
timeout[RW]
totalCommands[RW]
useFrameSearch[RW]

Public Class Methods

new() click to toggle source
# File lib/scoutui/commands/utils.rb, line 15
def initialize
  @command_list=['pause',
                 'assignvar',
                 'assignments',
                 'doUntil',
                 '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',
                 'whileDo']
  @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") },
      '__DD/MM/YYYY__' => lambda { Date.parse(Time.now.to_s).strftime("%d/%m/%Y") },
      '__DD/MM/YYYY\+\d+__' => lambda { |s|
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process s => #{s}"
        d=s.match(/__DD\/MM\/YYYY\+(\d+)__/)[1]
        d=(Date.today + d.to_i).strftime("%d/%m/%Y")
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "    new date: #{d}"
        d
      },
      '__DD/MM/YYYY\-\d+__' => lambda { |s|
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Process s => #{s}"
        d=s.match(/__DD\/MM\/YYYY\-(\d+)__/)[1]
        d=(Date.today - d.to_i).strftime("%d/%m/%Y")
        Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + "    new date: #{d}"
        d
      },
      '__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
      },
      '__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

Public Instance Methods

enableFrameSearch() click to toggle source
# File lib/scoutui/commands/utils.rb, line 211
def enableFrameSearch()
  Scoutui::Logger::LogMgr.instance.debug "EnableFrameSearch(true)"
  setEnableFrameSearch(true)
end
expandMacro(_text_to_type) click to toggle source
# File lib/scoutui/commands/utils.rb, line 154
def expandMacro(_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() click to toggle source
# File lib/scoutui/commands/utils.rb, line 203
def getFrameSearch()
  @userFrameSearch
end
getTimeout() click to toggle source
# File lib/scoutui/commands/utils.rb, line 251
def getTimeout()
  @timeout.to_i
end
isAssignVar?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 267
def isAssignVar?(_action)
  _action.is_a?(String) &&  !_action.match(/assign\(([\w]+)\s*\,(.*)\)\s*$/i).nil?
end
isAssignments?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 263
def isAssignments?(_action)
  _action.is_a?(String) &&  !_action.match(/^\s*(assignments)\s*$/).nil?
end
isCSS(_locator) click to toggle source
# File lib/scoutui/commands/utils.rb, line 220
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
isClick?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 291
def isClick?(_action)
  _action.is_a?(String) &&  !_action.match(/click\(/i).nil?
end
isConnect?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 303
def isConnect?(_action)
  _action.is_a?(String) &&  !_action.match(/^\s*connect\s*$/i).nil?
end
isDefineCommands?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 319
def isDefineCommands?(_action)
  _action.is_a?(String) && !_action.match(/^\s*definecommand[s]*\s*$/i).nil?
end
isDoUntil?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 255
def isDoUntil?(_action)
  _action.is_a?(Hash) && _action.has_key?('do') && !_action.has_key?('while')
end
isDumpVars?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 307
def isDumpVars?(_action)
  _action.is_a?(String) &&  !_action.match(/^\s*dumpvars\s*$/i).nil?
end
isExecuteCommands?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 315
def isExecuteCommands?(_action)
  _action.is_a?(String) && !_action.match(/^\s*executecommand[s]*\s*$/i).nil?
end
isExistsAlert?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 275
def isExistsAlert?(_action)
  _action.is_a?(String) &&  !_action.match(/[!]*(exist[s]*_*alert|existAlert|existsAlert|existsJsAlert|existsJsConfirm|existsJsPrompt)\(/i).nil?
end
isFillForm?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 299
def isFillForm?(_action)
  _action.is_a?(String) &&  !_action.match(/fillform\(/i).nil?
end
isFrame?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 279
def isFrame?(_action)
  _action.is_a?(String) &&  _action.match(/^\s*(frame|switchframe|switch_frame)\s*\(/i)
end
isFrameSearch?() click to toggle source
# File lib/scoutui/commands/utils.rb, line 216
def isFrameSearch?()
  @userFrameSearch.is_a?(TrueClass) || (@userFrameSearch.is_a?(String) && @userFrameSearch.match(/true/i))
end
isGetAlert?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 295
def isGetAlert?(_action)
  _action.is_a?(String) &&  !_action.match(/(get_*alert|clickjsconfirm|clickjsprompt|clickjsalert)/i).nil?
end
isHighlight?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 283
def isHighlight?(_action)
  _action.is_a?(String) &&   _action.match(/^\s*(highlight)/i)
end
isLoadDB?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 311
def isLoadDB?(_action)
  _action.is_a?(String) &&  !_action.match(/^\s*loaddb\s*$/i).nil?
end
isLoadData?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 323
def isLoadData?(_action)
  _action.is_a?(String) && !_action.match(/^\s*loaddata\s*$/i).nil?
end
isLoadJs?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 327
def isLoadJs?(_action)
  _action.is_a?(String) && !_action.match(/^\s*loadjs\s*$/i).nil?
end
isLoadRequirements?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 332
def isLoadRequirements?(_action)
  _action.is_a?(String) && !_action.match(/^\s*loadrequirements\s*$/i).nil?
end
isMouseOver?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 336
def isMouseOver?(_action)
  _action.is_a?(String) && !_action.match(/mouseover\(/).nil?
end
isNavigate?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 368
def isNavigate?(_action)
  !_action.nil? && _action.is_a?(String) && _action.match(/(navigate|url)\(/i)
end
isPause?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 352
def isPause?(_action)
  _action.is_a?(String) && !_action.match(/pause/).nil?
end
isSelect?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 356
def isSelect?(_action)
  !_action.nil? && _action.is_a?(String) && _action.match(/^\s*select\s*\(/i)
end
isSelectWindow?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 271
def isSelectWindow?(_action)
  _action.is_a?(String) &&  !_action.match(/^\s*select_window/i).nil?
end
isSleep?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 360
def isSleep?(_action)
  !_action.nil? && _action.is_a?(String) && _action.match(/^\s*sleep\s*\(\s*\d+\s*\)\s*$/i)
end
isSubmitForm?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 344
def isSubmitForm?(_action)
  _action.is_a?(String) && !_action.match(/submitform\(/).nil?
end
isSwitchFrame?() click to toggle source
# File lib/scoutui/commands/utils.rb, line 207
def isSwitchFrame?()
  @userFrameSearch.is_a?(String) && @userFrameSearch.match(/^\s*frame\s*\(/i)
end
isType?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 340
def isType?(_action)
  _action.is_a?(String) && !_action.match(/type[\!]*\(/).nil?
end
isUploadFiles?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 364
def isUploadFiles?(_action)
  !_action.nil? && _action.is_a?(String) && _action.match(/^\s*uploadfiles\s*$/i)
end
isValid?(cmd) click to toggle source
# File lib/scoutui/commands/utils.rb, line 372
def isValid?(cmd)

  rc=true

  if isDoUntil?(cmd)
    @totalCommands['doUntil']+=1
  elsif isWhileDo?(cmd)
    @totalCommands['whileDo']+=1
  elsif 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) click to toggle source
# File lib/scoutui/commands/utils.rb, line 287
def isVerifyElt?(_action)
  _action.is_a?(String) && !_action.match(/(verify[eE]lt|verify[eE]lement)\(/i).nil?
end
isVerifyForm?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 348
def isVerifyForm?(_action)
  _action.is_a?(String) && !_action.match(/verifyform\(/).nil?
end
isWhileDo?(_action) click to toggle source
# File lib/scoutui/commands/utils.rb, line 259
def isWhileDo?(_action)
  _action.is_a?(Hash) && _action.has_key?('while') && _action.has_key?('do')
end
reset(stanza=nil) click to toggle source
# File lib/scoutui/commands/utils.rb, line 180
    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() click to toggle source
# File lib/scoutui/commands/utils.rb, line 194
def resetFrameSearch()
  setEnableFrameSearch(false)
end
resetTimeout(t=30) click to toggle source
# File lib/scoutui/commands/utils.rb, line 243
def resetTimeout(t=30)
  setTimeout(t)
end
setCurrentWindow(_w) click to toggle source
# File lib/scoutui/commands/utils.rb, line 233
def setCurrentWindow(_w)
  if @hwnds[:previous].nil?
    @hwnds[:previous]=_w
  else
    @hwnds[:previous]=@hwnds[:current]
  end

  @hwnds[:current]=_w
end
setEnableFrameSearch(b) click to toggle source
# File lib/scoutui/commands/utils.rb, line 198
def setEnableFrameSearch(b)
  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " setEnabledFrameSearch(#{b})"
  @userFrameSearch=b
end
setTimeout(_t) click to toggle source
# File lib/scoutui/commands/utils.rb, line 247
def setTimeout(_t)
  @timeout=_t.to_i
end