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, reporter = nil) ⇒ XMLParser

Returns a new instance of XMLParser.



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

def initialize(source, reporter = nil)
  @source = source
  @xml = Nokogiri::XML(source)
  @reporter = reporter || NullReporter.new
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



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

def project
  @project
end

Instance Method Details

#build_actionword(actionword) ⇒ Object



185
186
187
188
189
190
191
192
# File 'lib/hiptest-publisher/xml_parser.rb', line 185

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

#build_actionwords(actionwords, actionwords_query = '> actionword') ⇒ Object



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

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

#build_actionwordSnapshot(actionword) ⇒ Object



194
195
196
197
198
199
200
201
# File 'lib/hiptest-publisher/xml_parser.rb', line 194

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

#build_actionwordSnapshots(actionword_snapshots) ⇒ Object



245
246
247
# File 'lib/hiptest-publisher/xml_parser.rb', line 245

def build_actionwordSnapshots(actionword_snapshots)
  build_actionwords(actionword_snapshots, '> actionwordSnapshot')
end

#build_argument(argument) ⇒ Object



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

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



118
119
120
# File 'lib/hiptest-publisher/xml_parser.rb', line 118

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

#build_assign(assign) ⇒ Object



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

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



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

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



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

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



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

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

#build_dataset(dataset) ⇒ Object



235
236
237
238
239
# File 'lib/hiptest-publisher/xml_parser.rb', line 235

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



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

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

#build_default_value(node) ⇒ Object



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

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

#build_dict(dict) ⇒ Object



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

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



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

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

#build_folder(folder) ⇒ Object Also known as: build_folderSnapshot



270
271
272
273
274
275
276
277
# File 'lib/hiptest-publisher/xml_parser.rb', line 270

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

#build_folderSnapshots(folder_snapshots) ⇒ Object



288
289
290
# File 'lib/hiptest-publisher/xml_parser.rb', line 288

def build_folderSnapshots(folder_snapshots)
  build_testPlan(folder_snapshots, '> folderSnapshot')
end

#build_if(if_then) ⇒ Object



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

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



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

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



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

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

#build_nullliteral(value = nil) ⇒ Object



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

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

#build_numericliteral(value) ⇒ Object



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

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



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

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



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

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



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

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

#build_parenthesis(parenthesis) ⇒ Object



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

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

#build_projectObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/hiptest-publisher/xml_parser.rb', line 292

def build_project
  project = css_first(@xml, 'project')
  test_run = css_first(project, '> testRuns > testRun')

  if test_run.nil?
    test_plan_node = css_first(project, '> testPlan')
    scenarios_node = css_first(project, '> scenarios')
    actionwords_node = css_first(project, '> actionwords')
  else
    test_plan_node = css_first(test_run, '> folderSnapshots')
    scenarios_node = css_first(test_run, '> scenarioSnapshots')
    actionwords_node = css_first(test_run, '> actionwordSnapshots')
  end

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

  @project.assign_scenarios_to_folders
  return @project
end

#build_scenario(scenario) ⇒ Object



203
204
205
206
207
208
209
210
211
212
# File 'lib/hiptest-publisher/xml_parser.rb', line 203

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, scenarios_query = '> scenario') ⇒ Object



249
250
251
# File 'lib/hiptest-publisher/xml_parser.rb', line 249

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

#build_scenarioSnapshot(scs) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/hiptest-publisher/xml_parser.rb', line 214

def build_scenarioSnapshot(scs)
  scenario = build_scenario(scs)
  datasets = scenario.each_sub_nodes(Hiptest::Nodes::Dataset).to_a

  if datasets.empty?
    scenario.set_uid(css_first_content(scs, 'testSnapshot > uid'))
  else
    scs.css('testSnapshot').each do |testSnapshot|
      uid = css_first_content(testSnapshot, '> uid')
      index = css_first_content(testSnapshot, '> index').to_i

      datasets[index].set_uid(uid) unless index >= datasets.length
    end
  end
  scenario
end

#build_scenarioSnapshots(scenario_snapshots) ⇒ Object



253
254
255
# File 'lib/hiptest-publisher/xml_parser.rb', line 253

def build_scenarioSnapshots(scenario_snapshots)
  build_scenarios(scenario_snapshots, '> scenarioSnapshot')
end

#build_step(step) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/hiptest-publisher/xml_parser.rb', line 136

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

#build_steps(item) ⇒ Object



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

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

#build_stringliteral(value) ⇒ Object



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

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



151
152
153
154
155
# File 'lib/hiptest-publisher/xml_parser.rb', line 151

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

#build_tags(item) ⇒ Object



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

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

#build_template(template) ⇒ Object



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

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

#build_test(test) ⇒ Object



261
262
263
264
265
266
267
268
# File 'lib/hiptest-publisher/xml_parser.rb', line 261

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, folders_query = '> folder') ⇒ Object



280
281
282
283
284
285
286
# File 'lib/hiptest-publisher/xml_parser.rb', line 280

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

  tp.organize_folders
  return tp
end

#build_tests(tests) ⇒ Object



257
258
259
# File 'lib/hiptest-publisher/xml_parser.rb', line 257

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

#build_unary_expression(operation) ⇒ Object



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

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



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

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

#build_var(variable) ⇒ Object



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

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

#build_while(while_loop) ⇒ Object



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

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