https://www.qatechies.com

QTP or UFT and VBScript: How to download file from QC or ALM ?

Latest Tosca,QTP,UFT,CodedUI Interview Questions

QTP\UFT and VBScript : How to download file from QC or ALM?


Welcome to this post!-“QTP or UFT and VBScript: How to download file from QC or ALM ?”

If you are looking for latest HP UFT \ QTP  interview Questions, then you are at right place. This post “How to download file from QC \ How to download file from ALM” consists of technical interview question which have been part of many interviews either external or internal. Usually these are assumed to be known in depth to check the logical solvency efficiency of the candidate and of course suitability for the project and company. Go ahead and enjoy reading…

This discussion will help you prepare well if you are going for the interview or you need the function to be used in your project.

 

In the interview usually, you might be questioned in different way like:

  1. How to download a file of any type from QC ?
  2. How to download the excel from ALM ?
  3. How to download the resource from QC ?
  4. How can you save QC resource onto a local folder ?
  5. How to download the script dependent file from QC?
  6. How to link a file from QC?
  7. How QTP or UFT downloads a file from QC \ ALM?,
  8. How to work with OTA in terms of downloading a resource from QC?

and so on.

Well, most of the time testers find it difficult while working with automation frameworks to find a solution on getting resources from qc directly to local working folder rather manually doing it plus scenarios can also be like other test suite automated scripts require previous resources which are stored in QC or in turn the changed test data file needs to be downloaded to local folder so that another script might pick up the latest file and start working on it. The scenarios can be many but what exactly is the common solution possible to it, this is what we are going to discuss.

Firstly, you need to understand that QC in itself is a complete module and has an object model too just like UFT or QTP has automation object model or AOM.

People tend to confuse themselves as they are unaware of this fact that QC or ALM has its built-in model on which it works, so to understand it better we will take the example of downloading the file from QC or ALM using OTA, but before discussing the complete code, we will visit the code in parts to understand what exactly is meant there.

Sounds Good! right?

So, to begin with, let us focus on discussing the most important part of writing code which is always create a heading comment section whenever you are writing code, it’s a good practice and really matters when you are liable for the module or application under test in which you were working. The readers or peers should be able to concentrate or focus on the usage of function just by going through your comments. Let me show you a good way with example.

Consider the heading comments below:

 

'------------------------------------------------------------'
'Function Name : Fn_DownloadFileFromALM
'Documentation: download any file with any resource type to local folder from the QC \ ALM module
'Created By : Prachur Saxena

 

 

It looks fair enough for anyone reading the heading comments of the function as there is good information given here. But we can save more time of code readers by providing the input and output expected or valid values for this function. Don’t you think so! it will be really a good for another person to go through it easily, right?

 

Let’s revisit the same again,

 

'------------------------------------------------------------'
'Function Name : Fn_DownloadFileFromALM
'Documentation: download any file with any resource type to local folder from the QC \ ALM module
'Created By : Prachur Saxena
'Date : 13/1/2018
'Modified By: NA
'Revision Comments: NA
'Return Values: True or False
'Example: Fn_DownloadFileFromALM "test_data.xls","C:\Users\Public\Documents\TEST_DATA_Files”
'-----------------------------------------------------------

 

Wow! now that’s look fantastic and quite impressive to understand for anyone to use the function in his code.

With this information he skips many steps like code debugging, asking another tester to understand the code and actually waste both the persons time, etc. The more you put input parameters examples the better it becomes as it gives much clarity on the working logic.

 

There are 3 additional comments which are shown here i.e. Date, Modified By, Revision Comments – these are a MUST and should be mentioned in the comments. The impact initially won’t occur to you if you are the developer of the function but will give you broader view if someone else has done that code and you are being asked to work on it.

If This Sounds Often to you, then make a HABIT of doing it.

 

Here I believe our very first part of writing a good function heading with comments ends. Now let’s focus on the code that we are targeting on the blog that is how to download any file from QC or ALM to your local folder.


Part 1 : Variables

Dim ResCount : ResCount = 0

Dim iterator

Dim ObjQC,CurrentResObj,ObjResFactory,ResObjList

 

In the beginning of the code it is really a good practice to write all your variables. Here we have declared all variables like

ResCount = for storing the count of resources which we receive from the collection of resources available in QC or ALM.

iterator = is just a variable for FOR loop,

CurrentResObj = points to each new resource which we get inside the FOR loop, while iterating through the resource collection.

And declare all variables related to storing the connection and resource object list or object.


Part 2 : Assignments

 Set ObjQC = QCUtil.QCConnection 

Set ObjResFactory = ObjQC.QCResourceFactory

 Set ResObjList =ObjResFactory.NewList("") 

ResCount = ResObjList.Count

 

In this section we are assigning the variables with values or creating the instances of the classes.

Firstly,

Set ObjQC = QCUtil.QCConnection } = > we are creating the object of connection to QC,

Now with the help of your QC connection object, get the instance of QCResourceFactory and store the list available within ‘ObjResFactory’ object in the variable ‘ResObjList’.

Finally get the count of all the available resources and store it in the variable declared earlier:

ResCount = ResObjList.Count


Part 3 : Execution

Now in this part, we are iterating in FOR loop with iterator as our variable here. Now accessing each of the collection object available in the list ‘ResObjList’ with the help of ‘Item’ method.

 

For iterator = 1 To ResCount

   Set CurrentResObj = ResObjList.Item(iterator)
      if InStr(1,CurrentResObj.Name,DownloadResName,1) > 0 then
	    om error resume next
		CurrentResObj.DownloadResource SaveToFolderPath,True

Next

 

Now match the two values first your currentResobj name ( get the name as by using code currentResobj.Name ) and second your expected DownloadResName with the help in built function of VBScript – InStr.

If the match is successful, then use the method for downloading the file,as

CurrentResObj.DownloadResource “<your local file path>”, true

Specify the local path as we want the exact location on which we want to download the should happen.

Once this is done exit the FOR loop.

Now try uploading the file onto the resource location you got in hand.

Now check if your download happened correctly or not.


Part 4 : Result

In this part you have either error in hand or a successful download of the file. In case some error has occurred then it is reported as FAIL along with the description. And here value for return is set to False.

If download was successful then PASS event is called and value of return is set to True.

‘catch your error here

		'catch your error here
        if Err.Number <> 0  then
 
           reporter.ReportEvent micFail,"File download from ALM got FAILED. please check the error:=" &  Err.Description
           Fn_DownloadFileFromALM  = False
		   ExitTest(1)
        else
 
           reporter.ReportEvent micPass,"File download from ALM was successful."
           Fn_DownloadFileFromALM = True
           
		   'do exit for as your file got downloaded
		   Exit For
        end if

 

Part 5: Releasing objects

A very crucial step is releasing the objects which you have used. Most of the times we do not release them thinking this might happen itself, but in VbScript there is no guarantee to be honest. For some objects it happens correctly and for some it might have memory links open. So, to avoid any future issues, it’s always good to write code for release the binding as shown below:

Set ResObjList = Nothing

Set CurrentResObj = Nothing

Set oNewResObj = Nothing

Set ObjResFactory = Nothing

Set ObjQC = Nothing


Till now we have discussed the complete code but in parts, now let’s have a look on the complete code:

A word of Caution!
Before running this code please check you have active connection available to QC or ALM.

'------------------------------------------------------------'
'Function Name : Fn_DownloadFileFromALM
'Documentation: download any file with any resource type to local folder from the QC \ ALM module
'Created By : Prachur Saxena
'Date : 13/1/2018
'Modified By: NA
'Revision Comments: NA
'Return Values: True or False
'Example: Fn_DownloadFileFromALM "test_data.xls","C:\Users\Public\Documents\TEST_DATA_Files”
'-----------------------------------------------------------
Function Fn_DownloadFileFromALM(DownloadResName,SaveToFolderPath)
Dim ResCount : ResCount = 0
Dim iterator
Dim ObjQC,CurrentResObj,ObjResFactory,ResObjList

Set ObjQC = QCUtil.QCConnection

Set ObjResFactory = ObjQC.QCResourceFactory

Set ResObjList = ObjResFactory.NewList("")


ResCount = ResObjList.Count

For iterator = 1 To ResCount

   Set CurrentResObj = ResObjList.Item(iterator)
      if InStr(1,CurrentResObj.Name,DownloadResName,1) > 0 then
	    om error resume next
		CurrentResObj.DownloadResource SaveToFolderPath,True
		
		'catch your error here
        if Err.Number <> 0  then
 
           reporter.ReportEvent micFail,"File download from ALM got FAILED. please check the error:=" &  Err.Description
           Fn_DownloadFileFromALM  = False
		   ExitTest(1)
        else
 
           reporter.ReportEvent micPass,"File download from ALM was successful."
           Fn_DownloadFileFromALM = True
           
		   'do exit for as your file got downloaded
		   Exit For
        end if
	    
		
	  End if 
   
Next

Set ResObjList = Nothing
Set CurrentResObj = Nothing
Set oNewResObj = Nothing
Set ObjResFactory = Nothing 
Set ObjQC = Nothing

End Function

 

 

In different scenarios of course, the parameters will change. But I really doubt that till now you have noticed the actual benefit out here? Have you?

In layman terms, the function is able to receive any resource type for download which is amazing don’t you think. You don’t need to make code for each of the resource type’s. One function is enough to handle the complete scenarios.

Plus, this makes the function more adaptable to any framework in question like linear, hybrid, keyword etc. You can use this with any existing framework or if you are designing a framework from scratch.


The important points to note here are:

  1. Prior calling the function you must know which type of resource you are targeting for the download.
  2. Often this kind of functions are used to download the excel file containing the test data, etc. These test data files can be used later as reference in calling scripts.
  3. This function gives more flexibility in downloading the files to your project designated folders.
  4. This function also gives you flexibility in downloading Different Types of Files.
  5. This function can be part of any framework in hand, i.e. regardless of kind of framework it can be easily adapted.

 

I really hope you enjoyed reading the post. If you have any doubt on this please feel free to add your comment below.


And if you like to read more on UFT or QTP Technical Interview Questions please follow below links:

UFT Technical Interview Questions – Set 1

UFT Technical Interview Questions – Set 2

How to Upload Resource To QC\ALM?

Or if you prefer General Interview Questions please follow below links:

UFT General Interview Questions – Part 1

UFT General Interview Questions – Part 2


If you would like to keep track of further articles on UFT (QTP). I recommend you to SUBSCRIBE by Email and have new UFT articles sent directly to your inbox.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

advanced-floating-content-close-btn
https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5034726663464946 (adsbygoogle = window.adsbygoogle || []).push({});
advanced-floating-content-close-btn 
*************************** Do you want to learn TOSCA? Do you want to excel in Career? Try my New Courses: 1. Tricentis Tosca and Working with Excel   2. Tricentis Tosca and UI Automation Great News!!   Price has been slashed down for limited period of time.So Hurry!!! Click The Shown Links and Enjoy Learning. ***************************
 
error: Content is protected !!