class Element

Attributes

name[RW]
xpath[RW]

Public Class Methods

new(page, object) click to toggle source
# File lib/core/PageObject.rb, line 12
def initialize(page, object)
        @page = page
        @name = object['name']
        @xpath = object['xpath']
end

Public Instance Methods

Check() click to toggle source
# File lib/core/PageObject.rb, line 123
def Check()
        checkbox = self.get_checkbox
        checkbox.set
        return true
end
Click() click to toggle source
# File lib/core/PageObject.rb, line 105
def Click()
        element = self.get
        element.click
        return true
end
Exists() click to toggle source

Verification methods will raise error if failed, don’t use for check condition logic

# 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
HasItem(value) click to toggle source
# File lib/core/PageObject.rb, line 253
def HasItem(value)
        select = self.get_select

        options = []
        for option in select.options
                options << option.text
        end

        if options.include? value
                return true
        end

        Log.Failed("Item not found in list", "\n\t" + options.join("\n\t"), value)
        return false
end
IsChecked() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source

def Select() ## for radio button

radio = self.get_radio
radio.set
return true

end

# 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) click to toggle source

Action methods

# File lib/core/PageObject.rb, line 99
def SendKeys(value)
        element = self.get
        element.send_keys(value)
        return true
end
Uncheck() click to toggle source
# File lib/core/PageObject.rb, line 129
def Uncheck()
        checkbox = self.get_checkbox
        checkbox.clear
        return true
end
ValueContains(value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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
enabled() click to toggle source
# File lib/core/PageObject.rb, line 55
def enabled
        return false
end
exists() click to toggle source
# File lib/core/PageObject.rb, line 45
def exists
        element = self.get
        
        if element.exists?
                return true
        else
                return false
        end
end
get() click to toggle source

Basic element properties

# File lib/core/PageObject.rb, line 22
def get
        return @page.browser.element(:xpath => @xpath)
end
get_checkbox() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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
value() click to toggle source
# 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.selected_options
                        text << option.text
                end

                return text.join('\n')
        elsif ['input', 'button'].include? element.tag_name
                return element.value
        else
                return element.text
        end
end