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.
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.
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.
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.
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.
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.