class Hiptest::XMLParser

Attributes

project[R]

Public Class Methods

new(source, reporter = nil) click to toggle source
# 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

Public Instance Methods

build_actionword(actionword) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_actionwordSnapshot(actionword) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 271
def build_actionwordSnapshots(actionword_snapshots)
  build_actionwords(actionword_snapshots, '> actionwordSnapshot')
end
build_actionwords(actionwords, actionwords_query = '> actionword') click to toggle source
# 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_argument(argument) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 125
def build_arguments(arguments)
  build_node_list(arguments.css('> arguments > argument'))
end
build_assign(assign) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 172
def build_default_value(node)
  build_node(css_first(node))
end
build_dict(dict) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
Also aliased as: build_folderSnapshot
build_folderSnapshot(folder)
Alias for: build_folder
build_folderSnapshots(folder_snapshots) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 342
def build_folderSnapshots(folder_snapshots)
  build_testPlan(folder_snapshots, '> folderSnapshot')
end
build_if(if_then) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 18
def build_nullliteral(value = nil)
  Hiptest::Nodes::NullLiteral.new
end
build_numericliteral(value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 184
def build_parameters(item)
  build_node_list(item.css('> parameters > parameter'))
end
build_parenthesis(parenthesis) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 90
def build_parenthesis(parenthesis)
  Hiptest::Nodes::Parenthesis.new(
    build_node(css_first(parenthesis)))
end
build_project() click to toggle source
# 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) click to toggle source
# 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_scenarioSnapshot(scs) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 279
def build_scenarioSnapshots(scenario_snapshots)
  build_scenarios(scenario_snapshots, '> scenarioSnapshot')
end
build_scenarios(scenarios, scenarios_query = '> scenario') click to toggle source
# 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_step(step) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 188
def build_steps(item)
  build_node_list(item.css('> steps > *'))
end
build_stringliteral(value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 180
def build_tags(item)
  build_node_list(item.css('> tags tag'))
end
build_template(template) click to toggle source
# 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) click to toggle source
# 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') click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 176
def build_value(node)
  build_node(css_first(node))
end
build_var(variable) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 46
def build_var(variable)
  Hiptest::Nodes::Variable.new(variable.content)
end
build_while(while_loop) click to toggle source
# 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

Private Instance Methods

build_node(node, default_node=nil) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 378
def build_node(node, default_node=nil)
  if node.nil? && default_node
    return default_node.new
  end
  self.send("build_#{node.name}", node)
rescue => error
  @reporter.dump_error(error, I18n.t('build_data.error', node: node.to_s))
  nil
end
build_node_list(l, container_class=nil) click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 388
def build_node_list(l, container_class=nil)
  items = l.map {|item| build_node(item)}

  unless container_class.nil?
    container_class.new(items)
  else
    items
  end
end
css_first(node, selector = '> *') click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 398
def css_first(node, selector = '> *')
  node.css(selector).first
end
css_first_content(node, selector = '> *') click to toggle source
# File lib/hiptest-publisher/xml_parser.rb, line 402
def css_first_content(node, selector = '> *')
  sub_node = css_first(node, selector)
  sub_node.nil? ? nil : sub_node.content
end