cancel
Showing results for 
Search instead for 
Did you mean: 

Environment variable in persistent variables declaration

SOLVED
Highlighted
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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: Environment variable in persistent variables declaration

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

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Re: Environment variable in persistent variables declaration

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.

Highlighted
New Contributor

Re: Environment variable in persistent variables declaration

What's the best way to show the code? 

Highlighted
Community Hero

Re: Environment variable in persistent variables declaration

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

Highlighted
Community Leader

Re: Environment variable in persistent variables declaration

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

View solution in original post

Highlighted
New Contributor

Re: Environment variable in persistent variables declaration

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?

 

 

Highlighted
Community Manager

Re: Environment variable in persistent variables declaration

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


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
New Contributor

Re: Environment variable in persistent variables declaration

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

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors