cancel
Showing results for 
Search instead for 
Did you mean: 

Using Global variables in Unit Script

SOLVED
New Contributor

Using Global variables in Unit Script

Trying to learn scripting, and have a simple script that opens a webpage and logs in. I have successfully gotten this to work using local variables, however I want to use persistent variables that can be reused in other scripts. So I created a new variable with a type of 'String' as such:

Name: PageLink

Type: String

Default Value: http://www.mypage.com/login/

Local Value: http://www.mypage.com/login/

 

In my script, I can open the browser to the page if I set the variable locally, i.e:

Sub Login
Dim Env
Env = "http://www.mypage.com/login/"
Browsers.Item(btIExplorer).Run Env
End Sub

That will open IE to the page set in 'Env'.

 

If I try using my global variable:

 

Sub Login
Dim Env
Dim Variables
Set Variables = ProjectSuite.Variables
Env = Variables.VariableByName("PageLink")
Browsers.Item(btIExplorer).Run Env
End Sub

Then I get the error message: "The Variables object does not contain a variable with the "PageLink" name".

 

I'm not quite sure what I'm doing wrong, or how I can tell my local variable to get its value from my global variable?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Using Global variables in Unit Script

When you create a variable in the Project/ProjectSuite, It autocompletes after typing Project.Variables.

 


@Dekks wrote:

 

 

Sub Login
Dim Env
Dim Variables
Set Variables = ProjectSuite.Variables
Env = Variables.VariableByName("PageLink")
Browsers.Item(btIExplorer).Run Env
End Sub 

You do not need to go like this much lines code to get your variable. Just do like below after creating a variable.

Browsers.Item(btIExplorer).Run ProjectSuite.Variables.PageLink

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

5 REPLIES 5
Community Hero

Re: Using Global variables in Unit Script

When you create a variable in the Project/ProjectSuite, It autocompletes after typing Project.Variables.

 


@Dekks wrote:

 

 

Sub Login
Dim Env
Dim Variables
Set Variables = ProjectSuite.Variables
Env = Variables.VariableByName("PageLink")
Browsers.Item(btIExplorer).Run Env
End Sub 

You do not need to go like this much lines code to get your variable. Just do like below after creating a variable.

Browsers.Item(btIExplorer).Run ProjectSuite.Variables.PageLink

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Community Hero

Re: Using Global variables in Unit Script

Hi,

 

> Set Variables = ProjectSuite.Variables

Check if you created ProjectSuite variable or Project variable.

In the latter case you must use

Set Variables = Project.Variables
Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Hero

Re: Using Global variables in Unit Script

You can also skip the step of assigning the local variable.  Just use the global variable directly.

New Contributor

Re: Using Global variables in Unit Script

Apologies for the late response, that worked perfectly thank you. I am able to call my variable directly by saying [action] Project.Variables.PageLink.

One thing I'm not entirely clear on is whether it fetches Default Value or Local value? (I have them both set to the same value).

Community Hero

Re: Using Global variables in Unit Script

Hi,

 

> whether it fetches Default Value or Local value?

Local value is used in all cases.

The only case when Default value is used is when you open test project in the shared mode for the first time. Only in this case Default value is used in order to populate the initially empty Local one. See https://support.smartbear.com/testcomplete/docs/working-with/teamwork/sharing-projects.html for more details if needed.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members 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. Postings made by [Community Expert Group] members
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.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors