Class: Scoutui::Commands::ExistsAlert

Inherits:
Command
  • Object
show all
Defined in:
lib/scoutui/commands/exists_alert.rb

Instance Attribute Summary

Attributes inherited from Command

#bm, #cmd, #description, #drv, #enableAssert, #executed, #executed_result, #locator, #rc, #stanza

Instance Method Summary collapse

Methods inherited from Command

#assert?, #disableAssert, #disableAsserts, #enableAsserts, #executedResult, #getLocator, #initialize, #passed?, #result, #run, #setBenchmark, #setLocator, #setResult, #wasExecuted?

Constructor Details

This class inherits a constructor from Scoutui::Commands::Command

Instance Method Details

#execute(drv = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
# File 'lib/scoutui/commands/exists_alert.rb', line 8

def execute(drv=nil)
  @drv=drv if !drv.nil?

  _action = @cmd.match(/(get_*alert|clickjsconfirm|clickjsprompt|clickjsalert)\s*\((.*)\)/i)[2].to_s.strip

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ExistsAlert(#{_action})"  if Scoutui::Utils::TestUtils.instance.isDebug?

  rc=false

  alert=nil

  begin
    alert=@drv.switch_to.alert

    Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | alert => #{alert.class.to_s}" if Scoutui::Utils::TestUtils.instance.isDebug?
    Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " | alert.text => #{alert.text.to_s}"

    if alert.is_a?(Selenium::WebDriver::Alert)
      if _action.match(/accept/i)
        alert.accept
      elsif _action.match(/dismiss/i)
        alert.dismiss
      end

      rc=true
    end

  rescue Selenium::WebDriver::Error::NoSuchAlertError
    ;
  rescue Selenium::WebDriver::Error::WebDriverError
    # Support for phantomjs/ghostdriver per switch_to.alert()
    ;
  end

  _req = Scoutui::Utils::TestUtils.instance.getReq()

  Testmgr::TestReport.instance.getReq(_req).testcase(_action).add(!alert.nil?, "Verify alert exists")
  Testmgr::TestReport.instance.getReq(_req).testcase(_action).add(rc, "Verify processed alert")

  Scoutui::Logger::LogMgr.instance.debug __FILE__ + (__LINE__).to_s + " ExistsAlert() => #{rc.to_s}"  if Scoutui::Utils::TestUtils.instance.isDebug?

  setResult(rc)
  rc

end