Class: Sapphire::WebAbstractions::Control
- Inherits:
-
Object
- Object
- Sapphire::WebAbstractions::Control
show all
- Defined in:
- lib/sapphire/WebAbstractions/Controls/Base/Control.rb
Direct Known Subclasses
AlertBox, Button, CheckBox, Date, DropDown, Hyperlink, Image, Label, List, RadioButton, TextArea, TextBox, Title
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ Control
Returns a new instance of Control.
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 9
def initialize(args)
return if args.nil?
@array = args
if args.is_a? Hash
@control = args.fetch :instance if args.has_key? :instance
@found_by_type = args.keys.first
@found_by_value = args.fetch(args.keys.first)
end
end
|
Instance Attribute Details
Returns the value of attribute control.
7
8
9
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 7
def control
@control
end
|
#found_by_type ⇒ Object
Returns the value of attribute found_by_type.
5
6
7
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 5
def found_by_type
@found_by_type
end
|
#found_by_value ⇒ Object
Returns the value of attribute found_by_value.
6
7
8
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 6
def found_by_value
@found_by_value
end
|
Instance Method Details
46
47
48
49
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 46
def Click
self.Find if @control.nil?
@control.click
end
|
#Contain(expected_value) ⇒ Object
76
77
78
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 76
def Contain(expected_value)
return ContainsComparison.new(ControlEvaluation.new(self.Text, expected_value, self))
end
|
#Equals(value, comparator) ⇒ Object
71
72
73
74
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 71
def Equals(value, comparator)
evaluation = ControlEvaluation.new(self.Text, value, self)
EqualsComparison.new(evaluation)
end
|
#Evaluate(key, arg, comparator, block) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 92
def Evaluate(key, arg, comparator, block)
value = GetValue(arg, key)
timeout = GetValue(arg, :wait)
timeout ||= 20
begin
value = value.Text if value.is_a? Control
evaluation = block.call(self, value)
wait = Selenium::WebDriver::Wait.new(:timeout => timeout)
result = wait.until {
evaluation = block.call(self, value)
y = evaluation.Evaluate()
comparator = EqualsComparison.new(evaluation) if evaluation == nil
evaluation if comparator.Compare(y == true, true)
}
return result
rescue
puts $!.backtrace if !$verbose.nil?
return ControlEvaluation.new(evaluation.left, evaluation.right, self)
end
end
|
#Find(comparator = nil) ⇒ Object
20
21
22
23
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 20
def Find(comparator = nil)
@control, @found_by_type, @found_by_value = $driver.FindItemWithWait(@array, comparator)
@control
end
|
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 25
def FindAll
items, @found_by_type, @found_by_value = $driver.FindAllItems(@array)
list = []
items.each do |item|
hash = {@found_by_type => @found_by_value, :instance => item}
list << Control.new(hash)
end
list
end
|
#FindWithoutWait(comparator = nil) ⇒ Object
36
37
38
39
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 36
def FindWithoutWait(comparator = nil)
@control, @found_by_type, @found_by_value = $driver.FindItemWithoutWait(@array, comparator)
@control
end
|
#GetValue(item, key) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 117
def GetValue(item, key)
if item.is_a? Array
item.each do |sub_item|
value = GetValue(sub_item, key)
return value if !value.nil?
end
end
if item.is_a? Hash
return Substitute(key) if Parameters.instance.Contains(key)
return Substitute(item[key]) if item.has_key? key
end
return Parameter(key) if Parameters.instance.Contains(key)
nil
end
|
#In(values, comparator) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 80
def In(values, comparator)
text = self.Text
values.each do |value|
if comparator.Compare(text, value)
return ControlEvaluation.new(text, value, self)
end
end
return ControlEvaluation.new(text, values, self)
end
|
#MouseOver ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 51
def MouseOver
self.Find
if(@found_by_type == :id)
$driver.ExecuteScript("document.getElementById('"+ @found_by_value +"').style.visibility = 'visible'; ")
elsif (@found_by_type == :name)
$driver.ExecuteScript("document.getElementByName('"+ @found_by_value +"').style.visibility = 'visible'; ")
elsif (@found_by_type == :xpath)
$driver.ExecuteScript("document.evaluate( '" + @found_by_value + "', document, null, XPathResult.ANY_TYPE, null ).iterateNext().style.visibility = 'visible'; ")
end
sleep(1)
end
|
#Substitute(item) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 136
def Substitute(item)
return $page.Get(item) if $page.Contains(item)
return Parameter(item) if Parameters.instance.Contains(item)
return item
end
|
41
42
43
44
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 41
def Text
text = self.Find
text.text
end
|
#Visible(shouldWait = true, comparator = nil) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 64
def Visible(shouldWait = true, comparator = nil)
control = self.Find comparator if shouldWait
control = self.FindWithoutWait comparator if !shouldWait
return ControlEvaluation.new(comparator.Compare(control.displayed?, true), true, self) if !comparator.nil?
ControlEvaluation.new(control.displayed?, true, self)
end
|