require_relative('./command') module Scoutui::Commands STEP_KEY='page' def self.processCommands(commandList, my_driver) Scoutui::Logger::LogMgr.instance.debug " enter [processCommands]" commandList.each do |cmd| begin rc=processCommand(cmd[:command], cmd[:e], my_driver) rescue => ex Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" end end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " exit [processCommands]" end def self.processCommand(_action, e, my_driver) Scoutui::Logger::LogMgr.instance.commands.debug __FILE__ + (__LINE__).to_s + " enter [processCommand(#{_action}, #{e})" _aborted=false _cmd=nil rc=true _req = Scoutui::Utils::TestUtils.instance.getReq() begin _totalWindows = my_driver.window_handles.length Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Current Total Windows : #{_totalWindows}" _c=nil ## # Check if an alert exists. ## begin my_driver.switch_to.alert Scoutui::Logger::LogMgr.instance.info __FILE__ + (__LINE__).to_s + " Alert currently active." rescue Selenium::WebDriver::Error::NoSuchAlertError my_driver.switch_to.default_content end if Scoutui::Commands::Utils.instance.isPause?(_action) _cmd='pause' _c = Scoutui::Commands::Pause.new(nil) _c.execute(e); elsif Scoutui::Commands::Utils.instance.isLoadDB?(_action) _cmd='loaddb' _c = Scoutui::Commands::LoadDB.new(e) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isConnect?(_action) _cmd='connect' _c = Scoutui::Commands::Connect.new(e) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isLoadData?(_action) _cmd='loaddata' _c = Scoutui::Commands::LoadData.new(e) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isLoadRequirements?(_action) _cmd='loadrequirements' _c = Scoutui::Commands::LoadRequirements.new(e) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isAssignments?(_action) _cmd='assignments' if e['page'].has_key?('vars') e['page']['vars'].each do |_a| puts __FILE__ + (__LINE__).to_s + " Process Assignment.var : #{_a}" begin _caborted=false if !Scoutui::Commands::Utils.instance.isAssignVar?(_a) _m=_a.match(/([\w\_])+\=(.*)/) _a="assign(#{_m[1]},#{_m[2]})" end _c = Scoutui::Commands::AssignVar.new(_a) _rc=_c.run(driver: my_driver, dut: e) _c.setResult(_rc) rescue => ex _caborted=true end Testmgr::TestReport.instance.getReq(_req).get_child(_cmd.downcase).add(!_caborted, "Verify command assign did not abort") end end elsif Scoutui::Commands::Utils.instance.isAssignVar?(_action) _cmd='assignvar' _c = Scoutui::Commands::AssignVar.new(_action) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isSelectWindow?(_action) _cmd='SelectWindow' _c = Scoutui::Commands::SelectWindow.new(_action) _c.execute(my_driver) elsif Scoutui::Commands::Utils.instance.isClick?(_action) _cmd='Click' _c = Scoutui::Commands::ClickObject.new(_action) _c.run(driver: my_driver, dut: e) if e[STEP_KEY].has_key?('then') Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " then => #{e[STEP_KEY]['then]']}" end elsif Scoutui::Commands::Utils.instance.isExistsAlert?(_action) _cmd='ExistsAlert' _c = Scoutui::Commands::JsAlert::ExistsAlert.new(_action) rc=_c.execute(my_driver) elsif Scoutui::Commands::Utils.instance.isFrame?(_action) _cmd='IsFrame' _c = Scoutui::Commands::SwitchFrame.new(_action) rc=_c.execute(my_driver, e) elsif Scoutui::Commands::Utils.instance.isGetAlert?(_action) _cmd='GetAlert' _c = Scoutui::Commands::ExistsAlert.new(_action) rc=_c.execute(my_driver) elsif Scoutui::Commands::Utils.instance.isHighlight?(_action) _cmd="Highlight" _c = Scoutui::Commands::Highlight.new(_action) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isMouseOver?(_action) _cmd='MouseOver' _c = Scoutui::Commands::MouseOver.new(_action) _c.execute(my_driver) elsif Scoutui::Commands::Utils.instance.isSelect?(_action) _cmd='Select' _c = Scoutui::Commands::SelectObject.new(_action) _c.run(driver: my_driver, dut: e) elsif Scoutui::Commands::Utils.instance.isFillForm?(_action) _cmd='FillForm' _c = Scoutui::Commands::FillForm.new(_action) _rc=false begin _form = _action.match(/fillform\((.*)\s*\)/)[1].to_s # _dut = _action.match(/fillform\(.*,\s*(.*)\)/)[1].to_s dut = e[STEP_KEY]['dut'] Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " DUT => #{dut}" _f = Scoutui::Utils::TestUtils.instance.getForm(_form) _f.dump() _f.verifyForm(my_driver) _f.fillForm(my_driver, dut) _rc=true rescue ; end _c.setResult(_rc) elsif Scoutui::Commands::Utils.instance.isSubmitForm?(_action) _cmd='SubmitForm' _c = Scoutui::Commands::SubmitForm.new(_action) _c.execute(my_driver) elsif Scoutui::Commands::Utils.instance.isNavigate?(_action) _cmd='Navigate' _c = Scoutui::Commands::UpdateUrl.new(_action) _c.run(driver: my_driver) elsif Scoutui::Commands::Utils.instance.isUploadFiles?(_action) _cmd='UploadFiles' _c = Scoutui::Commands::UploadFiles.new(_action) rc=_c.execute(my_driver, e) elsif Scoutui::Commands::Utils.instance.isVerifyElt?(_action) _cmd='VerifyElement' _c = Scoutui::Commands::VerifyElement.new(_action) _c.run(driver: my_driver) elsif Scoutui::Commands::Utils.instance.isType?(_action) _cmd='Type' _c = Scoutui::Commands::Type.new(_action) _c.run(driver: my_driver) else Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " Unknown command : #{_action}" rc=false end rescue => e Scoutui::Logger::LogMgr.instance.debug "#{e.class.to_s} Error during processing: #{$!}" Scoutui::Logger::LogMgr.instance.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}" puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}" _aborted=true rc=false end if my_driver.window_handles.length > _totalWindows Scoutui::Logger::LogMgr.instance.info " New Window generated from command #{_cmd}." end Testmgr::TestReport.instance.getReq(_req).get_child(_cmd.downcase).add(!_aborted, "Verify command #{_cmd} did not abort") Scoutui::Logger::LogMgr.instance.commands.debug __FILE__ + (__LINE__).to_s + " exit [processCommand(#{_action}) => #{_c}" _c end end