Class: Hiptest::XMLParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/xml_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = nil) ⇒ XMLParser

Returns a new instance of XMLParser.



11
12
13
14
15
# File 'lib/hiptest-publisher/xml_parser.rb', line 11

def initialize(source, options = nil)
  @source = source
  @xml = Nokogiri::XML(source)
  @options = options
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



9
10
11
# File 'lib/hiptest-publisher/xml_parser.rb', line 9

def project
  @project
end

Instance Method Details

#build_actionword(actionword) ⇒ Object



181
182
183
184
185
186
187
# File 'lib/hiptest-publisher/xml_parser.rb', line 181

def build_actionword(actionword)
  Hiptest::Nodes::Actionword.new(
    css_first_content(actionword, 'name'),
    build_tags(actionword),
    build_parameters(actionword),
    build_steps(actionword))
end

#build_actionwords(actionwords) ⇒ Object



210
211
212
# File 'lib/hiptest-publisher/xml_parser.rb', line 210

def build_actionwords(actionwords)
  build_node_list(actionwords.css('> actionword'), Hiptest::Nodes::Actionwords)
end

#build_argument(argument) ⇒ Object



120
121
122
123
124
125
# File 'lib/hiptest-publisher/xml_parser.rb', line 120

def build_argument(argument)
  value = css_first(argument, '> value')
  Hiptest::Nodes::Argument.new(
    css_first_content(argument, 'name'),
    value ? build_node(value) : nil)
end

#build_arguments(arguments) ⇒ Object



116
117
118
# File 'lib/hiptest-publisher/xml_parser.rb', line 116

def build_arguments(arguments)
  build_node_list(arguments.css('> arguments > argument'))
end

#build_assign(assign) ⇒ Object



104
105
106
107
108
# File 'lib/hiptest-publisher/xml_parser.rb', line 104

def build_assign(assign)
  Hiptest::Nodes::Assign.new(
    build_node(css_first(assign, 'to > *')),
    build_node(css_first(assign, 'value > *')))
end

#build_binary_expression(operation) ⇒ Object



61
62
63
64
65
66
# File 'lib/hiptest-publisher/xml_parser.rb', line 61

def build_binary_expression(operation)
  Hiptest::Nodes::BinaryExpression.new(
    build_node(css_first(operation, '> left > *')),
    css_first_content(operation, '> operator'),
    build_node(css_first(operation, '> right > *')))
end

#build_booleanliteral(value) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/hiptest-publisher/xml_parser.rb', line 37

def build_booleanliteral(value)
  if value.is_a?(TrueClass) || value.is_a?(FalseClass)
    Hiptest::Nodes::BooleanLiteral.new(value)
  else
    Hiptest::Nodes::BooleanLiteral.new(value.content)
  end
end

#build_call(call) ⇒ Object



110
111
112
113
114
# File 'lib/hiptest-publisher/xml_parser.rb', line 110

def build_call(call)
  Hiptest::Nodes::Call.new(
    css_first_content(call, '> actionword'),
    build_arguments(call))
end

#build_dataset(dataset) ⇒ Object



204
205
206
207
208
# File 'lib/hiptest-publisher/xml_parser.rb', line 204

def build_dataset(dataset)
  Hiptest::Nodes::Dataset.new(
    css_first_content(dataset, '> name'),
    build_node_list(dataset.css('> arguments argument')))
end

#build_datatable(datatable) ⇒ Object



200
201
202
# File 'lib/hiptest-publisher/xml_parser.rb', line 200

def build_datatable(datatable)
  Hiptest::Nodes::Datatable.new(build_node_list(datatable.css('> dataset')))
end

#build_default_value(node) ⇒ Object



161
162
163
# File 'lib/hiptest-publisher/xml_parser.rb', line 161

def build_default_value(node)
  build_node(css_first(node))
end

#build_dict(dict) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/hiptest-publisher/xml_parser.rb', line 91

def build_dict(dict)
  items = dict.element_children.map do |item|
    Hiptest::Nodes::Property.new(
      item.name,
      build_node(css_first(item)))
  end
  Hiptest::Nodes::Dict.new(items)
end

#build_field(field) ⇒ Object



49
50
51
52
53
# File 'lib/hiptest-publisher/xml_parser.rb', line 49

def build_field(field)
  Hiptest::Nodes::Field.new(
    build_node(css_first(field, '> base > *')),
    css_first_content(field, '> name'))
end

#build_folder(folder) ⇒ Object



231
232
233
234
235
236
# File 'lib/hiptest-publisher/xml_parser.rb', line 231

def build_folder(folder)
  Hiptest::Nodes::Folder.new(
    css_first_content(folder, 'uid'),
    css_first_content(folder, 'parentUid'),
    css_first_content(folder, 'name'))
end

#build_if(if_then) ⇒ Object



127
128
129
130
131
132
# File 'lib/hiptest-publisher/xml_parser.rb', line 127

def build_if(if_then)
  Hiptest::Nodes::IfThen.new(
    build_node(css_first(if_then, '> condition > *')),
    build_node_list(if_then.css('> then > *')),
    build_node_list(if_then.css('> else > *')))
end

#build_index(index) ⇒ Object



55
56
57
58
59
# File 'lib/hiptest-publisher/xml_parser.rb', line 55

def build_index(index)
  Hiptest::Nodes::Index.new(
    build_node(css_first(index, '> base > *')),
    build_node(css_first(index, '> expression > *')))
end

#build_list(list) ⇒ Object



87
88
89
# File 'lib/hiptest-publisher/xml_parser.rb', line 87

def build_list(list)
  Hiptest::Nodes::List.new(build_node_list(list.css('> item > *')))
end

#build_nullliteral(value = nil) ⇒ Object



17
18
19
# File 'lib/hiptest-publisher/xml_parser.rb', line 17

def build_nullliteral(value = nil)
  Hiptest::Nodes::NullLiteral.new
end

#build_numericliteral(value) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/hiptest-publisher/xml_parser.rb', line 29

def build_numericliteral(value)
  if value.is_a? Numeric
    Hiptest::Nodes::NumericLiteral.new(value)
  else
    Hiptest::Nodes::NumericLiteral.new(value.content)
  end
end

#build_operation(operation) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/hiptest-publisher/xml_parser.rb', line 74

def build_operation(operation)
  if css_first(operation, '> left').nil?
    build_unary_expression(operation)
  else
    build_binary_expression(operation)
  end
end

#build_parameter(parameter) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/hiptest-publisher/xml_parser.rb', line 153

def build_parameter(parameter)
  default_value = css_first(parameter, '> default_value')

  Hiptest::Nodes::Parameter.new(
    css_first_content(parameter, 'name'),
    default_value ? build_node(default_value) : nil)
end

#build_parameters(item) ⇒ Object



173
174
175
# File 'lib/hiptest-publisher/xml_parser.rb', line 173

def build_parameters(item)
  build_node_list(item.css('> parameters > parameter'))
end

#build_parenthesis(parenthesis) ⇒ Object



82
83
84
85
# File 'lib/hiptest-publisher/xml_parser.rb', line 82

def build_parenthesis(parenthesis)
  Hiptest::Nodes::Parenthesis.new(
    build_node(css_first(parenthesis)))
end

#build_projectObject



246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/hiptest-publisher/xml_parser.rb', line 246

def build_project
  project = css_first(@xml, 'project')

  @project = Hiptest::Nodes::Project.new(
    css_first_content(project, '> name'),
    css_first_content(project, '> description'),
    build_node(css_first(project, '> testPlan'), Hiptest::Nodes::TestPlan),
    build_node(css_first(project, '> scenarios'), Hiptest::Nodes::Scenarios),
    build_node(css_first(project, '> actionwords'), Hiptest::Nodes::Actionwords),
    build_node(css_first(project, '> tests'), Hiptest::Nodes::Tests))

  @project.assign_scenarios_to_folders
  return @project
end

#build_scenario(scenario) ⇒ Object



189
190
191
192
193
194
195
196
197
198
# File 'lib/hiptest-publisher/xml_parser.rb', line 189

def build_scenario(scenario)
  Hiptest::Nodes::Scenario.new(
    css_first_content(scenario, 'name'),
    css_first_content(scenario, 'description'),
    build_tags(scenario),
    build_parameters(scenario),
    build_steps(scenario),
    css_first_content(scenario, 'folderUid'),
    build_node(css_first(scenario, 'datatable'), Hiptest::Nodes::Datatable))
end

#build_scenarios(scenarios) ⇒ Object



214
215
216
# File 'lib/hiptest-publisher/xml_parser.rb', line 214

def build_scenarios(scenarios)
  build_node_list(scenarios.css('> scenario'), Hiptest::Nodes::Scenarios)
end

#build_step(step) ⇒ Object



134
135
136
137
138
139
# File 'lib/hiptest-publisher/xml_parser.rb', line 134

def build_step(step)
  first_prop = css_first(step)
  Hiptest::Nodes::Step.new(
    first_prop.name,
    build_node(css_first(first_prop)))
end

#build_steps(item) ⇒ Object



177
178
179
# File 'lib/hiptest-publisher/xml_parser.rb', line 177

def build_steps(item)
  build_node_list(item.css('> steps > *'))
end

#build_stringliteral(value) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/hiptest-publisher/xml_parser.rb', line 21

def build_stringliteral(value)
  if value.is_a? String
    Hiptest::Nodes::StringLiteral.new(value)
  else
    Hiptest::Nodes::StringLiteral.new(value.content)
  end
end

#build_tag(tag) ⇒ Object



147
148
149
150
151
# File 'lib/hiptest-publisher/xml_parser.rb', line 147

def build_tag(tag)
  Hiptest::Nodes::Tag.new(
    css_first_content(tag, '> key'),
    css_first_content(tag, '> value'))
end

#build_tags(item) ⇒ Object



169
170
171
# File 'lib/hiptest-publisher/xml_parser.rb', line 169

def build_tags(item)
  build_node_list(item.css('> tags tag'))
end

#build_template(template) ⇒ Object



100
101
102
# File 'lib/hiptest-publisher/xml_parser.rb', line 100

def build_template(template)
  Hiptest::Nodes::Template.new(build_node_list(template.css('> *')))
end

#build_test(test) ⇒ Object



222
223
224
225
226
227
228
229
# File 'lib/hiptest-publisher/xml_parser.rb', line 222

def build_test(test)
  Hiptest::Nodes::Test.new(
    css_first_content(test, 'name'),
    css_first_content(test, 'description'),
    build_tags(test),
    build_steps(test)
  )
end

#build_testPlan(test_plan) ⇒ Object



238
239
240
241
242
243
244
# File 'lib/hiptest-publisher/xml_parser.rb', line 238

def build_testPlan(test_plan)
  tp = Hiptest::Nodes::TestPlan.new(
    build_node_list(test_plan.css('> folder')))

  tp.organize_folders
  return tp
end

#build_tests(tests) ⇒ Object



218
219
220
# File 'lib/hiptest-publisher/xml_parser.rb', line 218

def build_tests(tests)
  build_node_list(tests.css('> test'), Hiptest::Nodes::Tests)
end

#build_unary_expression(operation) ⇒ Object



68
69
70
71
72
# File 'lib/hiptest-publisher/xml_parser.rb', line 68

def build_unary_expression(operation)
  Hiptest::Nodes::UnaryExpression.new(
    css_first_content(operation, '> operator'),
    build_node(css_first(operation, '> expression > *')))
end

#build_value(node) ⇒ Object



165
166
167
# File 'lib/hiptest-publisher/xml_parser.rb', line 165

def build_value(node)
  build_node(css_first(node))
end

#build_var(variable) ⇒ Object



45
46
47
# File 'lib/hiptest-publisher/xml_parser.rb', line 45

def build_var(variable)
  Hiptest::Nodes::Variable.new(variable.content)
end

#build_while(while_loop) ⇒ Object



141
142
143
144
145
# File 'lib/hiptest-publisher/xml_parser.rb', line 141

def build_while(while_loop)
  Hiptest::Nodes::While.new(
    build_node(css_first(while_loop, '> condition > *')),
    build_node_list(while_loop.css('> body > *')))
end