class LdsBlock

Public Class Methods

new(browser, idBlock, idScreen=nil) click to toggle source

constructor

# File lib/TNR360/components/lds_block.rb, line 26
def initialize(browser, idBlock, idScreen=nil)
  @browser =browser
  @idBlock=idBlock
  @idScreen=idScreen
  update
  @exists
end

Public Instance Methods

collapse() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 205
def collapse
  if (@collapsible && !@collapsed)
    @current_element.div(:index => 0).div(:index => 0).div.when_present.click
  end
  update
end
elementExists?(idElement) click to toggle source
# File lib/TNR360/components/lds_block.rb, line 139
def elementExists?(idElement)
  #this method assumes the screen/tab is already loaded
  oneIsVisible=false
  #if element not yet available in screen, wait for some time
  if (!@browser.div(:id => idElement).exists?)
    @browser.div(:id => idElement).when_present(10)
    oneIsVisible=true
  else
    if (!@browser.div(:id => idElement).visible?)
      @browser.divs(:id => idElement).each do |field|
        if field.visible?
          oneIsVisible=true
          break
        end
      end
      if !oneIsVisible
        @browser.div(:id => idElement).when_present(10)
        oneIsVisible=true
      end
    else
      oneIsVisible=true
    end
  end
  oneIsVisible
end
expand() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 212
def expand
  if (@collapsible && @collapsed)
    @current_element.div(:index => 0).div(:index => 0).div.when_present.click
  end
  update
end
extractAreas() click to toggle source

internal methods

# File lib/TNR360/components/lds_block.rb, line 76
def extractAreas
  if (@hasMultipleAreas)
    @areas=Array.new
    #iterate through list of areas
    @current_element.fieldsets.each do |fieldset|
      @areas << LdsArea.new(@browser, fieldset.id.to_s, self)
    end
  end
end
findElement(idElement) click to toggle source

method locate current element

# File lib/TNR360/components/lds_block.rb, line 104
def findElement idElement
  @current_element=nil

  #wait for screen to become visible (find screen forcefully)
  proc=Proc.new { isScreenDisplayed }
  force_find_element(proc).to_s

  #wait for screen to become visible (find screen forcefully)
  proc=Proc.new { elementExists?(idElement) }
  @exists=force_find_element(proc)
  puts 'Block found = '+@exists.to_s

  if (@browser.divs(:id => idElement).length>1)
    @browser.divs(:id => idElement).each do |field|
      if field.visible?
        @current_element=field
        break
      end
    end
  else
    @current_element=@browser.div(:id => idElement).when_present
  end


  if @current_element.visible?
    puts 'block is visible'
  else
    puts 'block is NOT visible'
  end
  @current_element


end
getAreas() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 237
def getAreas
  @areas
end
getElement() click to toggle source

Getters

# File lib/TNR360/components/lds_block.rb, line 221
def getElement
  @current_element
end
getIdBlock() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 225
def getIdBlock
  @idBlock
end
getIdScreen() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 229
def getIdScreen
  @idScreen
end
getTitle() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 233
def getTitle
  @title
end
getType() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 241
def getType
  @type
end
hasMultipleAreas?() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 245
def hasMultipleAreas?
  @hasMultipleAreas
end
isCollapsed?() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 253
def isCollapsed?
  @collapsed
end
isCollapsible?() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 249
def isCollapsible?
  @collapsible
end
isExist?() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 261
def isExist?
  @exists
end
isScreenDisplayed() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 165
def isScreenDisplayed
  if (@idScreen!=nil)
    @scr=LdsScreen.new(@browser, @idScreen)
    @scr.isVisible?
  else
    false
  end
end
isVisible?() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 257
def isVisible?
  @visible
end
refresh() click to toggle source

refresh object status from browser

# File lib/TNR360/components/lds_block.rb, line 36
def refresh
  #Look for element in browser
  @current_element= findElement @idBlock
  #update other data
  update
  @exists
end
reverse_collapse() click to toggle source

LdsScreen Actions

# File lib/TNR360/components/lds_block.rb, line 198
def reverse_collapse
  if (@collapsible)
    @current_element.div(:index => 0).div(:index => 0).div.when_present.click
  end
  update
end
to_s() click to toggle source

print object

# File lib/TNR360/components/lds_block.rb, line 176
def to_s
  if (@hasMultipleAreas && @areas!=nil)
    @areas.each do |area|
      area.to_s
    end
  else
    "\n***** Block *****"+
        "\nIdBlock : "+ no_null(@idBlock)+
        "\nIdScreen : "+ no_null(@idScreen) +
        "\nTitle : "+ no_null(@title)+
        "\nCollapsible :"+ bool_no_null(@collapsible.to_s)+
        "\nCollapsed :"+ bool_no_null(@collapsed.to_s)+
        "\nVisible : "+ bool_no_null(@visible.to_s)+
        "\nExists : "+ bool_no_null(@exists.to_s)+
        "\nHasMultipleAreas :"+ bool_no_null(@hasMultipleAreas.to_s)+
        "\nType :"+ no_null(@type.to_s)+
        "\n**********"
  end
end

Private Instance Methods

extractTitle() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 95
def extractTitle
  if @current_element.div(:index => 0).spans.length>0
    @title=@current_element.div(:index => 0).span(:index => 0).text
  else
    @title=""
  end
end
extractType() click to toggle source
# File lib/TNR360/components/lds_block.rb, line 87
def extractType
  if (@current_element.class_name.include? "form")
    @type="Form"
  else
    @type="Grid"
  end
end
update() click to toggle source

private method to update/save the status of the object

# File lib/TNR360/components/lds_block.rb, line 45
def update
  @exists=false

  #Look for element in browser
  @current_element||= findElement @idBlock

  # fill hasMultipleAreas
  @hasMultipleAreas=(@current_element.div(:index => 2).fieldsets.length>1 ? true : false)

  if (@hasMultipleAreas)
    #extract areas if available
    extractAreas
  else
    #fill @title
    extractTitle
    #fill visible
    @visible=@current_element.visible?
    #fill type
    extractType
    #fill isCollapsible
    @collapsible=@current_element.div(:index => 0).div(:index => 0).div.exists?
    #fill isCollapsed
    @collapsed=@current_element.class_name.include? "collapsed"
  end
  #everything exists
  @exists=true
end