class Scoutui::Commands::JsAlert::ExistsAlert

Public Class Methods

new(_cmd, _drv=nil) click to toggle source
Calls superclass method Scoutui::Commands::Command::new
# 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

Public Instance Methods

alertExists?() click to toggle source
# File lib/scoutui/commands/jsalert/action_jsalert.rb, line 16
def alertExists?
  @_alertExists
end
execute(drv=nil) click to toggle source
# 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() click to toggle source
# File lib/scoutui/commands/jsalert/action_jsalert.rb, line 20
def getAssertText()
  @assertText
end