class LdsTextField

Public Class Methods

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

constructor

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

Public Instance Methods

fill(value) click to toggle source

LdsScreen Actions

# File lib/TNR360/components/lds_text_field.rb, line 150
def fill (value)
  @browser.text_field(:id => @idField).when_present.set(value)
  update
end
findElement(idElement) click to toggle source

method locate current element

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

  #wait for screen to become visible (find screen forcefully)
  proc=Proc.new { isScreenDisplayed }
  puts 'Screen found = '+ 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 'Element found = '+@exists.to_s


  if (@browser.text_fields(:id => idElement).length>1 && @idBlock!=nil)
    #utiliser le id bloc
    @bloc=LdsBlock.new(@browser, @idBlock)
    @current_element=@bloc.getElement.text_field(:id, idElement).when_present
  else
    if (@browser.text_fields(:id => idElement).length>1)
      @browser.text_fields(:id => idElement).each do |field|
        if field.visible?
          @current_element=field
          break
        end
      end
    else
      @current_element=@browser.text_field(:id, idElement).when_present
    end
  end
  if @current_element.visible?
    puts 'element is visible'
  else
    puts 'element is NOT visible'
  end
  @current_element
end
getElement() click to toggle source

Getters

# File lib/TNR360/components/lds_text_field.rb, line 158
def getElement
  @current_element
end
getIdBlock() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 166
def getIdBlock
  @idBlock
end
getIdScreen() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 170
def getIdScreen
  @idScreen
end
getIdentifier() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 162
def getIdentifier
  @idField
end
getLabel() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 178
def getLabel
  @label
end
getValue() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 174
def getValue
  @value
end
isEditable?() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 190
def isEditable?
  @editable
end
isExist?() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 194
def isExist?
  @exists
end
isMandatory?() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 182
def isMandatory?
  @mandatory
end
isScreenDisplayed() click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 98
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_text_field.rb, line 186
def isVisible?
  @visible
end
refresh() click to toggle source

refresh object status from browser

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

print object

# File lib/TNR360/components/lds_text_field.rb, line 134
def to_s
  "\n***** Text_Field *****"+
      "\nId : "+no_null(@idField) +
      "\nIdBlock : "+ no_null(@IdBlock)+
      "\nIdScreen : "+ no_null(@IdScreen) +
      "\nValue : "+ no_null(@value)+
      "\nLabel : "+ no_null(@label)+
      "\nMandatory : "+ no_null(@mandatory.to_s)+
      "\nVisible : "+ no_null(@visible.to_s)+
      "\nEditable : "+ no_null(@editable.to_s)+
      "\nExists : "+ no_null(@exists.to_s)+
      "\n**********"
end

Private Instance Methods

elementExists?(idElement) click to toggle source
# File lib/TNR360/components/lds_text_field.rb, line 107
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.text_field(:id => idElement).exists?)
    @browser.text_field(:id => idElement).when_present($wait_time.to_i)
    oneIsVisible=true
  else
    if (!@browser.text_field(:id => idElement).visible?)
      @browser.text_fields(:id => idElement).each do |field|
        if field.visible?
          oneIsVisible=true
          break
        end
      end
      if !oneIsVisible
        @browser.text_field(:id => idElement).when_present($wait_time.to_i)
        oneIsVisible=true
      end
    else
      oneIsVisible=true
    end
  end
  oneIsVisible
end
update() click to toggle source

private method to update/save the status of the object

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

  #Look for element in browser
  @current_element||= findElement @idField
  #fill value
  @value=@current_element.value
  #fill label
  @label=@current_element.name
  #fill isMandatory #TODO
  ## @mandatory=@browser.label(:for, @idField).when_present.style.include? "bold"
  #fill visible
  @visible=@current_element.visible?
  #fill editable
  @editable=!(@current_element.readonly?)
  #everything exists
  @exists=true
end