Dynamic Values passing between test steps in Test Studio

Recently I was talking to a customer. He discussed a simple but important problem with me on test automation using Test Studio. He had a requirement to use values of variables from one test step in another test step.

To understand this problem in better way, consider below web application which is inserting data in database.

clip_image001

Let us try to understand this problem bit further. Suppose you have 6 test steps in test. In step2 user is typing UserName to be inserted.

clip_image003

To verify successful insertion of UserName in database, you need to do follow steps,

  • Read UserName inserted by user from step 2
  • Reading of username is done in step 4. So here you are reading value from step 2 in step4.
  • Use read value of step 4 to verify insertion in database.

In this post we are going to see how we can read variables value from one step in another step. In this case from step 2 to step 4 and then in step 6.

To use variable from one step in another you need Coded step. To add coded step select Test from menu and then Script Step from ribbon. In Visual Studio extension Coded Step can be added by clicking Add then selecting Coded Step.

clip_image001[6]

If you notice test steps in we have taken in example there are two test steps (step 4 and step 6) are coded steps. In step 4 we are reading user inserted value as below and assigning that to a public global variable.

clip_image003[6]

In step 4 (coded step) we read value from step 2 or in other words value from DOM element in which value got assigned in step 2. Now we need to read global variable value in step 6.

clip_image005

In this way very easily you can read variable values from one step in another step in a test project. I hope this post will help you. Thanks for reading.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s