require_relative './commands' module Scoutui::Commands class AssignVar < Command def execute(drv, e=nil) @drv=drv if !drv.nil? rc=nil obj=nil _locator=nil _req = Scoutui::Utils::TestUtils.instance.getReq() _uservar = @cmd.match(/^\s*assign\(([\w]+)\s*\,(.*)\)\s*$/)[1].to_s.strip _condition = @cmd.match(/^\s*assign\(([\w]+)\s*\,(.*)\)\s*$/)[2].to_s.strip Scoutui::Logger::LogMgr.instance.command.info __FILE__ + (__LINE__).to_s + " assignVar => #{_uservar} : #{_condition}" expectObj=!_condition.match(/^\s*(text|value)\s*\(/i).nil? if expectObj _locator=_condition.match(/^\s*(text|value)\s*\((.*)\)\s*$/i)[2].to_s.strip _locator = Scoutui::Base::UserVars.instance.normalize(_locator) Scoutui::Logger::LogMgr.instance.command.info __FILE__ + (__LINE__).to_s + " | translate : #{_locator}" if Scoutui::Utils::TestUtils.instance.isDebug? obj = Scoutui::Base::QBrowser.findElement(@drv, _locator, Scoutui::Commands::Utils.instance.getFrameSearch(), Scoutui::Commands::Utils.instance.getTimeout) else _val = _condition if Scoutui::Base::UserVars.instance.isTestData?(_val) _v2=Scoutui::Base::UserVars.instance.normalize(_val) _condition=_v2 elsif Scoutui::Base::UserVars.instance.isTestReport?(_val) _connectID = _val.match(/^\s*TestData\((.*?)\)\.getReport\(.*?\)\s*$/)[1].to_s _reportName = _val.match(/^\s*TestData\((.*?)\)\.getReport\((.*?)\)/)[2].to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " connectID : #{_connectID}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " repName : #{_reportName}" result=DataMgr::DB.instance.getResult(id: _connectID, report: _reportName) _getters = Scoutui::Base::UserVars.instance.getTestReportGetter(_val) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _getters => #{_getters}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " result #{result.class} => #{result}" _hit=result if _getters _getters.split(/\.get\(\s*(.*)\s*\)/).each do |p| if !p.empty? if p.match(/\d+$/) && _hit.has_key?(p.to_i) _hit=_hit[p.to_i] elsif _hit.has_key?(p) _hit=_hit[_p] else Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " key #{p} doesn't exist." end end end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Retrive.DB.Results(#{_connectID}.#{_reportName} => #{result}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _getters : #{_getters}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " HIT : #{_hit}" _condition=_hit.to_s end Scoutui::Base::UserVars.instance.setVar(_uservar, Scoutui::Commands::Utils.instance.expandMacro(_condition)) rc=_condition end begin if expectObj # Refactor in qbrowser if !obj.nil? wait = Selenium::WebDriver::Wait.new(:timeout => Scoutui::Commands::Utils.instance.getTimeout) isDisplayed=false isDisplayed = wait.until { obj.displayed? } rc = obj.text if _condition.match(/^\s*text/i) rc = obj.attribute('value') if _condition.match(/^\s*value/i) Scoutui::Base::UserVars.instance.setVar(_uservar, rc) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " rc :: #{Scoutui::Base::UserVars.instance.getVar(_uservar)} => #{rc.to_s}" if isDisplayed ; else Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " Element, #{_locator} is not displayed." end else Scoutui::Logger::LogMgr.instance.error __FILE__ + (__LINE__).to_s + " assign failed - unable to get element #{_locator}" end end rescue => ex Scoutui::Logger::LogMgr.instance.warn "Error during processing: #{ex}" Scoutui::Logger::LogMgr.instance.warn "Backtrace:\n\t#{ex.backtrace.join("\n\t")}" end if expectObj Scoutui::Logger::LogMgr.instance.asserts.info "Verify object to assign exists #{_locator} : #{obj.class.to_s} - #{!obj.nil?.to_s}" Testmgr::TestReport.instance.getReq(_req).testcase('click').add(!obj.nil?, "Verify object to assign exists #{_locator} : #{obj.class.to_s}") end setResult(!rc.nil?) end end end