Skip to content

Commit 93a8ae9

Browse files
committed
started general report
1 parent 49fdbac commit 93a8ae9

File tree

5 files changed

+779
-3
lines changed

5 files changed

+779
-3
lines changed

lib/kraken-mobile/helpers/reporter.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'kraken-mobile/constants'
22
require 'digest'
3+
require 'json'
34

45
module KrakenMobile
56
class Reporter
@@ -19,6 +20,22 @@ def initialize(execution_id, options)
1920
#-------------------------------
2021
# Generator
2122
#-------------------------------
23+
def generate_general_report
24+
erb_file = File.join(File.expand_path("../../../../reporter/", __FILE__), "index.html.erb")
25+
html_file = File.join(File.expand_path("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/"), "index.html")
26+
# Variables
27+
@devices = [{"user":1,"id":"93c6af52","model":"ONEPLUS_A6013"},{"user":2,"id":"emulator-5554","model":"Android_SDK_built_for_x86"}]
28+
devices_report = report_by_devices(@devices)
29+
@features_report = fetures_from_report_by_devices devices_report
30+
@branches = branches(@features_report).to_json # TODO
31+
template = File.read(erb_file)
32+
result = ERB.new(template).result(binding)
33+
# write result to file
34+
File.open(html_file, 'w+') do |f|
35+
f.write result
36+
end
37+
end
38+
2239
def generate_device_report device
2340
@apk_path = device.config["apk_path"] ? device.config["apk_path"] : @options[:apk_path]
2441
report_file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json")
@@ -42,6 +59,34 @@ def generate_device_report device
4259
generate_features_report @features, device
4360
end
4461

62+
def report_by_devices devices
63+
devices_report = {}
64+
devices.each do |device|
65+
next if !File.exists?("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device[:id]}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json")
66+
report_file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device[:id]}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json")
67+
content = report_file.read
68+
devices_report[device[:user]] = JSON.parse(content)
69+
devices_report[device[:user]].each do |d| d["device_id"] = device[:id] if !d["device_id"] end
70+
end
71+
devices_report
72+
end
73+
74+
def fetures_from_report_by_devices report_by_devices
75+
features = {}
76+
report_by_devices.keys.each do |user_key|
77+
report = report_by_devices[user_key]
78+
report.each do |feature|
79+
features[feature["id"]] = {} if !features[feature["id"]]
80+
features[feature["id"]]["name"] = feature["name"] if !features[feature["id"]]["name"] && feature["name"]
81+
features[feature["id"]]["uri"] = feature["uri"] if !features[feature["id"]]["uri"] && feature["uri"]
82+
features[feature["id"]]["hash"] = feature_id(feature) if !features[feature["id"]]["hash"]
83+
features[feature["id"]]["devices"] = {} if !features[feature["id"]]["devices"]
84+
features[feature["id"]]["devices"][user_key] = feature["elements"] if feature["elements"]
85+
end
86+
end
87+
features
88+
end
89+
4590
def generate_features_report features, device
4691
features.each do |feature|
4792
generate_feature_report feature, device
@@ -63,6 +108,27 @@ def generate_feature_report feature, device
63108
end
64109
end
65110

111+
# 0: create 1: commit 2: merge
112+
def branches features_report
113+
branches = {}
114+
features_report.keys.each do |key|
115+
report = features_report[key]
116+
branches[report["hash"]] = {} if !branches[report["hash"]]
117+
branches[report["hash"]]["steps"]= [] if !branches[report["hash"]]["steps"]
118+
devices = report["devices"]
119+
devices.keys.each do |device_key|
120+
branches[report["hash"]]["steps"] << { type: 0, name: device_key }
121+
feature_steps = devices[device_key][0]["steps"] if devices[device_key].count > 0 && devices[device_key][0]["steps"]
122+
feature_steps.each do |step|
123+
hash_step = { type: 1, name: device_key}
124+
hash_step[:image] = step["after"][0]["embeddings"][0] if step["after"].count > 0 && step["after"][0]["embeddings"] && step["after"][0]["embeddings"].count > 0
125+
branches[report["hash"]]["steps"] << hash_step
126+
end
127+
end
128+
end
129+
branches
130+
end
131+
66132
#-------------------------------
67133
# Helpers
68134
#-------------------------------

lib/kraken-mobile/runners/calabash/android/android_runner.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def before_all
3030
Dir.mkdir(KrakenMobile::Constants::REPORT_PATH) unless File.exists?(KrakenMobile::Constants::REPORT_PATH)
3131
Dir.mkdir("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}")
3232
devices_id_list = []
33-
@devices_manager.connected_devices.each do |device|
34-
devices_id_list << { id: device.id }
33+
@devices_manager.connected_devices.each_with_index do |device, index|
34+
devices_id_list << { user: (index+1), id: device.id, model: device.model }
3535
Dir.mkdir("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}")
3636
end
3737
file = open("#{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{KrakenMobile::Constants::REPORT_DEVICES_FILE_NAME}.json", 'w')
@@ -79,6 +79,7 @@ def run_in_parallel
7979
run_tests(group, index, @options)
8080
@reporter.generate_device_report devices_connected[index]
8181
end
82+
@reporter.generate_general_report
8283
end
8384

8485
def run_tests(test_files, process_number, options)

lib/kraken-mobile/runners/calabash/android/kraken_hooks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
end
1212

1313
AfterStep do |scenario|
14-
#screenshot_embed
14+
screenshot_embed
1515
end

reporter/assets/js/gitgraph.min.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)