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.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 8
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 = @by
@found_by_value = @value
end
end
|
Instance Attribute Details
#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
44
45
46
47
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 44
def Click
control = self.Find
control.click
end
|
#Contain(value) ⇒ Object
72
73
74
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 72
def Contain(value)
return ContainsComparison.new(ControlEvaluation.new(self.Text, value, self))
end
|
#Equals(value, comparator) ⇒ Object
67
68
69
70
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 67
def Equals(value, comparator)
evaluation = ControlEvaluation.new(self.Text, value, self)
EqualsComparison.new(evaluation)
end
|
#Evaluate(key, arg, comparator, block) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 88
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
return ControlEvaluation.new(evaluation.left, evaluation.right, self)
end
end
|
#Find(comparator = nil) ⇒ Object
19
20
21
22
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 19
def Find(comparator = nil)
@control, @found_by_type, @found_by_value = $driver.FindItemWithWait(@array, comparator) if @control.nil?
@control
end
|
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 24
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
35
36
37
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 35
def FindWithoutWait(comparator = nil)
$driver.FindItemWithoutWait(@array, comparator)
end
|
#GetValue(item, key) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 112
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
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 76
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
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 49
def MouseOver
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
131
132
133
134
135
136
137
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 131
def Substitute(item)
return $page.Get(item) if $page.Contains(item)
return Parameter(item) if Parameters.instance.Contains(item)
return item
end
|
39
40
41
42
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 39
def Text
text = self.Find
text.text
end
|
#Visible(shouldWait = true) ⇒ Object
61
62
63
64
65
|
# File 'lib/sapphire/WebAbstractions/Controls/Base/Control.rb', line 61
def Visible(shouldWait = true)
control = self.Find if shouldWait
control = self.FindWithoutWait if !shouldWait
ControlEvaluation.new(control.displayed?, true, self)
end
|