module Scoutui::Commands class Type < Command 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 puts __FILE__ + (__LINE__).to_s + " => #{_pg}" end # Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " IsVisible #{isVisible} - PAUSE"; gets end end end def execute(drv=nil) @drv=drv if !drv.nil? _isKb=false _rc=false _req = Scoutui::Utils::TestUtils.instance.getReq() begin if @cmd.strip.match(/^\s*type\s*\(\s*__TAB__\s*\)\s*$/) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " HIT TAB key" @drv.action.send_keys(:tab).perform _rc=true _isKb=true else _xpath = @cmd.match(/^\s*type[\!]*\(([^,]*),\s*/)[1].to_s _val = @cmd.match(/^\s*type[\!]*\([^,]*,\s*(.*)\)/)[1].to_s Scoutui::Logger::LogMgr.instance.commands.debug __FILE__ + (__LINE__).to_s + "Process TYPE #{_val} into #{_xpath}" obj = Scoutui::Base::QBrowser.findElement(@drv, _xpath, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " type(#{_val})" if !obj.nil? && !obj.attribute('type').downcase.match(/(text|textarea|password|email)/).nil? # Refactor in qbrowser wait = Selenium::WebDriver::Wait.new(:timeout => Scoutui::Commands::Utils.instance.getTimeout) isDisplayed=false isDisplayed = wait.until { true if obj.displayed? } if @cmd.match(/type\!/i) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " clear()" obj.clear if isDisplayed end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " send_keys(#{_val})" if isDisplayed if _val.match(/__DOWN__/) obj.send_keys(:arrow_down) elsif _val.match(/__TAB__/) obj.send_keys(:tab) else _uservars = _val.scan(/\$\{(.*?)\}/) _v2 = _val for i in 0 .. (_uservars.size - 1) _t = Scoutui::Base::UserVars.instance.get(_uservars[i][0]) puts __FILE__ + (__LINE__).to_s + " translate(#{_uservars[i][0]}) => #{_t}" if !_t.nil? && _uservars[i][0]!=_t _v2.gsub!("\$\{#{_uservars[i][0]}\}", _t) end puts __FILE__ + (__LINE__).to_s + " value => #{_v2}" end ## Global replaces _text_to_type = Scoutui::Base::UserVars.instance.get(_v2) transList={ '__DATE__' => lambda { Time.now().to_s }, '__CITY__' => lambda { Faker::Address.city.to_s }, '__ZIP__' => lambda { Faker::Address.zip_code.to_s }, '__STREET__' => lambda { Faker::Address.street_address.to_s}, '__STATE__' => lambda { Faker::Address.state.to_s }, '__COUNTRY__' => lambda { Faker::Address.country.to_s }, '__SENTENCE__' => lambda { Faker::Lorem.sentence.to_s }, '__PARAGRAPH__' => lambda { Faker::Lorem.paragraph.to_s }, '__NUMBER__' => lambda { Faker::Number.number(10).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, 29)__' => lambda { Faker::Number.between(1, 29).to_s }, '__NUMBER(1, 30)__' => lambda { Faker::Number.between(1, 30).to_s }, '__NUMBER(1, 31)__' => lambda { Faker::Number.between(1, 31).to_s } } transList.each_pair do |_k, _v| if _text_to_type.include?(_k.to_s) _text_to_type.gsub!(_k, _v.call) end end # _text_to_type.gsub!(/__DATE__/, Time.now().to_s) obj.send_keys(_text_to_type) end _rc=true end else Scoutui::Logger::LogMgr.instance.commands.debug __FILE__ + (__LINE__).to_s + " Unable to process command TYPE => #{obj.to_s}" end end rescue => ex Scoutui::Logger::LogMgr.instance.debug "Error during processing: #{ex}" puts __FILE__ + (__LINE__).to_s + "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end if !_isKb Testmgr::TestReport.instance.getReq(_req).testcase('type').add(!obj.nil?, "Verify object #{_xpath} to type #{_val} exists : #{obj.class.to_s}") Testmgr::TestReport.instance.getReq(_req).testcase('type').add(_rc, "Verify typed data #{_rc}") end setResult(_rc) end end end