Class: Scoutui::Commands::JsAlert::ExistsAlert
- Inherits:
-
Command
- Object
- Command
- Scoutui::Commands::JsAlert::ExistsAlert
show all
- 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
Methods inherited from Command
#assert?, #disableAssert, #disableAsserts, #enableAsserts, #executedResult, #getLocator, #passed?, #result, #run, #setBenchmark, #setLocator, #setResult, #wasExecuted?
Constructor Details
#initialize(_cmd, _drv = nil) ⇒ 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
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
elsif @cmd.match(/^\s*!/)
_rc = false
if !@_alertExists && _action.empty?
@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
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
|