require_relative './commands' module Scoutui::Commands class AssignVar < Command def execute(drv, e=nil) @drv=drv if !drv.nil? rc=nil obj=nil _req = Scoutui::Utils::TestUtils.instance.getReq() _uservar = @cmd.match(/assign\(([\w]+)\s*\,(.*)\)\s*$/)[1].to_s.strip _condition = @cmd.match(/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 Scoutui::Base::UserVars.instance.setVar(_uservar, _condition) rc=_condition end begin if !obj.nil? # Refactor in qbrowser wait = Selenium::WebDriver::Wait.new(:timeout => Scoutui::Commands::Utils.instance.getTimeout) isDisplayed=false isDisplayed = wait.until { true if 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) puts __FILE__ + (__LINE__).to_s + " rc :: #{Scoutui::Base::UserVars.instance.getVar(_uservar)}" if isDisplayed ; else Scoutui::Logger::LogMgr.instance.warn __FILE__ + (__LINE__).to_s + " Element, #{_locator} is not displayed." 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