Class: Sapphire::WebAbstractions::List

Inherits:
Control show all
Defined in:
lib/sapphire/WebAbstractions/Controls/List.rb

Instance Attribute Summary

Attributes inherited from Control

#control, #found_by_type, #found_by_value

Instance Method Summary collapse

Methods inherited from Control

#Evaluate, #Find, #FindAll, #FindWithoutWait, #GetValue, #MouseOver, #Substitute, #Visible

Constructor Details

#initialize(hash) ⇒ List

Returns a new instance of List.



5
6
7
8
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 5

def initialize(hash)
  @retryAttempts = 0
  super hash
end

Instance Method Details

#ClickObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 57

def Click
  wait = Selenium::WebDriver::Wait.new(:timeout => 20)
  begin
    clicked = wait.until { items = self.FindAll
    if !items.empty? && items.first.Visible
      items.first.Click
      return true
    end
    }
    return nil
  rescue
    #retry a few times because in strange events from finding all the elements to trying to click one, it can become
    #unavailable
    if(@retryAttempts < 2)
      @retryAttempts = @retryAttempts + 1
      self.Click
    else
      return nil
    end
  end
end

#Contain(expected_text) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 46

def Contain(expected_text)
  text = self.Text
  text.each do |t|
    if t.include? expected_text
      return ContainsComparison.new(ControlEvaluation.new(t, expected_text, nil))
    end
  end

  return ControlEvaluation.new("Value not found in list", expected_text, self)
end

#Count(value) ⇒ Object



79
80
81
82
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 79

def Count(value)
  items = self.FindAll
  return ControlEvaluation.new(items.count, value, self)
end

#Equals(value, comparator) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 10

def Equals(value, comparator)
  x = self.FindAll
  x.each do |item|
    if comparator.Compare(item.Text, value)
      return  EqualsComparison.new(ControlEvaluation.new(item.Text, value, item))
    end
  end

  #if here then it couldnt make a match, build up the list of values
  alltext = []
  x.each do |item|
    alltext << item.Text
  end

  return EqualsComparison.new(ControlEvaluation.new(alltext, value, self))
end

#In(values, comparator) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 27

def In(values, comparator)
  x = self.FindAll
  x.each do |item|
    values.each do |value|
      if comparator.Compare(item.Text, value)
        return ControlEvaluation.new(item.Text, value, item)
      end
    end
  end

  #if here then it couldnt make a match, build up the list of values
  alltext = []
  x.each do |item|
    alltext << item.Text
  end

  return ControlEvaluation.new(values, alltext, self)
end

#TextObject



84
85
86
87
88
89
90
91
92
# File 'lib/sapphire/WebAbstractions/Controls/List.rb', line 84

def Text
  values = []
  x = self.FindAll
  x.each do |item|
    values << item.control.text
  end

  return values
end