How can I change data bound to a test step during test execution?

1 Answer 97 Views
Coded Steps General Discussions Test Configuration Test Execution
Daniel
Top achievements
Rank 1
Iron
Iron
Daniel asked on 14 Jan 2022, 07:25 PM

I'm currently unsure how to go about this. Take for instance this simplified version of the issue as shown in this series of tests as steps.

1. Log in as user A

2. Perform actions Q,R,S

3. Log out of user A's profile

4. Log in as user B

5. Perform actions T,U,V

6. Log out of user B's profile.

Currently, I don't have a way to let the application know that the second time the "Log in" test runs, it's supposed to use a different bit of data. If I have two rows of data for that test. It simply runs the entire list of tests (from 1-6) for each row. But I'd like for it to run only once, but using different data for each Log in.

Any assistance is greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 18 Jan 2022, 09:38 AM

Hello Daniel,

I analyzed the scenario that you want to automate and prepared sample tests against publicly accessible application. Please explore the attached tests and the details below.

One of the options is to data bind actions Q,R,S to work as actions T,U,V in the second iteration and only have steps for login (A) and one set of data driven actions (Q,R,S) - see test LoginDifferentUsersDataDriveAll. However, this might not be possible and my other suggestion is to use a condition, based on the logged in user. For example, if the logged in user is from the first iteration, the test will execute all steps in the If block. Otherwise, it will execute the steps in the Else block. This is showcased in test LoginDifferentUsersConditional.

I hope the above suggestions and sample tests will be helpful to you for this specific automation. Of course, I remain available to continue our discussion, if you need further assistance.

Regards,
Plamen Mitrev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Test Studio course! Check it out at https://learn.telerik.com/.
Daniel
Top achievements
Rank 1
Iron
Iron
commented on 18 Jan 2022, 06:28 PM

Hello, I think maybe I was a bit unclear in my question. steps 1-6 above would be carried out in a single iteration ideally. with the log in step, being a test as a step. So the question is really if after running the first Log in test, in the same iteration of steps 1-6 if it was possible (through code even)  to change the data bound to the log in step?
Plamen Mitrev
Telerik team
commented on 19 Jan 2022, 11:59 AM

Hi Daniel, thank you for the additional information. In this case, you can change the data from the current iteration in a coded step right before the second login. I prepared a sample test with coded step, which changes the local data of the iteration, so it uses the new values. Please explore the code and local data of the attached test.

For your scenario, I assume that the coded step should be placed before the second login test as step. You can give it a try and let me know if this helped you automate this scenario.

Daniel
Top achievements
Rank 1
Iron
Iron
commented on 20 Jan 2022, 07:25 PM

Hello, this logic would solve the problem i'm having. However when i try to integrate it into my solution i'm getting this error.

error CS0012: The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
15:21:50 'INFO' > Build Failed

any ideas on what would be causing this/ how i can fix it?

 

Plamen Mitrev
Telerik team
commented on 21 Jan 2022, 09:15 AM

Hello Daniel, the compilation error says that your project is missing reference to assembly System.Xml and probably System.Data. You need to reference them in your Test Studio project, so they can be used by the coded step. You can follow the instructions to do that in this article.

In my sample test's coded step, I declared System.Xml and System.Data assemblies with the "using" keyword and added references to them in my project. Your project should compile after you add a reference to the required assemblies. Let me know if you encounter any troubles. 

Daniel
Top achievements
Rank 1
Iron
Iron
commented on 21 Jan 2022, 11:57 AM

Hey Plamen, noted and i will try. One quick follow up question. Do you think this would work if all the steps in the iteration were tests as steps?
Plamen Mitrev
Telerik team
commented on 24 Jan 2022, 09:01 AM

Hi Daniel, it should work if the steps are test as steps as long as they have the correct data source. Either the test as steps should be data driven or inherit the parent test's data. Based on the tests as step and the overall scenario, you need to decide where to put the coded step that updates the data of the current iteration. I assume that it would be better to place it in the main test, outside of the login test as step, according to the information about your scenario.

Let me know if the suggestions worked and whether you need further assistance on the topic. I will be more than happy to help!

Daniel
Top achievements
Rank 1
Iron
Iron
commented on 21 Feb 2022, 02:37 PM

Hello Plamen, the suggestions work. I just realised there was an oversight in my thinking about what I needed my test to accomplish. Is there a way (through code) to write a value into local data? I know I can use the Data["column"] to read information, but was hoping there is a way that I can write to the local data source. Any assistance will be appreciated. Thank you!
Elena
Telerik team
commented on 21 Feb 2022, 03:45 PM

Hi Daniel, 

You can use a coded step and write into data source, if this is an external source - here is an example for an Excel file

An alternative of this could be to use the extracted variables in code. Here you can read the general concept for extracting some value from the page and store it into variable. For more complicated scenarios these variables can be used in coded steps to change their value following some requirements. Then, these new values can be used back in the test through the step bindings (there is a sample project, which demonstrates a complete scenario for this). 

I hope these possible options will be of further help for you to setup the automation tests. Let us know in case you have further questions .

Regards,
Elena

Daniel
Top achievements
Rank 1
Iron
Iron
commented on 21 Feb 2022, 03:59 PM | edited

Hello Elena, it is not for an external source, simply for the built in local data. Meanwhile, I will take a look at the other resources provided. Thank you!

 

Elena
Telerik team
commented on 22 Feb 2022, 12:17 PM

Hi Daniel, 

I am sorry for any possible misunderstanding. You cannot directly write into the built-in data of a test. The options you have is to use the extracted variables either in code, or if these values don't require modification - directly in the UI. 

If the scenario is more complex and you need to keep some info in a data source, you can switch to using an external source and write into it from a coded step. 

I hope this helps!

Regards,
Elena

Tags
Coded Steps General Discussions Test Configuration Test Execution
Asked by
Daniel
Top achievements
Rank 1
Iron
Iron
Answers by
Plamen Mitrev
Telerik team
Share this question
or