Forum Discussion

GradyJr's avatar
GradyJr
Contributor
5 years ago
Solved

Different application filepaths for TestedApps

Prior to recording keyword tests/scripts on a system, one must identify the application(s) being tested in the TestedApps area and then, in the script, start an application with the TestApps.<appname>.Run (or RunAs) method. In the TestedApps area of TestComplete, the source/filepath of the executable is identified in the "Application:" textbox. All is well and good until I try to run the project on a different system where the TestedApp application/executable has been installed in a totally different filepath.

 

Now, I can certainly create multiple copies of the application in the TestedApps area (with different names such as MyApp1, MyApp2, etc) and then insert IF logic in the test/script that will find the app in the correct location:

 

If Sys.HostName = "ServerA" Then
Call TestedApps.MyApp1.Run(1, True)
ElseIf Sys.HostName = "ServerB" Then
Call TestedApps.MyApp2.Run(1, True)
Else
Call TestedApps.MyApp3.Run(1, True)
End If

 

but that seems like a bulky, convoluted way to handle it. What I envision would be having an optional configuration file associated with the project suite that can be edited on a particular system with that system's correct values which are read in at project suite start up and utilized for the run. Something like:

<TestExecuteConfig>
<TestedApps>
<MyApp>
<FilePath>C:\ProgramFiles\MyApp.exe</FilePath>

<CommandLineParms></CommandLineParms>

<WorkingFolder></WorkingFolder>
<MyApp/>

<AnotherApp>

<FilePath>C:\ProgramFiles\AnotherApp.exe</FilePath>

<CommandLineParms></CommandLineParms>

<WorkingFolder></WorkingFolder>

</AnotherApp>
</TestedApps>
<SomethingElse>
. . . . . . . . . . . . . . . . 
</SomethingElse>
</TestExecuteConfig>

The "Application:" textbox would dynamically be populated with the FilePath value above requiring only one definition of the application in the TestApps area and no IF logic necessary.

Does anything like this exist in TestComplete/TestExecute and, if not, what is the best way to handle it? I searched the Help files within the TestComplete application and this Community Board but didn't really see anything close to this.

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    There's not EXACTLY a way of importing a TestedApp in like that.  However, a couple of things:

     

    1) TestedApps is an object in TestComplete with a method called "Add" where you can add a tested application on the fly.  Sample code is at https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/tested-apps/testedapps/add.html along with all sorts of other documentation.
    2) TestedApp is an individual item within the TestedApps collection which you can set a number of properties on as well. (https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/tested-apps/testedapp/methods.html)

    3) There is an object called Storages which has an XML capability.  (https://support.smartbear.com/testcomplete/docs/testing-with/advanced/working-with-external-data-sources/xml.html#Storages

     

    Combine these three different pieces and you can write code to do EXACTLY what you want: read configuration information from an XML file into the project and use it to launch your tested application regardless of machine.

    • GradyJr's avatar
      GradyJr
      Contributor

      Sorry for not responding sooner.  I was able to accomplish what I needed by using your first suggestion of dynamically adding testedapps on those servers where the applications are installed on a different drive or have any sort of different file path name.  i created index variables for the applications and Initialization and  finalization routines. In the initialization, if it is one of the servers that doesn't conform to the normal naming convention, i add a testedapp and store its index in the variable for that app. if it's not, then I'm using the TestedApps.Find("appname") to get the index. The finalization routine simply deletes any tested apps that had to be added. Thanks again!

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Thank you for the update, glad to hear tristaanogre's advice helped:smileyhappy:

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thank you tristaanogre.

       

      Hi GradyJr have you tried inplementing the approach above?