This is a migrated thread and some comments may be shown as answers.

Passing Variable from SubTest to Parent to SubTest

3 Answers 136 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Garry
Top achievements
Rank 1
Garry asked on 24 Dec 2010, 01:37 AM
I have a variable that is created in a Subtest that I would need to reuse in another subtest. The System I am using requires Unique email addresses for Registration. In the Register subtest, I concat the First Name, Last Name, and Date Ticks to create a unique email address every time. The email address does not need to be valid at this time.

Subtest Register - create unique email
Subtest Login - use unique email to log in

These are part of a Main test with an Excel Data Source that the subtest Register is pulling the first and last name from.

My though would be if the email variable could be global.

Thanks,
Garry

3 Answers, 1 is accepted

Sort by
0
Nikolai
Telerik team
answered on 24 Dec 2010, 06:53 AM
Hi Garry,

You can define a global variable in your parent test then set its value from the child using simple code.
How to:

1. Create two tests - Parent, Child in my case
2. Declare global variable in the Parent test

public static string Email {get; set;}
3. Call the Child test from the Parent
4. In the Child test create a coded step from which you will set the value of the Email variable 
 
Parent.Email = "test@mail.com";

5. Back in the Parent test use the new value of the global variable
Pages.Google.QText.Text = Parent.Email;

Hope this helps.


All the best,
Nikolai
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Garry
Top achievements
Rank 1
answered on 27 Dec 2010, 11:56 PM
Is there a way to reference the variable in the child test, so that the child test can be used in many scripts?
0
Nikolai
Telerik team
answered on 29 Dec 2010, 06:04 AM
Hi Garry,

About your latest question:
Is there a way to reference the variable in the child test, so that the child test can be used in many scripts?

The answer is Yes. All you need to do is to declare the "Email" variable in the Child test instead of the Parent and then call Child.Email = "test@test.com" instead of the Parent.Email = "test@test.com".

Greetings,
Nikolai
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
Garry
Top achievements
Rank 1
Answers by
Nikolai
Telerik team
Garry
Top achievements
Rank 1
Share this question
or