Forum Discussion

rajeshthomas's avatar
rajeshthomas
Contributor
13 years ago

Run Registry file from Test Complete

Hi



The software we are working have 3 version but the look and feel, functions and navigation of the software is same. Each version require different registry setup. Since the application is same we planned to use the same Project suite and test cases for testing all the versions.



We made a copy of the registry file for each version  and stored in the Stores>File (of Test Complete). And we planning to run the registry from a test item.



Our plan is to run the corresponding registry for the respective version. In order to that i need to run the Registry. Can anybody help me in script to run ( or dblclick) the registry file from the test item. 



Or is there is any better way to handle this scenario.



Please advice..






3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Rajesh,



    You can import a .reg file into the registry programmatically by executing the reg import command:

    reg import <path>\MyFile.reg


    In scripts, you can run this command using the WshShell.Run method, like this:

    Dim oShell, strFileName, iExitCode



    ' Get the name and path of the .reg file in Stores

    strFileName = Files.FileNameByName("MyRegFile")



    Set oShell = Sys.OleObject("WScript.Shell")

    iExitCode = oShell.Run("reg import """ & strFileName & """")



    If iExitCode = 0 Then

      Log.Message "The Reg file was imported successfully."

    Else

      Log.Error "Importing the reg file failed."

    End If


    Note that if you are using Windows 7 or Vista with UAC enabled, you may need to run TestComplete as an administrator in order for the reg import command to be executed successfully (see Testing Applications With TestComplete Under Windows Vista and Later Operating Systems).
  • Thanks, i got it. 



    But i had a problem with the Exit Code part. Even if there is no file in the location or wrong file name, the log message was "Registry imported correctly".



    so i changed 



    if strFileName  = empty then 

    log.message("Registry is not imported")



    Did i handle it fine or there is any side effects for the above script.



    Thanks




  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Rajesh,



    To check whether the file exists, use the aqFileSystem.Exists method:

    If Not aqFileSystem.Exists(strFileName) Then

      Log.Error "The file """ & strFileName & """ does not exist."

    Else

      ' Do the registry import

      ...

    End If