Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URL Variables
#1
Hi,
I'm very new to QTP so please help. I have created a number of QTP scripts and uploaded them to HPQC, connectivity is established and scripts can be played back ok.
However, my intention is to run these scripts on multiple test environments now (same screens just log in via different URLs). So I wanted to link to an external (XML?) file that contains the URL information so that changing the URL in this file would point the scripts to the desired test environment. I'm not finding this easy to do. Can you give me some advice please on setting up the first few steps of the scripts to check the external file for the URL to use when IE loads. I have tried creating and using a User Defined Environment Variable without success :-( Thanks in advance for any help.
PS If username and password can be stored in the file also that would be great.
Reply
#2
create an XML environment file in this format, and store it in where it can always be found on disk by your tests. You can have as many "<Variable>" tags as you want in your XML file. Each "<Variable>" tag must contain a "<Name>" and a "<Value>" sub-tags.

The file must start with "<Environment>" and end with "</Environment>". Within that context, you can define whatever variables you want. In the example below, if the URL of your test server changes, you change the PRODUCT_URL tag's value.

Code:
<Environment> <Variable> <Name>LOGIN_ID</Name> <Value>automation@gmail.com</Value> </Variable> <Variable> <Name>LOGIN_PASSWORD</Name> <Value>yourpassword</Value> </Variable> <Variable> <Name>PRODUCT_URL</Name> <Value>http://www.myproductserver1.com</Value> </Variable> </Environment>
When your script is ready to load and set these variable values, do this in your code:

Code:
'get the currently loaded external file name; blank if not file loaded fileName=Environment.ExternalFileName If (fileName="") Then Environment.LoadFromFile(" "C:\Automation XML Files\Automation Environment Variables.xml") End If

We have been keeping our xml file in the QC repository under "Resources", where function libraries are stored. I created a sub-directory there named "xml files" and store our xml file there. That way it is under source control so you can see the change history and you can revert to a previous version if you want.

doing that required a little more work:

Code:
fileName=Environment.ExternalFileName If (fileName="") Then executeFile("[QualityCenter\Resources] Resources\Function Libraries\Quality Center Functions.qfl") fileName=downloadEnvironmentVariablesFile("Environment Variable XML files", "C:\Automation XML Files", "Automation Environment Variables.xml") Environment.LoadFromFile(fileName) End If

"downloadEnvironmentVariablesFile" is a function we wrote and is defined in function library file "Quality Center Functions.qfl":

Code:
Option Explicit Public Function downloadEnvironmentVariablesFile(ByVal ResourceFileDirectory, ByVal hostDownloadDirectory, ByVal EnviromentVariablesFileName) Dim index, filename,itemCount, itemName,found,folderList,folderItemCount,folderItemName,itemList,AutomationEnvironmentVariablesXML, itemID,itemType,itemData, AutomationResourceFile, _ downloadPath downloadEnvironmentVariablesFile="" set folderList=QCUtil.QCConnection.QCResourceFolderFactory.root.QCResourceFolderFactory.newlist("") folderItemCount=folderList.count folderItemName=folderList.item(1).name found=false ' find all folders under the root of the Resources section of QC ' search for the folder that contains the Automation environment xml file For index =1 to folderItemCount itemName=folderList.item(index).name If itemName=ResourceFileDirectory Then found=true exit for End If Next If found Then set itemList=folderList.item(index).QCResourceFactory.newlist("") itemCount=itemList.count found=false For index=1 to itemCount If itemList(index).name=EnviromentVariablesFileName Then found=true exit for End If Next set AutomationResourceFile=itemList(index) itemName=AutomationResourceFile.name itemType=AutomationResourceFile.type itemData=AutomationResourceFile.path filename=AutomationResourceFile.FileName ' so far, name , id ,type, and path all work OK downloadPath=AutomationResourceFile.DownloadResource(hostDownloadDirectory,True) downloadEnvironmentVariablesFile=downloadPath &"\" & filename End If End Function

Hope this helps.
Reply
#3
Thank you very much. I will try this tomorrow.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  where to declare variables?? ACCBAJPA 0 2,771 10-01-2013, 07:20 PM
Last Post: ACCBAJPA
  Break up a string of text and variables csutter2002 3 4,444 03-20-2013, 06:58 AM
Last Post: basanth27
  Problems with URL as Object identifier??? jcraig26 1 3,884 02-27-2013, 05:06 PM
Last Post: anil2u
Question User-Defined Environment Variables vs. Global Variables vs. DataTable Values imzeeshan 0 3,492 11-16-2012, 01:51 AM
Last Post: imzeeshan
  Parameter values VS Environmental Variables Brian.Osborne 1 2,760 10-11-2012, 01:47 PM
Last Post: harishshenoy

Forum Jump:


Users browsing this thread: 1 Guest(s)