Class: Scoutui::Commands::JsAlert::ExistsAlert
- Defined in:
- lib/scoutui/commands/jsalert/action_jsalert.rb
Instance Attribute Summary
Attributes inherited from Command
#bm, #cmd, #description, #drv, #enableAssert, #executed, #executed_result, #locator, #rc, #stanza
Instance Method Summary collapse
- #alertExists? ⇒ Boolean
- #execute(drv = nil) ⇒ Object
- #getAssertText ⇒ Object
-
#initialize(_cmd, _drv = nil) ⇒ ExistsAlert
constructor
A new instance of ExistsAlert.
Methods inherited from Command
#assert?, #disableAssert, #disableAsserts, #enableAsserts, #executedResult, #getLocator, #passed?, #result, #run, #setBenchmark, #setLocator, #setResult, #wasExecuted?
Constructor Details
#initialize(_cmd, _drv = nil) ⇒ ExistsAlert
Returns a new instance of ExistsAlert.
8 9 10 11 12 13 14 |
# File 'lib/scoutui/commands/jsalert/action_jsalert.rb', line 8 def initialize(_cmd, _drv=nil) super(_cmd, _drv) @assertText=nil @alert_text=nil @_alertExists=false end |
Instance Method Details
#alertExists? ⇒ Boolean
16 17 18 |
# File 'lib/scoutui/commands/jsalert/action_jsalert.rb', line 16 def alertExists? @_alertExists end |
#execute(drv = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/scoutui/commands/jsalert/action_jsalert.rb', line 24 def execute(drv=nil) @drv=drv if !drv.nil? _rc=nil @_alertExists=false Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " command => #{@cmd.to_s}" _action=@cmd.match(/[!]*(exist[s]*_*alert|existAlert|existsAlert|existsJsAlert|existsJsConfirm|existsJsPrompt)\s*\((.*)\)/i)[2].to_s.strip Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ExistsAlert(#{_action})" alert=nil begin alert=@drv.switch_to.alert Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | alert => #{alert.class.to_s}" @_alertExists = alert.is_a?(Selenium::WebDriver::Alert) if @_alertExists && !(_action.nil? && _action.empty?) _r = Regexp.new _action.to_s @alert_text = alert.text.to_s Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _r => #{_r}" Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " _t => #{alert.text.to_s}" _rc=!alert.text.to_s.match(_r).nil? end rescue Selenium::WebDriver::Error::NoSuchAlertError alert=nil rescue Selenium::WebDriver::Error::WebDriverError # Support for phantomjs/ghostdriver per switch_to.alert() alert=nil end @assertText = "Verify JsAlert is present" if @cmd.match(/^\s*e/i) if (_action.empty?) _rc = @_alertExists else @assertText = "Verify JsAlert exists with matching regex #{_action} (actual: #{@alert_text})" _r = Regexp.new _action.to_s _rc = @_alertExists && !@alert_text.match(_r).nil? end ## # Verify if alert is explicitly NOT present (e.g. !existsAlert() ) # or, # Verify if the existing Alert DOES NOT have matching text. ## elsif @cmd.match(/^\s*!/) _rc = false if !@_alertExists && _action.empty? ## # !existsAlert() ## @assertText = "Verify JsAlert is not present" _rc = true elsif !@_alertExists && !_action.empty? @assertText = "Verify JsAlert exists without matching #{_action}" _rc = false elsif @_alertExists @assertText = "Verify existing JsAlert does not match #{_action}" _rc = @alert_text.match(/#{_action}/).nil? end end # Testmgr::TestReport.instance.getReq('UI').testcase('expectJsAlert').add(@_alertExists, assertText) # if !(_action.nil? && _action.empty?) # Testmgr::TestReport.instance.getReq('UI').get_child('expectJsAlert').add(_rc, assertText) # end Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ExistsAlert() => #{alert.class.to_s} rc:#{_rc.to_s}" setResult(_rc) end |
#getAssertText ⇒ Object
20 21 22 |
# File 'lib/scoutui/commands/jsalert/action_jsalert.rb', line 20 def getAssertText() @assertText end |