Uploading a ZIP-File as an ExecutionAttachment

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

Uploading a ZIP-File as an ExecutionAttachment

Postby volkertoewe » Wed Oct 23, 2013 9:16 pm

I tried to upload a zip file as execution attachment, but it failed. The uploaded attachement ist not readable after download. Could be the filetype the reason for the problem? What filetype should I use?

Perl:
open(FILE, $zipfile) or die "Zipfile kann nicht gelesen werden [$!]\n";
$zipArchive = <FILE>;
close (FILE);

$uploadresult = $cli->send_request('tl.uploadExecutionAttachment', {
'devKey' => $devkey,
'executionid' => $executionid,
'filename' => "$zipfile",
'filetype' => "application/x-zip",
'content' => encode_base64($zipArchive)
});
volkertoewe
TestLink user
 
Posts: 8
Joined: Mon Jan 14, 2013 7:14 pm
Location: Germany, Kiel

Re: Uploading a ZIP-File as an ExecutionAttachment

Postby volkertoewe » Sun Jan 26, 2014 7:36 pm

I found a solution to my problem. This subroutine implemented in perl reports test results to testlink.
The script sets the result status and uploads the result protocol. I changed the upload from ZIP to TXT file.
Feel free th use this example.

...
use RPC::XML;
use RPC::XML::Client;
use Data::Dumper;
use MIME::Base64;
...
#-------------------------------------------------------------------------------------------------------
# reportToTestLink
#
# reports the result for executed test cases in TestLink
#-------------------------------------------------------------------------------------------------------

sub reportToTestLink
{
my $trl_tlproject = $_[0];
my $trl_tltestsuite = $_[1];
my $trl_tltestplan = $_[2];
my $trl_testcase = $_[3];
my $trl_tlerg = $_[4];
my $trl_protocol = $_[5];
my $trl_tcextid = $_[6];
my $trl_server_url = $_[7];
my $trl_devkey = $_[8];

# declarations
my ( $testplanid, $testcaseid, $projectid, $platformid, $buildid, $tcexternalid, $executionid );
my ( $resulttestplan, $resulttestcase, $resultplatform, $resultbuild, $resultresult, $uploadresult, $notes );
my ( $buf, $content );
my %statuses = ('passed' => 'p', 'failed' => 'f', 'blocked' => 'b');

#print "\nreportToTestLink Parameter:";
#print "\nProject : $trl_tlproject";
#print "\nTestsuite : $trl_tltestsuite";
#print "\nTestplan : $trl_tltestplan";
#print "\nTestcase : $trl_testcase";
#print "\nResult : $trl_tlerg";
#print "\nProtocol : $trl_protocol";
#print "\nTestcase External ID: $trl_tcextid";
#print "\nServer URL : $trl_server_url";
#print "\nDev Key : $trl_devkey \n";

$notes ="Executed with PPI TestClient";
my $cli_rp = RPC::XML::Client->new($trl_server_url);

#print "\ngetTestPlanByName \n",
$resulttestplan = $cli_rp->send_request('tl.getTestPlanByName',
{
'devKey'=>$trl_devkey,
'testprojectname'=>$trl_tlproject,
'testplanname'=>$trl_tltestplan
}
);

if (isResponseError($resulttestplan)) {
die "An error occurred in getTestPlanByName ($main::apiLastResponseCode): $main::apiLastResponseString\n";
}
#print Dumper($resulttestplan); # uncomment to see what the raw response looks like

$projectid = $resulttestplan->value->[0]{testproject_id};
$testplanid = $resulttestplan->value->[0]{id};
#print "\nProjectid : $projectid";
#print "\nTestplanid: $testplanid";
#print "\ntl.getTestPlanPlatforms\n",
$resultplatform = $cli_rp->send_request('tl.getTestPlanPlatforms',
{
'devKey' => $trl_devkey,
'testplanid' => $testplanid
}
);
if (isResponseError($resultplatform)) {
die "An error occurred in getTestPlanPlatforms ($main::apiLastResponseCode): $main::apiLastResponseString\n";
}
#print Dumper($resultplatform); # uncomment to see what the raw response looks like

$platformid = $resultplatform->value->[0]{'id'};
#print "\nPlatform: $platformid \n";
#print "\ntl.getTestCase mit Name $trl_tcfullname\n";
$resulttestcase = $cli_rp->send_request('tl.getTestCase',
{
'devKey'=>$trl_devkey,
'testcaseexternalid'=>$trl_tcextid,
}
);

if (isResponseError($resulttestcase)) {
die "An error occurred in getTestCase ($main::apiLastResponseCode): $main::apiLastResponseString\n";
}
#print Dumper($resulttestcase); # uncomment to see what the raw response looks like

$testcaseid = $resulttestcase->value->[0]{'id'};
#print "\nTestcaseid: $testcaseid\n";

#print "\ntl.getBuildsForTestPlan\n",
$resultbuild = $cli_rp->send_request('tl.getBuildsForTestPlan',
{
'devKey' => $trl_devkey,
'testplanid' => $testplanid
}
);

if (isResponseError($resultbuild)) {
die "An error occurred in getBuildsForTestPlan ($main::apiLastResponseCode): $main::apiLastResponseString\n";
}
#print Dumper($resultbuild); # uncomment to see what the raw response looks like

$buildid = $resultbuild->value->[0]{id};

#print "\nDevKey: $tl_devkey";
#print "\nTestcaseid: $testcaseid";
#print "\nTestplanid: $testplanid";
#print "\nStatus: $trl_tlerg";
#print "\nNotes: $notes";
#print "\nBuildid: $buildid\n";
#print "\nPlatformid: $platformid\n";

$resultresult = $cli_rp->send_request('tl.reportTCResult', {
'devKey' => $trl_devkey,
'testcaseexternalid' => $trl_tcextid,
'testplanid' => $testplanid,
'status' => $trl_tlerg,
'buildid' => $buildid,
'notes' => $notes,
'platformid' => $platformid,
"guess" =>"TRUE"
});
if (isResponseError($resultresult)) {
print STDERR "Unable to save result for TC:$testcaseid, platform:$platformid:\n",
"\t($main::apiLastResponseCode): $main::apiLastResponseString\n",
"\t\$notes = $notes\n",
"\t\$status = $trl_tlerg\n";
}
else {
$executionid = $resultresult->value->[0]{'id'};
#print "\nExecutionid: $executionid\n";

open(INFILE, $trl_protocol) or die "Protokoll kann nicht gelesen werden [$!]\n";
binmode INFILE;
while(<INFILE>){
$buf = $buf.$_;
}
$content=encode_base64($buf);
close INFILE;

$uploadresult = $cli_rp->send_request('tl.uploadExecutionAttachment', {
'devKey' => $trl_devkey,
'executionid' => $executionid,
'filename' => "Testclient-Log.out",
'filetype' => "application/octet-stream",
'content' => $content
});


if (isResponseError($uploadresult)) {
print STDERR "Unable to upload attachment for TC:executionid, $testcaseid,:\n",
"\t($main::apiLastResponseCode): $main::apiLastResponseString\n";
}
}
}
volkertoewe
TestLink user
 
Posts: 8
Joined: Mon Jan 14, 2013 7:14 pm
Location: Germany, Kiel


Return to XML-RPC API



Who is online

Users browsing this forum: No registered users and 1 guest