How to use a variable in different files?

Ask general questions here.
rahulj
Posts: 2
Joined: Mon Oct 29, 2012 2:54 pm

How to use a variable in different files?

Post by rahulj » Mon Oct 29, 2012 3:02 pm

Hi,

I am creating a variable username while doing recording of login script. Now i want to use that variable in another recording or code base.So that both the script can read the data from same variable.

Can anyone please let me know how can i make the variable global or how can i use same variable in different files?

Any help would be appreciated and thanks in advance.

Regards,
Rahul Jain

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to use a variable in different files?

Post by Support Team » Tue Oct 30, 2012 2:05 pm

Hi,

Is your variable a Module Variable?
If yes you can for instance create a new global or test case parameter and bind the module variables from the different recordings to the parameter.
This will automatically set the variables from the other modules to the specific value of the login script.
Here is a useful link about this topic: Combining Variables with Parameters.

Regards,
Markus
.
Image

rahulj
Posts: 2
Joined: Mon Oct 29, 2012 2:54 pm

Re: How to use a variable in different files?

Post by rahulj » Tue Oct 30, 2012 2:42 pm

Thanks for the reply,

I want to automate following scenario:

1.Enter valid username.
2.Enter valid password.
3.Store password in some variable for eg. var1.
4.After login gets successfully, Go to change password page.
5.Enter old password using the variable var1 in which old password is stored.
6.Now enter new password in new password field and store that password in some variable like var2.
7.From next time when user login it reads the value from var2.

How can i perform the scenario which either overwrite the value of var1 or replace var1 with var2 when i next time run the script.

Please suggest the workaround.

Thanks,
Rahul Jain

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to use a variable in different files?

Post by Support Team » Tue Oct 30, 2012 4:34 pm

Hi,

Basically you have to create a module variable in the recording where you store the password the first time and
in the Recording or UserCode file where you store the new password.
Now you have two variables and these two variables have to be bound to a global parameter (right click on the test suite and click on Global Parameters...), this will ensure that the second variable will be set to the value of the first and in the next iteration that the first variable will be set to the value of the second one.

Regards,
Markus
.
Image