Saturday, March 16, 2013

Add image to Quality Center using OTA and Perl

I thought I would share this little snippet of code that implements the adding of an image file to a specific test step in Quality Center. To accomplish this we will use HP's recommended way of interfacing with their system: Open Test Architecture (OTA). As opposed to trying to go directly to the QC DB.

From the Perl side there are three modules needed (all available from CPAN):
  1. Win32::OLE qw(in valof);
  2. Win32::OLE::Enum;
  3. Win32::OLE::Variant;
You will also need to have the OTA client installed on the computer being used to update the Test Lab. This usually gets downloaded when you first connect to QC. The file name is OTAClient90.dll.

First, the code:

1:  # ATTACH TEST STEP IMAGE IF IT EXISTS  
2:  my $step_up_count = 0;  
3:  if ($TEST_RUN_RESULTS{$test_timestamp}{step_results}->[$step_up_count]{image_link} ne '') {  
4:     my $file_name = "$TEST_RUN_RESULTS{$test_timestamp}{step_results}->[$step_up_count]{image_link}";  
5:          
6:     my $attachment_factory = $run_step->Attachments;  
7:     my $attachment = $attachment_factory->AddItem(Win32::OLE::Variant->new(VT_NULL)); # This returns a Win32::OLE::Variant object type NULL required by AddItem()  
8:     $attachment->{FileName} = "$file_name";  
9:     $attachment->{Type} = 1;  
10:     $attachment->Post;  
11:  }  
12:  $step_up_count++;  

We begin by keeping track of the steps we are adding to QC on line 2.
For attaching the images I implement an IF condition (Line 3) that checks whether an image exists for this step or not. If it does find one we get an instance of the attachment factory for the step being currently updated (Line 6).

A very important step (as in this will not work unless you do this) is to pass Win32::OLE::Variant of type VT_NULL to AddItem. If you do not do this the image will not be updated. That is, $attachment (Line 7) must first be NULL.

After we add the file_name and attachment type (Lines 8-9) we then Post the image and associated attributes to Quality Center Test Lab module.

That is all it takes to add an image to the Test Lab of Quality Center via a program that uses HP's COM interface to QC, Open Test Architecture. If you would like us to implement an automated solution for your company that includes QC integration please contact us; we are happy to provide a quote.

2 comments:

  1. I actually enjoyed reading through this posting.Many thanks
    Miami Web Design Company

    ReplyDelete
  2. Pretty remarkable post. I simply came across your blog and desired to say that I have really enjoyed searching your blog posts.
    Magento Website Miami

    ReplyDelete

Creative Commons License
VGP-Miami Web and Mobile Automation Blog by Alfred Vega is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.