Skip to content

Commit 1e509bb

Browse files
committed
reporter graph finished
1 parent eead082 commit 1e509bb

File tree

3 files changed

+86
-20
lines changed

3 files changed

+86
-20
lines changed

lib/kraken-mobile/helpers/reporter.rb

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,70 @@ def feature_by_nodes_and_links features_report
120120
def nodes_and_links feature_report, feature_name
121121
last_node_id = 0
122122
nodes = [{ name: "", id: "empty", image: nil }]
123+
signal_hash = {}
123124
links = []
124125
feature_report.keys.each do |key|
125126
steps = feature_report[key]
127+
coming_from_signal = false
128+
last_signal = -1
126129
steps.each_with_index do |step, index|
127130
node_id = last_node_id+1
128-
node = { name: step[:name], id: "#{node_id}", image: step[:image], status: step[:status] }
129-
link = {
130-
source: (index == 0 ? 0 : last_node_id),
131-
target: node_id,
132-
value: 1,
133-
owner: key,
134-
owner_model: step[:device_model]
135-
}
136-
nodes << node
137-
links << link
138-
last_node_id += 1
131+
if isReadSignal(step[:name]) && step[:status] == PASSED
132+
signal = signalContent(step[:name])
133+
already_created_signal = signal_hash[signal] ? true : false
134+
signal_hash[signal] = already_created_signal ? signal_hash[signal] : { id: "#{node_id}", receiver: key }
135+
node = { name: "Signal: #{signal}, Receiver: #{step[:device_model]}", id: signal_hash[signal][:id], image: nil, status: step[:status] }
136+
if already_created_signal
137+
entry = nodes.select{ |node| node[:id] == signal_hash[signal][:id] }.first
138+
entry[:name] = "Signal: #{signal}, Receiver: #{step[:device_model]}" if entry
139+
end
140+
source = (coming_from_signal ? last_signal : (index == 0 ? 0 : last_node_id))
141+
link = {
142+
source: source,
143+
target: signal_hash[signal][:id].to_i,
144+
value: 1,
145+
owner: key,
146+
owner_model: step[:device_model]
147+
}
148+
nodes << node if !already_created_signal
149+
links << link
150+
last_node_id += 1 if !already_created_signal
151+
last_signal = signal_hash[signal][:id].to_i
152+
coming_from_signal = true
153+
elsif isWriteSignal(step[:name]) && step[:status] == PASSED
154+
signal = signalContent(step[:name])
155+
receiver = signalReceiver(step[:name])
156+
already_created_signal = signal_hash[signal] ? true : false
157+
signal_hash[signal] = already_created_signal ? signal_hash[signal] : { id: "#{node_id}", receiver: receiver }
158+
node = { name: step[:name], id: signal_hash[signal][:id], image: nil, status: step[:status] }
159+
source = (coming_from_signal ? last_signal : (index == 0 ? 0 : last_node_id))
160+
link = {
161+
source: source,
162+
target: signal_hash[signal][:id].to_i,
163+
value: 1,
164+
owner: key,
165+
owner_model: step[:device_model]
166+
}
167+
nodes << node if !already_created_signal
168+
links << link
169+
last_node_id += 1 if !already_created_signal
170+
last_signal = signal_hash[signal][:id].to_i
171+
coming_from_signal = true
172+
else
173+
node = { name: step[:name], id: "#{node_id}", image: step[:image], status: step[:status] }
174+
source = (coming_from_signal ? last_signal : (index == 0 ? 0 : last_node_id))
175+
link = {
176+
source: source,
177+
target: node_id,
178+
value: 1,
179+
owner: key,
180+
owner_model: step[:device_model]
181+
}
182+
nodes << node
183+
links << link
184+
last_node_id += 1
185+
coming_from_signal = false
186+
end
139187
end
140188
end
141189
return {
@@ -145,6 +193,26 @@ def nodes_and_links feature_report, feature_name
145193
}
146194
end
147195

196+
def isReadSignal step
197+
line = step.split(' ')[1..-1].join(' ')
198+
(line =~ /^I wait for a signal containing "([^\"]*)"$/ ? true : false) || (line =~ /^I wait for a signal containing "([^\"]*)" for (\d+) seconds$/ ? true : false)
199+
end
200+
201+
def isWriteSignal step
202+
line = step.split(' ')[1..-1].join(' ')
203+
line =~ /^I send a signal to user (\d+) containing "([^\"]*)"$/ ? true : false
204+
end
205+
206+
def signalContent step
207+
line = step.split(' ')[1..-1].join(' ')
208+
line.scan(/"([^\"]*)"/).first.first if line.scan(/"([^\"]*)"/).first
209+
end
210+
211+
def signalReceiver step
212+
line = step.split(' ')[1..-1].join(' ')
213+
line.scan(/(\d+)/).first.first if line.scan(/(\d+)/).first
214+
end
215+
148216
def generate_features_report features, device
149217
features.each do |feature|
150218
generate_feature_report feature, device

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def build_execution_command process_number, general_apk, test_files
9999
raise "Theres not a device for process #{process_number}" unless device
100100
apk_path = device.config["apk_path"] ? device.config["apk_path"] : general_apk
101101
raise "Invalid apk path" unless apk_path
102-
cucumber_options = "--format json -o #{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json"
102+
cucumber_options = "--format pretty --format json -o #{KrakenMobile::Constants::REPORT_PATH}/#{@execution_id}/#{device.id}/#{KrakenMobile::Constants::REPORT_FILE_NAME}.json"
103103
execution_command = @command_helper.build_command [BASE_COMMAND, apk_path, cucumber_options, *test_files, "--tags @user#{device.position}"]
104104
env_variables = {
105105
AUTOTEST: '1',

reporter/index.html.erb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,12 @@
638638
let devicesHash = {};
639639
for(var k = 0; k < jsonObject.links.length; k++) {
640640
let link = jsonObject.links[k];
641-
devicesSet.add(link.owner_model);
642-
devicesHash[link.owner_model] = link.owner
641+
devicesSet.add(link.owner);
642+
devicesHash[link.owner] = link.owner_model
643643
}
644644
devices = Array.from(devicesSet);
645-
var numDevices = jsonObject["numDevices"];
646-
647645
// GRAPH
648-
var height = 150*numDevices;
646+
var height = 150*(devices.length-1);
649647
var c20c = d3.scale.category10();
650648
d3.select("#chart_row" + (i+1))
651649
.text(jsonObject["name"])
@@ -683,7 +681,7 @@
683681
var legend = svg
684682
.append("g")
685683
.selectAll("g")
686-
.data(devices)
684+
.data(Object.keys(devicesHash))
687685
.enter()
688686
.append('g')
689687
.attr('class', 'legend')
@@ -698,14 +696,14 @@
698696
.attr('width', legendRectSize)
699697
.attr('height', legendRectSize)
700698
.style('fill', function(d) {
701-
return c20c(devicesHash[d]);
699+
return c20c(d);
702700
})
703701
.style('opacity', .2)
704702

705703
legend.append('text')
706704
.attr('x', legendRectSize + 5)
707705
.attr('y', 10)
708-
.text(function(d) { return d; });
706+
.text(function(d) { return devicesHash[d]; });
709707
}
710708
});
711709
</script>

0 commit comments

Comments
 (0)