03-02-2011, 11:16 PM
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.
When your script is ready to load and set these variable values, do this in your code:
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:
"downloadEnvironmentVariablesFile" is a function we wrote and is defined in function library file "Quality Center Functions.qfl":
Hope this helps.
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>
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.