Class: Scoutui::Commands::Type
- Defined in:
- lib/scoutui/commands/type.rb
Constant Summary collapse
- KEYBOARD_CMDS =
{ '__DELETE__' => { :val => :delete }, '__DOWN__' => { :val => :arrow_down }, '__ENTER__' => { :val => :enter }, '__ESC__' => { :val => :escape }, '__ESCAPE__' => { :val => :escape }, '__UP__' => { :val => :arrow_up }, '__LEFT__' => { :val => :arrow_left }, '__RIGHT__' => { :val => :arrow_right }, '__TAB__' => { :val => :tab }, '__SHIFT_TAB__' => {:val => :custom, :run => lambda { |drv| puts __FILE__ + (__LINE__).to_s + " *** SHIFT_TAB ***" drv.action.key_down(:shift).send_keys(:tab).perform; drv.action.key_up(:shift).perform; }} }
- KEYBOARD_LIST =
{ '__DOWN__' => lambda { |obj| obj.send_keys(:arrow_down) }, '__ESC__' => lambda { |obj| obj.send_keys(:escape) }, '__ESCAPE__' => lambda { |obj| obj.send_keys(:escape) }, '__TAB__' => lambda { |obj| obj.send_keys(:tab) }, '__CLEAR__' => lambda { |obj| obj.clear } }
Instance Attribute Summary
Attributes inherited from Command
#bm, #cmd, #description, #drv, #enableAssert, #executed, #executed_result, #locator, #rc, #stanza
Instance Method Summary collapse
Methods inherited from Command
#assert?, #disableAssert, #disableAsserts, #enableAsserts, #executedResult, #getLocator, #initialize, #passed?, #result, #run, #setBenchmark, #setLocator, #setResult, #wasExecuted?
Constructor Details
This class inherits a constructor from Scoutui::Commands::Command
Instance Method Details
#_whenTyped(page_elt) ⇒ Object
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 |
# File 'lib/scoutui/commands/type.rb', line 35 def _whenTyped(page_elt) if page_elt.is_a?(Hash) && page_elt.has_key?('when_typed') Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Verify #{page_elt['when_clicked']}" page_elt['when_clicked'].each do |_elt| _r = _elt.keys[0].to_s _pg = _elt[_r] # _c = Scoutui::Commands::VerifyElement.new("verifyelement(" + _elt + ")") # _c.execute(@drv) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _whenClicked -> assertions (#{_pg}, #{_r.to_s})" if _pg.is_a?(Array) _pg.each do |_pg2| isVisible=Scoutui::Base::Assertions.instance.isVisible(@drv, _pg2, _r) end elsif _pg.is_a?(String) isVisible=Scoutui::Base::Assertions.instance.isVisible(@drv, _pg, _r) else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " => #{_pg}" end # Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " IsVisible #{isVisible} - PAUSE"; gets end end end |
#execute(drv = nil, pageElt = nil) ⇒ Object
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/scoutui/commands/type.rb', line 71 def execute(drv=nil, pageElt=nil) @drv=drv if !drv.nil? _tm={:start => 0, :end => 0 } _val=nil _isKb=false _rc=false _req = Scoutui::Utils::TestUtils.instance.getReq() _startTime=Time.now _endTime=nil begin if @cmd.match(/^type\(focused\s*,\s*.*\)\s*$/) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Type into active element" obj = @drv.switch_to.active_element Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | active.Tag : " + obj.tag_name Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | active.Class: " + obj.attribute('class').to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | active.ID : " + obj.attribute('id').to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | active.Name : " + obj.attribute('name').to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | active.Text : " + obj.text.to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | active.Value: " + obj.attribute('value').to_s _val = @cmd.match(/^type\(focused\s*,\s*(.*)\)\s*$/)[1].to_s if KEYBOARD_CMDS.has_key?(_val) _val = KEYBOARD_CMDS[_val][:val] end _xpath="[focused]" obj.send_keys(_val) _rc=true elsif @cmd.match(/^type\((#{KEYBOARD_CMDS.keys.join('|')})\)$/) _tm[:start]=Time.now _keyVal=@cmd.match(/^type\((#{KEYBOARD_CMDS.keys.join('|')})\)$/)[1].to_s if KEYBOARD_CMDS[_keyVal][:val]==:custom KEYBOARD_CMDS[_keyVal][:run].call(@drv) else @drv.action.send_keys(KEYBOARD_CMDS[_keyVal][:val]).perform end thenClause = Scoutui::Commands::ThenClause.new(@drv) doUntil = Scoutui::Commands::DoUntil.new(@drv) _tm[:start]=Time.now # _bUntil = thenClause.execute_until(pageElt) _bUntil = doUntil.do_until(pageElt) _tm[:end]=Time.now Testmgr::TestReport.instance.getReq(_req).testcase('until').add(_bUntil, Scoutui::Base::UserVars.instance.normalize("Verify then-until met #{_bUntil}"), (_tm[:end] - _tm[:start])) _rc=_bUntil _isKb=true else if @cmd.match(/^\s*type[\!]*\((.*),\s*'(.*)\s*'\)\s*$/) _xpath = @cmd.match(/^\s*type[\!]*\((.*),\s*'(.*)\s*'\)\s*$/)[1] _val = @cmd.match(/^\s*type[\!]*\((.*),\s*'(.*)\s*'\)\s*$/)[2] else _xpath = @cmd.match(/^\s*type[\!]*\((.*),\s*(.*)\s*\)\s*$/)[1] _val = @cmd.match(/^\s*type[\!]*\((.*),\s*(.*)\s*\)\s*$/)[2] end Scoutui::Logger::LogMgr.instance.commands.debug __FILE__ + (__LINE__).to_s + " Process TYPE #{_val} into #{_xpath}" _tm[:start]=Time.now obj = Scoutui::Base::QBrowser.getElement(@drv, _xpath, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) _tm[:end]=Time.now Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " type(#{_val})" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " tag : #{obj.tag_name}" if obj.is_a?(Selenium::WebDriver::Element) typeInto = !obj.nil? && (obj.tag_name.downcase=='body' || !obj.attribute('type').downcase.match(/(file|input|text|textarea|password|email)/).nil? ) if typeInto isDisplayed=false # FileUpload dialog is not 'displayed' if !Scoutui::Base::QBrowser.isFileType?(obj) begin wait = Selenium::WebDriver::Wait.new(:timeout => Scoutui::Commands::Utils.instance.getTimeout) isDisplayed = wait.until { if Scoutui::Base::QBrowser.isStale?(obj) obj = Scoutui::Base::QBrowser.findElement(@drv, _xpath, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) end true if obj.displayed? } _tm[:end]=Time.now rescue Selenium::WebDriver::Error::TimeOutError => ex Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Timeout waiting for display?: #{_xpath}" end end if @cmd.match(/^\s*type\!/i) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " clear()" (0..3).each do |j| if Scoutui::Base::QBrowser.isStale?(obj) obj = Scoutui::Base::QBrowser.getElement(@drv, _xpath, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) _tm[:end]=Time.now else break end end obj.clear if isDisplayed end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " send_keys(#{_val})" if isDisplayed || Scoutui::Base::QBrowser.isFileType?(obj) if KEYBOARD_LIST.has_key?(_val.strip) KEYBOARD_LIST[_val.strip].call(obj) elsif _val.match(/^\s*__ENTER__\s*$/) obj.send_keys("") @drv.action.send_keys(:enter).perform else if Scoutui::Base::UserVars.instance.isTestData?(_val) _v2=Scoutui::Base::UserVars.instance.normalize(_val) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getData ==> #{_v2}" else _uservars = _val.scan(/\$\{(.*?)\}/) _v2 = _val for i in 0 .. (_uservars.size - 1) _t = Scoutui::Base::UserVars.instance.get(_uservars[i][0]) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " translate(#{_uservars[i][0]}) => #{_t}" if !_t.nil? && _uservars[i][0]!=_t _v2.gsub!("\$\{#{_uservars[i][0]}\}", _t) end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " value => #{_v2}" end end ## Global replaces _text_to_type = Scoutui::Base::UserVars.instance.get(_v2) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " rawText : #{_text_to_type}" _text_to_type = Scoutui::Commands::Utils.instance.(_text_to_type) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Text to type : #{_text_to_type}" if true _stale=true _inRow=0 _cnt=0 (0..7).each do |i| _cnt+=1 _stale=Scoutui::Base::QBrowser.isStale?(obj) if _stale _inRow=0 sleep 0.5 obj = Scoutui::Base::QBrowser.getElement(@drv, _xpath, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) _tm[:end]=Time.now else _inRow+=1 break if _inRow >= 3 obj = Scoutui::Base::QBrowser.getElement(@drv, _xpath, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) _tm[:end]=Time.now end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Stale: #{_stale}, i: #{_cnt}, _inRow:#{_inRow}" end obj.send_keys(_text_to_type) if !pageElt.nil? && pageElt['page'].has_key?('then') thenClause = Scoutui::Commands::ThenClause.new(@drv) thenClause.execute(pageElt) end if !obj.nil? && false arr=_text_to_type.split(/__ENTER__/) i=0 arr.each do |_t| # puts __FILE__ + (__LINE__).to_s + " => #{_t}"; STDIN.gets; if i > 0 obj.send_keys("") @drv.action.send_keys(:enter).perform Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ENTER"; STDIN.gets() obj.send_keys("<ENTER>") end obj.send_keys(_t) i+1 end end end _rc=true end else Scoutui::Logger::LogMgr.instance.commands.warn __FILE__ + (__LINE__).to_s + " Unable to process command TYPE => #{obj.to_s}" end end rescue => ex Scoutui::Logger::LogMgr.instance.warn "Error during processing: #{ex.class}" Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end _endTime=Time.now if !_isKb Testmgr::TestReport.instance.getReq(_req).testcase('type').add(!obj.nil?, Scoutui::Base::UserVars.instance.normalize("Verify object #{_xpath} to type #{_val} exists : #{obj.class.to_s}"), _tm[:end]-_tm[:start]) Testmgr::TestReport.instance.getReq(_req).testcase('type').add(_rc, Scoutui::Base::UserVars.instance.normalize("Verify typed data #{_rc}"), (_endTime - _startTime)) end setResult(_rc) end |