Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URL Variables
#2
Solved: 10 Years, 9 Months, 3 Weeks ago
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


Messages In This Thread
URL Variables - by kevwhite79 - 03-02-2011, 09:27 PM
RE: URL Variables - by tdevick - 03-02-2011, 11:16 PM
RE: URL Variables - by kevwhite79 - 03-03-2011, 01:53 AM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)