require_relative './commands' module Scoutui::Commands class Connect < Command def hasQuery(e) rc=nil if e['page'].has_key?('execute') && e['page']['execute'].has_key?('query') rc=e['page']['execute']['query'].to_s end rc end def execute(drv, e=nil) @drv=drv if !drv.nil? rc=false obj=nil isConnected=false _locator=nil # _req = Scoutui::Utils::TestUtils.instance.getReq() || "DB" begin Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " connect()" if e['page'].has_key?('to') isConnected=Scoutui::Base::TestData.instance.connectDB(e['page']['to']) Testmgr::TestReport.instance.getReq('DB').testcase('DB').add(isConnected, "Verify connected to DB #{e['page']['to'].to_s}") end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " isConnected : #{isConnected}" _val = hasQuery(e) if isConnected && !_val.nil? _q=_val.to_s _v2=Scoutui::Base::UserVars.instance.normalize(_val) if !_v2.nil? Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " getData ==> #{_v2}" reportName=e['page']['execute']['report'] || 'SCOUTUI' DataMgr::DB.instance.run(id: e['page']['to'], query: _v2, report: reportName) result=DataMgr::DB.instance.getResult(id: e['page']['to'], report: reportName) Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " *** RESULT : #{result.class.to_s} : #{result} ***" end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " connect() : #{isConnected}" rc=true 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 Scoutui::Logger::LogMgr.instance.asserts.info "Verify connect command passed - #{rc}" Testmgr::TestReport.instance.getReq('DB').testcase('DB').add(rc, "Verify connect command passed") setResult(rc) end end end