Class: Element
- Inherits:
-
Object
- Object
- Element
- Defined in:
- lib/core/PageObject.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#xpath ⇒ Object
Returns the value of attribute xpath.
Instance Method Summary collapse
- #Check ⇒ Object
- #Click ⇒ Object
- #enabled ⇒ Object
- #exists ⇒ Object
-
#Exists ⇒ Object
Verification methods will raise error if failed, don’t use for check condition logic.
-
#get ⇒ Object
Basic element properties.
- #get_checkbox ⇒ Object
- #get_radio ⇒ Object
- #get_select ⇒ Object
- #HasItem(value) ⇒ Object
-
#initialize(page, object) ⇒ Element
constructor
A new instance of Element.
- #IsChecked ⇒ Object
- #IsNotSelected ⇒ Object
- #IsSelected ⇒ Object
- #IsUnchecked ⇒ Object
- #NotExists ⇒ Object
-
#SelectItem(value) ⇒ Object
def Select() ## for radio button radio = self.get_radio radio.set return true end.
-
#SendKeys(value) ⇒ Object
Action methods.
- #Uncheck ⇒ Object
- #value ⇒ Object
- #ValueContains(value) ⇒ Object
- #ValueIs(value) ⇒ Object
- #ValueIsBetween(value1, value2) ⇒ Object
- #ValueIsEmpty ⇒ Object
- #ValueIsLessThan(value) ⇒ Object
- #ValueIsLessThanOrEqual(value) ⇒ Object
- #ValueIsMoreThan(value) ⇒ Object
- #ValueIsMoreThanOrEqual(value) ⇒ Object
- #ValueIsNot(value) ⇒ Object
- #ValueIsNotEmpty ⇒ Object
Constructor Details
#initialize(page, object) ⇒ Element
Returns a new instance of Element.
12 13 14 15 16 |
# File 'lib/core/PageObject.rb', line 12 def initialize(page, object) @page = page @name = object['name'] @xpath = object['xpath'] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/core/PageObject.rb', line 10 def name @name end |
#xpath ⇒ Object
Returns the value of attribute xpath.
10 11 12 |
# File 'lib/core/PageObject.rb', line 10 def xpath @xpath end |
Instance Method Details
#Check ⇒ Object
123 124 125 126 127 |
# File 'lib/core/PageObject.rb', line 123 def Check() checkbox = self.get_checkbox checkbox.set return true end |
#Click ⇒ Object
105 106 107 108 109 |
# File 'lib/core/PageObject.rb', line 105 def Click() element = self.get element.click return true end |
#enabled ⇒ Object
55 56 57 |
# File 'lib/core/PageObject.rb', line 55 def enabled return false end |
#exists ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/core/PageObject.rb', line 45 def exists element = self.get if element.exists? return true else return false end end |
#Exists ⇒ Object
Verification methods will raise error if failed, don’t use for check condition logic
139 140 141 142 143 144 145 146 |
# File 'lib/core/PageObject.rb', line 139 def Exists() if self.exists return true end Log.Failed("Value not matched", '<not exists>', '<exists>') return false end |
#get ⇒ Object
Basic element properties
22 23 24 |
# File 'lib/core/PageObject.rb', line 22 def get return @page.browser.element(:xpath => @xpath) end |
#get_checkbox ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/core/PageObject.rb', line 59 def get_checkbox element = self.get if element.tag_name == 'input' and element.attribute_value('type') == 'checkbox' checkbox = @page.browser.checkbox(:xpath => @xpath) return checkbox end Log.Failed("The element '#{@name}' is not type 'checkbox'\n") return nil end |
#get_radio ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/core/PageObject.rb', line 71 def get_radio element = self.get if element.tag_name == 'input' and element.attribute_value('type') == 'radio' radio = @page.browser.radio(:xpath => @xpath) return radio end Log.Failed("The element '#{@name}' is not type 'radio'\n") return nil end |
#get_select ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/core/PageObject.rb', line 83 def get_select element = self.get if element.tag_name == 'select' select = @page.browser.select_list(:xpath => @xpath) return select end Log.Failed("The element '#{@name}' is not type 'select'\n") return nil end |
#HasItem(value) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/core/PageObject.rb', line 253 def HasItem(value) select = self.get_select = [] for option in select. << option.text end if .include? value return true end Log.Failed("Item not found in list", "\n\t" + .join("\n\t"), value) return false end |
#IsChecked ⇒ Object
291 292 293 294 295 296 297 298 299 300 |
# File 'lib/core/PageObject.rb', line 291 def IsChecked() checkbox = self.get_checkbox if checkbox.set? return true end Log.Failed("Value not matched", '<not checked>', '<checked>') return false end |
#IsNotSelected ⇒ Object
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/core/PageObject.rb', line 280 def IsNotSelected() radio = self.get_radio if not radio.set? return true end Log.Failed("Value not matched", '<selected>', '<not selected>') return false end |
#IsSelected ⇒ Object
269 270 271 272 273 274 275 276 277 278 |
# File 'lib/core/PageObject.rb', line 269 def IsSelected() radio = self.get_radio if radio.set? return true end Log.Failed("Value not matched", '<not selected>', '<selected>') return false end |
#IsUnchecked ⇒ Object
302 303 304 305 306 307 308 309 310 311 |
# File 'lib/core/PageObject.rb', line 302 def IsUnchecked() checkbox = self.get_checkbox if not checkbox.set? return true end Log.Failed("Value not matched", 'checked>', '<unchecked>') return false end |
#NotExists ⇒ Object
148 149 150 151 152 153 154 155 |
# File 'lib/core/PageObject.rb', line 148 def NotExists() if not self.exists return true end Log.Failed("Value not matched", '<exists>', '<not exists>') return false end |
#SelectItem(value) ⇒ Object
def Select() ## for radio button radio = self.get_radio radio.set return true end
117 118 119 120 121 |
# File 'lib/core/PageObject.rb', line 117 def SelectItem(value) ## for select list select = self.get_select select.select(value) return true end |
#SendKeys(value) ⇒ Object
Action methods
99 100 101 102 103 |
# File 'lib/core/PageObject.rb', line 99 def SendKeys(value) element = self.get element.send_keys(value) return true end |
#Uncheck ⇒ Object
129 130 131 132 133 |
# File 'lib/core/PageObject.rb', line 129 def Uncheck() checkbox = self.get_checkbox checkbox.clear return true end |
#value ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/core/PageObject.rb', line 26 def value element = self.get if element.tag_name == 'select' select = self.get_select text = [] for option in select. text << option.text end return text.join('\n') elsif ['input', 'button'].include? element.tag_name return element.value else return element.text end end |
#ValueContains(value) ⇒ Object
193 194 195 196 197 198 199 200 |
# File 'lib/core/PageObject.rb', line 193 def ValueContains(value) if self.value.include? value return true end Log.Failed("Value not matched", self.value, value) return false end |
#ValueIs(value) ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/core/PageObject.rb', line 175 def ValueIs(value) if self.value == value return true end Log.Failed("Value not matched", self.value, value) return false end |
#ValueIsBetween(value1, value2) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/core/PageObject.rb', line 238 def ValueIsBetween(value1, value2) if value1 < value2 if self.value >= value1 and self.value <= value2 return true end else if self.value <= value1 and self.value >= value2 return true end end Log.Failed("Value not matched", self.value, " x in (#{value1} - #{value2})") return false end |
#ValueIsEmpty ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/core/PageObject.rb', line 157 def ValueIsEmpty() if self.value == '' return true end Log.Failed("Value not matched", self.value, '<empty>') return false end |
#ValueIsLessThan(value) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/core/PageObject.rb', line 220 def ValueIsLessThan(value) if self.value < value return true end Log.Failed("Value not matched", self.value, "( x < #{value} )") return false end |
#ValueIsLessThanOrEqual(value) ⇒ Object
229 230 231 232 233 234 235 236 |
# File 'lib/core/PageObject.rb', line 229 def ValueIsLessThanOrEqual(value) if self.value <= value return true end Log.Failed("Value not matched", self.value, "( x <= #{value} )") return false end |
#ValueIsMoreThan(value) ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/core/PageObject.rb', line 202 def ValueIsMoreThan(value) if self.value > value return true end Log.Failed("Value not matched", self.value, "( x > #{value} )") return false end |
#ValueIsMoreThanOrEqual(value) ⇒ Object
211 212 213 214 215 216 217 218 |
# File 'lib/core/PageObject.rb', line 211 def ValueIsMoreThanOrEqual(value) if self.value >= value return true end Log.Failed("Value not matched", self.value, "( x >= #{value} )") return false end |
#ValueIsNot(value) ⇒ Object
184 185 186 187 188 189 190 191 |
# File 'lib/core/PageObject.rb', line 184 def ValueIsNot(value) if self.value != value return true end Log.Failed("Value not matched", self.value, value) return false end |
#ValueIsNotEmpty ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/core/PageObject.rb', line 166 def ValueIsNotEmpty() if self.value != '' return true end Log.Failed("Value not matched", '<empty>', '<not empty>') return false end |