Class: Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb

Overview

A class defining a flow. This contains the fields to be interacted with, in their proper sequence, with valid or invalid values

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Flow

Returns a new instance of Flow.



35
36
37
38
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 35

def initialize(name)
  @name = name
  @flow_map = []
end

Instance Attribute Details

#flow_mapObject

some collection of Flow, FlowField & other Flow-type objects # TODO



33
34
35
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 33

def flow_map
  @flow_map
end

#nameObject

Returns the value of attribute name.



32
33
34
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 32

def name
  @name
end

Instance Method Details

#==(o) ⇒ Object

TODO needed?



45
46
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 45

def ==(o)
end

#add(flow_item) ⇒ Object



40
41
42
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 40

def add(flow_item)
  @flow_map << flow_item
end

#execute(browser, custom_values_hash = {}, success_sym = :success, mandatory_fields_sym = :mandatory) ⇒ Object

Executes the flow Takes symbols which act as flags : success_sym - set to :success for a valid set of inputs, set to :fail for one or more of the inputs to be invalid and the flow to fail mandatory_fields_sym - set to :mandatory to only involve the mandatory fields, set to :all_fields to use all defined fields in the flow custom_values_hash - hash of values some/all of the fields must take (e.g. creating a new record with a specific foreign key) keys are field names (as defined in CeresFlows) in either symbol or string form, values are the values the fields should take TODO : don’t want to have to pass in browser each time



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 64

def execute(browser, custom_values_hash = {}, success_sym = :success, mandatory_fields_sym = :mandatory)
  report = nil # if report is still nil at the end of the method, generate a dummy one
  return_value = nil # default value that will be fed into the report # TODO needs to be an array? Or hold multiple
  # values?
  #    pass = true
  #    all = true
  case success_sym
    when :success
      pass = true
    when :fail
      pass = false
    else
      raise "Did not understand value '#{success_sym.inspect}' for success_sym"
  end

  case mandatory_fields_sym
    when :mandatory
      all = false
    when :all_fields
      all = true
    else
      raise "Did not understand value '#{mandatory_fields_sym.inspect}' for mandatory_fields_sym"
  end

  @flow_map.each do |flow_item|
    case flow_item
      when Flow # flows can contain sub-flows
        flow_item.execute(browser, custom_values_hash, success_sym, mandatory_fields_sym) # call recursively
      when FlowPrecondition
        # TODO : find flow from name & execute it
        flow_item.execute_precondition_flow(custom_values_hash)
      when FlowLink
        # debugging
        #          puts "Executing #{flow_item.name}"
        #          puts browser.url

        browser.link(:id => flow_item.name).click

        sleep 1 # TODO determine expected page, call page.wait_until_displayed
      when FlowField
        puts "Now executing field #{flow_item.to_s}"
        next if all == false && flow_item.mandatory == false # skip optional fields if instructed

        field = nil
        
        # TODO : look up field identification parameters (e.g. :id => something) from field definition in xxabbrevxx_pages
        #        The linkage should be that the NAME of the xxabbrevxx_page field (e.g. page.add_field("role", :list, :id, "user_role") )
        #        matches the NAME of the flow_item. We therefore use flow_item.name to track down the field identification parameters
        #        stored in the field definition in xxabbrevxx_pages (in this example, :id, "user_role" )
        # Until this is done, flow_item.name needs to match the xxabbrevxx_pages field ident param.
        
        case flow_item.type
          # TODO only have this case statement determine field type, then pass it into one eval line instead of one
          # line per type
          # Type field completion may differ by more than just their field type...

          when :string
            field = browser.text_field(:id => flow_item.name)
          when :p
            field = browser.p(:id => flow_item.name)
          when :div
            field = browser.div(:id => flow_item.name)
          when :checkbox
            field = browser.input(:id => flow_item.name)
          when :list
#              field = browser.select_list(:id => flow_item.name)
            field = browser.select(:id => flow_item.name)
          when :button
            # buttons only have one function - to be pressed, not to be read or written to
            browser.button(:id => flow_item.name).click
          else
            raise "Cannot execute #{flow_item.class} of type #{flow_item.type}"
        end
        case flow_item.operation
          when :read
            case flow_item.type
              when :string, :checkbox, :list, :p, :div
#                  puts "value : #{field.value}"
#                puts "text : #{field.text}"
                return_value = field.value
              return_value = field.text if return_value == "" # p needs .text
#                  puts "return_value : #{return_value}"
            end
          when :write
            # get valid value from hash, if it has been specified
            value = custom_values_hash[flow_item.name.to_sym].to_s # flow_item.name is defined in xxabbrevxx_flows to be a string; it is nicer if the custom hash keys are symbols, but we then need to convert them
            value = flow_item.random_valid_value if value == nil
            #        value = flow_item.random_invalid_value if invalid # TODO enable
            case flow_item.type
              when :string, :checkbox
                field.set(value)
              when :list
                field.select(value)
            end
        end
      when FlowVerify
        name = "verify"
        verify_flow = Flow.new(name)
        verify_flow.add(flow_item.flow_field)
        # call recursively, have it generate a Report, perform validation against the Report
        report = verify_flow.execute(browser)
#puts "report : #{report}"
        value = report.value
        flow_item.verify(value)
        return_value = "FlowVerify passed : #{flow_item}"
      when FlowReport # not yet in use - no FlowReports have been defined in xxabbrevxx_flows
        report = flow_item.generate_report
      else
        raise "Cannot execute flow item of class #{flow_item.class}"
    end # end case
  end # end .each
  if report == nil # if report is still nil at the end of the method, generate a dummy one
    #      return_value =
    report = FlowReport.new(return_value)
  end
  report
end

#to_sObject



48
49
50
51
52
53
# File 'lib/taft_files/framework/zznamezz/watir/flows/flow_objects.rb', line 48

def to_s
  s = ""
  s += "Flow name : #{@name}. Flow map size : #{@flow_map.size}. Flow items :"
  @flow_map.each {|f| s += "\n\t#{f.to_s}" }
  s
end