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

Passing a Variable from a Web Test to an API Test

3 Answers 116 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kris
Top achievements
Rank 1
Kris asked on 26 Nov 2019, 06:03 PM

Part of our software uses a lot of API calls. I have tests build for these API calls to test them in the API side of Telerik. I have a Web project built for testing the UI side of things and I have web tests built that import API tests as a step so that I can include my API tests in test lists and have them run on a normal schedule. What I am needing to do is run my API tests against multiple environments. I have done this in the past just by duplicating the API tests and the web tests to have a test for each environment. As you can imagine this makes it a bit of a pain to maintain the tests. 

I already have variables set in the API tests that I am using. What I would like to do is be able to pass a variable for baseURL, Username and Password from the web test to the API test. Is this possible? If so what is the best way to go about it? I read on this link https://docs.telerik.com/teststudio/knowledge-base/test-execution-kb/run-api-test-in-web-test#advanced-passing-a-variable-from-an-api-test-to-a-web-test about passing a variable from the API test back to a web test by basically writing the variable in the Variables folder then pulling that from the web test. Can I do that just in reverse, Write the variable from the web test for the API test to use? Is that my only option? I would love to hear any and all of your thoughts!! Thanks!!

3 Answers, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 27 Nov 2019, 11:09 AM

Hi Kris,

Thank you for sharing details about the test scenario that you want to automate.

I am happy to tell you that you can pass multiple variables to the embedded API Test as Step. You can find the Variables option in the test step properties and follow the instructions to add the needed variables. They will be set as a project level variables in the API project.

I hope that the above information will help you with the scenario at hand. Please do not hesitate to contact us again, if you need further assistance.

Regards,
Plamen Mitrev
Progress Telerik

 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Kris
Top achievements
Rank 1
answered on 18 Dec 2019, 08:31 PM
Thanks for the reply, I am just getting back to working on this again. Your option does help, but is there a way to pass the variable from a Test List to the web test to the API test? Essentially I have an API test I need to run on multiple environments and want them to run on a set schedule. Each environment has a different URL and User/Pass 

Ideally I would be able to just add the API test directly to a test list itself, then be able to set variables to pass to the tests (Base_URL, User, Pass, etc...). I don't think that is possible though. I know there is the option for the base URL under the list settings but I do not see an option for any other variables. So as Telerik works today do I have to create a web test for each API in each environment, Set the environment variables in the web test properties, then add those web tests to the test lists I want to schedule? Is there any other options?
0
Plamen Mitrev
Telerik team
answered on 19 Dec 2019, 03:00 PM

Hello Kris,

I am glad to know that the existing feature helps you automate the test scenario.

Thank you for sharing more details on the test case. I will to my best to advise you and help you with that.

The API test must be part of a Web test and you can then add it to a test list. It is not possible to add an API test like it is in the test list. This means that you can pass some variables to that API test, as I suggested in my previous reply.

You can set your own variables in a coded step and the pass them to the API test step in the same test. You can set any variable like the baseURL, password and username. You can get some of those variables from the Settings, or read them from external file for example. Please check the sample code below, which sets the baseUrl from the settings to a new variable "urlBase".

SetExtractedValue("urlBase", this.Manager.Settings.Web.BaseUrl);

I hope that the above suggestion will help you run the same set of tests against different environments by creating or changing some variables in a coded step.

Please do not hesitate to contact us again, if you need further assistance, or any questions arise.

Regards,
Plamen Mitrev
Progress Telerik

 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Kris
Top achievements
Rank 1
Answers by
Plamen Mitrev
Telerik team
Kris
Top achievements
Rank 1
Share this question
or