From bc2ff9916b3a95113f3a6d4e97ffadd288f75bdc Mon Sep 17 00:00:00 2001 From: Quentin Delance Date: Wed, 30 Dec 2015 09:18:04 +0100 Subject: [PATCH 1/2] Provide user feedback thu echo command --- apps/selenium/mode/scenario.pm | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/selenium/mode/scenario.pm b/apps/selenium/mode/scenario.pm index dd41cc2cd..abef5afdc 100644 --- a/apps/selenium/mode/scenario.pm +++ b/apps/selenium/mode/scenario.pm @@ -91,7 +91,7 @@ sub check_options { alarm($self->{option_results}->{timeout}); } if (!defined($self->{option_results}->{scenario})) { - $self->{output}->add_option_msg(short_msg => "Please specify a scenario name" . $self->{option_results}->{scenario} . "."); + $self->{output}->add_option_msg(short_msg => "Please specify a scenario name."); $self->{output}->option_exit(); } } @@ -124,6 +124,8 @@ sub run { my $step = $listActionNode->get_nodelist; my $temp_step = 0; my $stepOk = 0; + my $last_echo_msg = undef; + my $last_cmd = undef; my $exit1 = 'UNKNOWN'; foreach my $actionNode ($listActionNode->get_nodelist) { ($action, $filter, $value) = $xp->find('./td', $actionNode)->get_nodelist; @@ -142,11 +144,16 @@ sub run { sleep($sleepTime / 1000); $stepOk++; $self->{output}->output_add(long_msg => "Step " . $temp_step . " - Pause : " . $sleepTime . "ms"); + # It's an echo command => do not send it to Selenium server + # and store the associated string so that it can be displayed + # in case of a failure as an info message } elsif ($trim_action eq 'echo'){ - next; + $last_echo_msg = $trim_filter; + $stepOk += 1; } else { my $exit_command; + $last_cmd = $trim_action . ' ' . $trim_filter . ' ' . $trim_value; eval { $exit_command = $sel->do_command($trim_action, $trim_filter, $trim_value); }; @@ -172,8 +179,17 @@ sub run { my $exit2 = $self->{perfdata}->threshold_check(value => $timeelapsed, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed)); + if ($exit eq 'OK') { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%d/%d steps (%.3fs)", $stepOk, $step, $timeelapsed)); + } else { + my $extra_info = $last_cmd; + if (defined($last_echo_msg)) { + $extra_info .= " - $last_echo_msg"; + } + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%d/%d steps (%.3fs) - %s", $stepOk, $step, $timeelapsed, $extra_info)); + } $self->{output}->perfdata_add(label => "time", unit => 's', value => sprintf('%.3f', $timeelapsed), min => 0, From 141ac83273af3dc0a238f1c32f38ff8e5a448c1f Mon Sep 17 00:00:00 2001 From: Quentin Delance Date: Wed, 30 Dec 2015 10:29:26 +0100 Subject: [PATCH 2/2] Modif after code review --- apps/selenium/mode/scenario.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/selenium/mode/scenario.pm b/apps/selenium/mode/scenario.pm index abef5afdc..27ead607b 100644 --- a/apps/selenium/mode/scenario.pm +++ b/apps/selenium/mode/scenario.pm @@ -124,8 +124,7 @@ sub run { my $step = $listActionNode->get_nodelist; my $temp_step = 0; my $stepOk = 0; - my $last_echo_msg = undef; - my $last_cmd = undef; + my ($last_echo_msg, $last_cmd); my $exit1 = 'UNKNOWN'; foreach my $actionNode ($listActionNode->get_nodelist) { ($action, $filter, $value) = $xp->find('./td', $actionNode)->get_nodelist; @@ -149,6 +148,8 @@ sub run { # in case of a failure as an info message } elsif ($trim_action eq 'echo'){ $last_echo_msg = $trim_filter; + # Prevent output breakage in case of echo message contains invalid chars + $last_echo_msg =~ s/\||\n/ - /msg; $stepOk += 1; } else { my $exit_command;