Class: Fastlane::Actions::CollateJunitReportsAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::CollateJunitReportsAction
- Defined in:
- lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
Class Method Summary collapse
-
.clean_report(report) ⇒ Object
Cleans formatting of report.
-
.get_test_name(test_data) ⇒ Object
Returns the test name of the retried test.
-
.merge_assets(asset_files, assets_folder) ⇒ Object
Merges screenshots from all retries.
-
.merge_logs(log_files, logs_folder) ⇒ Object
Merges console log of reports.
-
.mergeLists(target_report, retry_report, params) ⇒ Object
Merges .plist reports.
- .run(params) ⇒ Object
-
.write_report_to_file(report, file_name) ⇒ Object
Outputs report to a new file.
Class Method Details
.authors ⇒ Object
154 155 156 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 154 def self. ["Gloria Chow/@gmgchow"] end |
.available_options ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 102 def self. [ FastlaneCore::ConfigItem.new( key: :reports, env_name: 'COLLATE_PLIST_REPORTS_REPORTS', description: 'An array of plist reports to collate. The first report is used as the base into which other reports are merged in', optional: false, type: Array, verify_block: proc do |reports| UI.user_error!('No plist report files found') if reports.empty? reports.each do |report| UI.user_error!("Error: plist report not found: '#{report}'") unless File.exist?(report) end end ), FastlaneCore::ConfigItem.new( key: :collated_report, env_name: 'COLLATE_PLIST_REPORTS_COLLATED_REPORT', description: 'The final plist report file where all testcases will be merged into', optional: true, default_value: 'result.xml', type: String ), FastlaneCore::ConfigItem.new( key: :assets, env_name: 'COLLATE_PLIST_REPORTS_ASSETS', description: 'An array of plist reports to collate. The first report is used as the base into which other reports are merged in', optional: false, type: Array, verify_block: proc do |assets| UI.user_error!('No plist report files found') if assets.empty? assets.each do |asset| UI.user_error!("Error: plist report not found: '#{asset}'") unless File.exist?(asset) end end ), FastlaneCore::ConfigItem.new( key: :logs, env_name: 'COLLATE_PLIST_REPORTS_LOGS', description: 'An array of plist reports to collate. The first report is used as the base into which other reports are merged in', optional: false, type: Array, verify_block: proc do |logs| UI.user_error!('No plist report files found') if logs.empty? logs.each do |log| UI.user_error!("Error: plist report not found: '#{log}'") unless File.exist?(log) end end ) ] end |
.clean_report(report) ⇒ Object
Cleans formatting of report
54 55 56 57 58 59 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 54 def self.clean_report(report) report = report.gsub("<XCAccessibilityElement:/>0x", " XCAccessibilityElement ") report = report.gsub("<XCAccessibilityElement:></XCAccessibilityElement:>", " XCAccessibilityElement ") report = Nokogiri::XML(report) report end |
.description ⇒ Object
94 95 96 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 94 def self.description "Combines test results from multiple plist files." end |
.details ⇒ Object
98 99 100 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 98 def self.details "Based on the fastlane-plugins-test_center plugin by lyndsey-ferguson/@lyndseydf" end |
.get_test_name(test_data) ⇒ Object
Returns the test name of the retried test
84 85 86 87 88 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 84 def self.get_test_name(test_data) test_name = test_data.xpath("(//key[contains(.,'TestSummaryGUID')])/../key[contains(.,'TestName')]/following-sibling::string").to_a[0].to_s test_name = test_name[8..-10] test_name end |
.is_supported?(platform) ⇒ Boolean
158 159 160 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 158 def self.is_supported?(platform) platform == :ios end |
.merge_assets(asset_files, assets_folder) ⇒ Object
Merges screenshots from all retries
45 46 47 48 49 50 51 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 45 def self.merge_assets(asset_files, assets_folder) UI.verbose ("Merging screenshot folders...") Dir.mkdir(assets_folder) unless File.exists?(assets_folder) asset_files.each do |folder| FileUtils.cp_r(Dir[folder + '/*'], assets_folder) end end |
.merge_logs(log_files, logs_folder) ⇒ Object
Merges console log of reports
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 62 def self.merge_logs(log_files, logs_folder) UI.verbose("Merging console logs...") target_log = log_files.shift log_files.each do |log| to_append = File.read(log) File.open(target_log, "a") do |handle| handle.puts to_append end FileUtils.cp_r(target_log, logs_folder) end end |
.mergeLists(target_report, retry_report, params) ⇒ Object
Merges .plist reports
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 27 def self.mergeLists(target_report, retry_report, params) UI.verbose("Merging retried results...") Dir.mkdir(params[:collated_report]) unless File.exists?(params[:collated_report]) file_name = params[:collated_report] + "/action_TestSummaries.plist" retried_tests = retry_report.xpath("//key[contains(.,'TestSummaryGUID')]/..") current_node = retried_tests.shift while (current_node != nil) testName = get_test_name(current_node) matching_node = target_report.at_xpath("//string[contains(.,'#{testName}')]/..") if (!matching_node.nil?) matching_node.previous.next.replace(current_node) write_report_to_file(target_report, file_name) end current_node = retried_tests.shift end end |
.run(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 10 def self.run(params) report_filepaths = params[:reports].reverse if report_filepaths.size == 1 FileUtils.cp(report_filepaths[0], params[:collated_report]) else target_report = File.open(report_filepaths.shift) {|f| Nokogiri::XML(f)} reports = report_filepaths.map { |report_filepath| Nokogiri::XML(Nokogiri::PList(open(report_filepath)).to_plist) } reports.each do |retry_report| retry_report = clean_report(retry_report.to_s) mergeLists(target_report, retry_report, params) end end merge_assets(params[:assets], params[:collated_report] + "/Attachments") merge_logs(params[:logs], params[:collated_report] + "/") end |
.write_report_to_file(report, file_name) ⇒ Object
Outputs report to a new file
75 76 77 78 79 80 81 |
# File 'lib/fastlane/plugin/retry_failed_tests/actions/collate_junit_reports.rb', line 75 def self.write_report_to_file(report, file_name) UI.verbose("Writing merged results to file...") File.new(file_name, 'w') File.open(file_name, 'w') do |f| f.write(report.to_xml) end end |