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



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

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'),
    css_first_content(actionword, '> description'))
end

#build_actionwordLibraries(libraries) ⇒ Object



316
317
318
319
320
# File 'lib/hiptest-publisher/xml_parser.rb', line 316

def build_actionwordLibraries(libraries)
  Hiptest::Nodes::Libraries.new(
    build_node_list(libraries.css('> actionwordLibrary'))
  )
end

#build_actionwordLibrary(library) ⇒ Object



328
329
330
331
332
333
# File 'lib/hiptest-publisher/xml_parser.rb', line 328

def build_actionwordLibrary(library)
  Hiptest::Nodes::Library.new(
    css_first_content(library, '> name'),
    build_node_list(library.css('> libraryActionwords libraryActionword'))
  )
end

#build_actionwordLibrarySnapshot(library) ⇒ Object



335
336
337
338
339
340
# File 'lib/hiptest-publisher/xml_parser.rb', line 335

def build_actionwordLibrarySnapshot(library)
  Hiptest::Nodes::Library.new(
    css_first_content(library, '> name'),
    build_node_list(library.css('> libraryActionwordSnapshots actionwordSnapshot'))
  )
end

#build_actionwordLibrarySnapshots(libraries) ⇒ Object



322
323
324
325
326
# File 'lib/hiptest-publisher/xml_parser.rb', line 322

def build_actionwordLibrarySnapshots(libraries)
  Hiptest::Nodes::Libraries.new(
    build_node_list(libraries.css('> actionwordLibrarySnapshot'))
  )
end

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



267
268
269
# File 'lib/hiptest-publisher/xml_parser.rb', line 267

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

#build_actionwordSnapshot(actionword) ⇒ Object



212
213
214
215
216
217
218
219
220
# File 'lib/hiptest-publisher/xml_parser.rb', line 212

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'),
    css_first_content(actionword, '> description'))
end

#build_actionwordSnapshots(actionword_snapshots) ⇒ Object



271
272
273
# File 'lib/hiptest-publisher/xml_parser.rb', line 271

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

#build_argument(argument) ⇒ Object



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

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



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

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

#build_assign(assign) ⇒ Object



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

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



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

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



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

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



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

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

#build_datatable(datatable) ⇒ Object



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

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

#build_default_value(node) ⇒ Object



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

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

#build_dict(dict) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/hiptest-publisher/xml_parser.rb', line 99

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



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

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



296
297
298
299
300
301
302
303
304
305
# File 'lib/hiptest-publisher/xml_parser.rb', line 296

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),
    css_first_content(folder, 'order_in_parent').to_i,
    build_steps(folder))
end

#build_folderSnapshots(folder_snapshots) ⇒ Object



342
343
344
# File 'lib/hiptest-publisher/xml_parser.rb', line 342

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

#build_if(if_then) ⇒ Object



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

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



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

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

#build_libraryActionword(libraryActionword) ⇒ Object



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

def build_libraryActionword(libraryActionword)
  Hiptest::Nodes::LibraryActionword.new(
    css_first_content(libraryActionword, '> name'),
    build_tags(libraryActionword),
    build_parameters(libraryActionword),
    build_steps(libraryActionword),
    css_first_content(libraryActionword, '> uid'),
    css_first_content(libraryActionword, '> description'))
end

#build_list(list) ⇒ Object



95
96
97
# File 'lib/hiptest-publisher/xml_parser.rb', line 95

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



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

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



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

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



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

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

#build_parenthesis(parenthesis) ⇒ Object



90
91
92
93
# File 'lib/hiptest-publisher/xml_parser.rb', line 90

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

#build_projectObject



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/hiptest-publisher/xml_parser.rb', line 346

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')
    libraries_node = css_first(project, '> actionwordLibraries')
  else
    test_plan_node = css_first(test_run, '> folderSnapshots')
    scenarios_node = css_first(test_run, '> scenarioSnapshots')
    actionwords_node = css_first(test_run, '> actionwordSnapshots')
    libraries_node = css_first(test_run, '> actionwordLibrarySnapshots')
  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),
    build_node(libraries_node, Hiptest::Nodes::Libraries)
  )

  @project.assign_scenarios_to_folders
  return @project
end

#build_scenario(scenario) ⇒ Object



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

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),
    css_first_content(scenario, 'order_in_parent').to_i)
end

#build_scenarios(scenarios, scenarios_query = '> scenario') ⇒ Object



275
276
277
# File 'lib/hiptest-publisher/xml_parser.rb', line 275

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

#build_scenarioSnapshot(scs) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/hiptest-publisher/xml_parser.rb', line 234

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

  scenario.add_tags(scs.css('testSnapshot').flat_map { |test| build_tags(test)}.compact)

  if datasets.empty?
    scenario.set_uid(css_first_content(scs, 'testSnapshot > uid'))
  else
    scenario.set_uid(css_first_content(scs, ' > uid'))

    scs.css('testSnapshot').each do |testSnapshot|
      test_snapshot_uid = css_first_content(testSnapshot, '> uid')
      dataset_uid = css_first_content(testSnapshot, '> datasetUid')

      dataset = datasets.find { |ds| ds.children[:uid] == dataset_uid }
      dataset.set_test_snapshot_uid(test_snapshot_uid) if dataset
    end
  end
  scenario
end

#build_scenarioSnapshots(scenario_snapshots) ⇒ Object



279
280
281
# File 'lib/hiptest-publisher/xml_parser.rb', line 279

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

#build_step(step) ⇒ Object



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

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



188
189
190
# File 'lib/hiptest-publisher/xml_parser.rb', line 188

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_symbol(symbol) ⇒ Object



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

def build_symbol(symbol)
  Hiptest::Nodes::Symbol.new(
    css_first_content(symbol, '> value'),
    css_first_content(symbol, '> delimiter')
  )
end

#build_tag(tag) ⇒ Object



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

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

#build_tags(item) ⇒ Object



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

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

#build_template(template) ⇒ Object



108
109
110
# File 'lib/hiptest-publisher/xml_parser.rb', line 108

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

#build_test(test) ⇒ Object



287
288
289
290
291
292
293
294
# File 'lib/hiptest-publisher/xml_parser.rb', line 287

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



308
309
310
311
312
313
314
# File 'lib/hiptest-publisher/xml_parser.rb', line 308

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



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

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

#build_unary_expression(operation) ⇒ Object



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

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



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

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



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

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