Class: ResultsParser
- Inherits:
-
Object
- Object
- ResultsParser
- Defined in:
- lib/trail_marker/results_parser.rb
Overview
HISTORY: 1/7/2016 modified to handle just 1 file
3/21/2016 Allows indexing of test case
e.g. (TestRail: [C11, C22], [C33, C44], 1) Last argument is an index (starts at 0)
to mark test case C33 and C44. Modified method parse_trail_tag to implement this.
TODO: Parse Failure element CDATA to add to comment - will require changes in request.rb, etc.
Constant Summary collapse
- DEBUG_MODE =
false
Instance Method Summary collapse
- #checkIfDirectoryExists(xml_loc) ⇒ Object
-
#getAllXMLFiles ⇒ Object
Retrieves all .xml files in the directory passed as parameter also recurssively gets subdirectory files because it uses Dir.glob Return: array of file names with path where it is located.
-
#initialize(results_path) ⇒ ResultsParser
constructor
A new instance of ResultsParser.
-
#parse_trail_tag(name_line) ⇒ Object
Parses the ‘name’ attribute of <testcase> and returns all test cases found.
-
#read_XML_file(xfile) ⇒ Object
Reads XML file and uses nokogiri to parse.
- #readAllXMLFiles(xml_files) ⇒ Object
-
#rspec_parser(nokigiri_doc) ⇒ Object
Parses the results of an RSPEC XML file.
-
#squish_parser(nokigiri_doc) ⇒ Object
Parses the SquishReport XML results file.
Constructor Details
#initialize(results_path) ⇒ ResultsParser
Returns a new instance of ResultsParser.
15 16 17 18 19 20 |
# File 'lib/trail_marker/results_parser.rb', line 15 def initialize(results_path) checkIfDirectoryExists(results_path) @results_path = results_path #xmls = getAllXMLFiles(results_path) #readAllXMLFiles(xmls) end |
Instance Method Details
#checkIfDirectoryExists(xml_loc) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/trail_marker/results_parser.rb', line 22 def checkIfDirectoryExists(xml_loc) if ! File.directory?(xml_loc) && ! File.file?(xml_loc) puts "ERROR: Cannot find the XML results directory or file:" puts " #{xml_loc}" puts " Please check the path of the directory where the results are located.\n\n" exit(0) end end |
#getAllXMLFiles ⇒ Object
Retrieves all .xml files in the directory passed as parameter also recurssively gets subdirectory files because it uses Dir.glob Return: array of file names with path where it is located.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/trail_marker/results_parser.rb', line 34 def getAllXMLFiles() originalDir = Dir.pwd Dir.chdir @results_path filesArray = Array.new debug_msg "#{@results_path}/**/*.xml" Dir.glob("**/*.xml") do |f| debug_msg "XML: #{f}" filesArray << "#{@results_path}/" + f end Dir.chdir originalDir return filesArray end |
#parse_trail_tag(name_line) ⇒ Object
Parses the ‘name’ attribute of <testcase> and returns all test cases found. Returns an array in case a single test can mark off multiple test cases. Ex. <testcase name=“Login: should allow all valued users to successfully login (TestRail: C123, C888) Returns [‘C123’, ‘C888’]
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/trail_marker/results_parser.rb', line 129 def parse_trail_tag(name_line) case_arr = [] ndex = get_index(name_line) if ndex < 0 pattern = /\(TestRail:([Cc0-9\,\s]+)\)/ just_cases = pattern.match(name_line) if ! just_cases.nil? debug_msg "HowMany #{just_cases[1]}" split_cases = just_cases[1].split(',') split_cases.each do |onecase| case_arr.push(onecase.strip) end end debug_msg "ARR: #{case_arr}" else case_arr = get_indexed_cases(name_line, ndex) end return case_arr end |
#read_XML_file(xfile) ⇒ Object
Reads XML file and uses nokogiri to parse
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/trail_marker/results_parser.rb', line 55 def read_XML_file(xfile) result_array = [] if File.file?(xfile) puts "\n\nOPENING #{xfile}" f = File.open(xfile) doc = Nokogiri::XML(f) if is_squish?(doc) result_array = squish_parser(doc) else result_array = rspec_parser(doc) end else puts "\nNot a file: #{xfile} - verify options (-x for directory, -f for a specific file)" end return result_array end |
#readAllXMLFiles(xml_files) ⇒ Object
47 48 49 50 51 |
# File 'lib/trail_marker/results_parser.rb', line 47 def readAllXMLFiles(xml_files) xml_files.each do |xml_file| read_XML_file(xml_file) end end |
#rspec_parser(nokigiri_doc) ⇒ Object
Parses the results of an RSPEC XML file. TODO:
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 |
# File 'lib/trail_marker/results_parser.rb', line 93 def rspec_parser(nokigiri_doc) result_arr = [] testsuites = nokigiri_doc.xpath("//testsuites") testsuites.each do |suites| testsuite = suites.xpath("./testsuite") testsuite.each do |suite| debug_msg "\nSUITE: #{suite["name"]} " testsuite_name = suite["name"] testcases = suite.xpath("./testcase") testcases.each do |tcase| debug_msg "TESTCASE: #{tcase}" is_passed = false failure = tcase.xpath("./failure") if ! failure.nil? is_passed = true if failure.size > 0 is_passed = false end end debug_msg " TC: #{tcase["name"]}" testcase_name = tcase["name"] trail_cases = parse_trail_tag(testcase_name) trail_cases.each do |trail_case| result_arr.push({:trail_case => trail_case, :passed => is_passed}) end end end debug_msg "FINAL: #{result_arr}" return result_arr end end |
#squish_parser(nokigiri_doc) ⇒ Object
Parses the SquishReport XML results file
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/trail_marker/results_parser.rb', line 73 def squish_parser(nokigiri_doc) result_arr = [] verifications = nokigiri_doc.xpath("//verification") verifications.each do |verification| #puts "ONEVER: #{verification}" trail_cases = parse_trail_tag(verification["name"]) result = verification.xpath("result").first is_passed = squish_check_passed(result) debug_msg "\nVERIFICATION: #{verification["name"]} :: #{trail_cases}" trail_cases = parse_trail_tag(verification["name"]) trail_cases.each do |trail_case| result_arr.push({:trail_case => trail_case, :passed => is_passed}) end end debug_msg "Squish FINAL: #{result_arr}" return result_arr end |