Ask a Question

Environment variable in persistent variables declaration

SOLVED
rasmus
New Contributor

Environment variable in persistent variables declaration

I want to use a Windows environment variable in the persistent variables section of a keyword test.

E.g. Something line InstallFolder is %TEMP%\MyAppLocation.

Using the variable InstallFolder works fine when defining the tested apps. E.g MyApp is $(InstallFolder)\MyApp.exe. The application starts as expected.

 

But when adding a check in JavaScript to verify if the InstallFolder folder exists, the check fails because the variable %TEMP% is not expanded.

E.g.  aqFileSystem.Exists(Project.Variables.InstallFolder) returns false because Project.Variables.InstallFolder returns the string %TEMP%\MyAppLocation and not <Where ever my temp folder is>\MyAppLocation.

 

How can I fix this?

 

I'm new to TestComplete. So if my question may be a little bit unprecise. Hope it is not too confusing ...

 

TestComplete 14.40

Windows 10

Scripting language JavaScript

7 REPLIES 7
Marsha_R
Community Hero

Let's see the actual code from both calls.  It's probably just a syntax difference but we need to see it in order to help.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

What's the best way to show the code? 

You can copy paste or insert a screenshot.  Up to you.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame

You have some environment variables directly avaiable with Sys.OSInfo object.

For example, to get the specific value of %TEMP% you must use Sys.OSInfo.TempDirectory

 

For other environment variables:

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqenvironment/getenvironme...

 

For general use for environment variables:

https://support.smartbear.com/testcomplete/docs/testing-with/advanced/environment-variables.html

 

 

 

Un sourire et ça repart

Seems that the environment variable is not expanded automatically.

 

Variables:

rasmus_2-1589436616759.png

Tested apps using the variables:

rasmus_3-1589436685000.png

Test case:

rasmus_4-1589436754178.png

Value of Project.Variables.InstallFolder at breakpoint

rasmus_5-1589436817171.png

 

Is there any way to expand environment variables when defining project variables in the persistent variables window?

 

 

sonya_m
SmartBear Alumni (Retired)

Hi @rasmus , have you tried what Benoit suggested above ? It seems to be what you are looking for.


Sonya Mihaljova
Community and Education Specialist

rasmus
New Contributor

Hi,

the solution Benoit suggested was not exactly what I'm looking for. Using the %TEMP% variable was an example only. But anyway - I'm using C:\Test now for my tests. Works fine on all my windows machines.

 

Rasmus

cancel
Showing results for 
Search instead for 
Did you mean: