#!/usr/bin/env perl # ABSTRACT: Bulk mark entire runs/plans (or groups of tests therein) as the provided status. # PODNAME: testrail-bulk-mark-results =head1 USAGE testrail-bulk-mark-results [OPTIONS] status [reason] =head1 DESCRIPTION Sometimes it is useful to mark entire runs of tests when, for example, a prerequisite test in a sequence invalidates all further tests. For example, if a binary produced for test fails to run at all, more detailed testing will be impossible; it would save time to just mark everything as blocked. =head2 PARAMETERS: =head3 MANDATORY PARAMETERS -j --project [project]: desired project name. -r --run [run]: desired run name. =head3 SEMI-OPTIONAL PARAMETERS -p --plan [plan]: desired plan name. Required if the run passed is a child of a plan. -e --encoding: Character encoding of arguments. Defaults to UTF-8. See L for supported encodings. =head3 OPTIONAL PARAMETERS -c --config [config]: configuration name to filter plans in run. Can be passed multiple times. -a --assignedto [user]: only mark tests assigned to user. Can be passed multiple times. =head3 CONFIG OPTIONS In your \$HOME, (or the current directory, if your system has no concept of a home directory) put a file called .testrailrc with key=value syntax separated by newlines. Valid Keys are: apiurl,user,password =head3 CONFIG OVERRIDES These override the config, if present. If neither are used, you will be prompted. --apiurl [url] : full URL to get to TestRail index document --password [key] : Your TestRail Password, or a valid API key (TestRail 4.2 and above). --user [name] : Your TestRail User Name. =head2 TESTING OPTIONS: --mock: don't do any real HTTP requests. --help: show this output =cut use strict; use warnings; use utf8; use TestRail::API; use TestRail::Utils; use Getopt::Long; Getopt::Long::Configure('pass_through'); use File::HomeDir qw{my_home}; use File::Find; use Cwd qw{abs_path}; use File::Basename qw{basename}; use Pod::Perldoc 3.10; sub help { @ARGV = ($0); Pod::Perldoc->run(); exit 0; } my %opts; GetOptions( 'apiurl=s' => \$opts{'apiurl'}, 'password=s' => \$opts{'pass'}, 'user=s' => \$opts{'user'}, 'j|project=s' => \$opts{'project'}, 'p|plan=s' => \$opts{'plan'}, 'r|run=s' => \$opts{'run'}, 'c|config=s@' => \$opts{'configs'}, 'a|assignedto=s@' => \$opts{'users'}, 'mock' => \$opts{'mock'}, 'e|encoding=s' => \$opts{'encoding'}, 'h|help' => \$opts{'help'} ); if ($opts{help}) { help(); } my $status = $ARGV[0]; my $reason = $ARGV[1]; die("No status to set provided.") unless $status; #Parse config file if we are missing api url/key or user my $homedir = my_home() || '.'; if (-e $homedir . '/.testrailrc' && (!$opts{apiurl} || !$opts{pass} || !$opts{user}) ) { ($opts{apiurl},$opts{pass},$opts{user}) = TestRail::Utils::parseConfig($homedir,1); } TestRail::Utils::interrogateUser(\%opts,qw{apiurl user pass project run}); if ($opts{mock}) { use Test::LWP::UserAgent::TestRailMock; $opts{browser} = $Test::LWP::UserAgent::TestRailMock::mockObject; $opts{debug} = 1; } my $tr = TestRail::API->new($opts{apiurl},$opts{user},$opts{pass},$opts{'encoding'},$opts{'debug'}); $tr->{'browser'} = $opts{'browser'} if $opts{'browser'}; $tr->{'debug'} = 0; my $project = $tr->getProjectByName($opts{'project'}); if (!$project) { print "No such project '$opts{project}'.\n"; exit 6; } my ($run,$plan); if ($opts{'plan'}) { $plan = $tr->getPlanByName($project->{'id'},$opts{'plan'}); if (!$plan) { print "No such plan '$opts{plan}'!\n"; exit 1; } $run = $tr->getChildRunByName($plan,$opts{'run'}, $opts{'configs'}); } else { $run = $tr->getRunByName($project->{'id'},$opts{'run'}); } if (!$run) { print "No such run '$opts{run}' matching the provided configs (if any).\n"; exit 2; } my $user_ids; #Process assignedto ids if ($opts{'users'}) { eval { @$user_ids = $tr->userNamesToIds(@{$opts{'users'}}); }; if ($@) { print "$@\n"; exit 5; } } my $cases = $tr->getTests($run->{'id'},undef,$user_ids); if (!$cases) { print "No cases in TestRail to mark!\n"; exit 3; } my ($status_id) = $tr->statusNamesToIds($status); @$cases = map { { 'test_id' => $_->{'id'}, 'status_id' => $status_id, 'comment' => $reason, 'version' => $opts{'version'} } } @$cases; my $results = $tr->bulkAddResults($run->{'id'},$cases); print "Successfully set the status of ".scalar(@$results)." cases to $status.\n"; exit 0; __END__ L L for the finding of .testrailrc =head1 SPECIAL THANKS Thanks to cPanel Inc, for graciously funding the creation of this distribution.