cancel
Showing results for 
Search instead for 
Did you mean: 

Reusable Functions Framework setup

678
Regular Contributor

Reusable Functions Framework setup

Can any one share a framework for Reusable Functions Framework setup 

 

currently i have a 

 

Project 

   Library_TestSuite

        Function1_Testcase

        Function2_Testcase

   Actual_Testsuite 

          TestCase1

          TestCase2 

 

 

I need how to call functions when ever i required on any testcase 

 

 

 

Thanks

 

9 REPLIES 9
msiadak
Community Hero

Re: Reusable Functions Framework setup

Are you meaning that Function1/Function2 are test cases that need to be re-used/re-ran in the actual later test cases? If so, there are two ways I know to handle this. One is groovy being used to run those test cases on demand.  The other is to use a "Run TestCase" test step. That might work.

It really comes down to what is actually in those Function test cases and what they do, and if they rely on input from the Actual test cases. If that's the case, this'll be more complex.




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
678
Regular Contributor

Re: Reusable Functions Framework setup

Function 1 :  a groovy script to gerenerate randomstringuserid

 

import java.util.Random;

Random rand = new Random();
int num = rand.nextInt(9000) + 9999;

userid = "test"+num

context.testRunner.testSuite.setPropertyValue("randomuser", userid)

 

 

 

Function 2 : a groovy script to generate randomalphanumericpassword

 

import java.util.Random;

Random rand = new Random();
int num = rand.nextInt(9000) + 9999;

pw = "test"+num

context.testRunner.testSuite.setPropertyValue("randompassword", pw)

 

 

Stored these groovy scripts under as Testcases under Library Testsuite 

 

 

 

sanj
Super Contributor

Re: Reusable Functions Framework setup

So for TC you are referencing these groovy scripts?

 

msiadak
Community Hero

Re: Reusable Functions Framework setup

If those are what you need to access, you should be able to use a RunTestCase test step to access these. They will store the properties you are expecting relative to their location, though. 

Alternatively, you can do an INLINE groovy script, too, but it might be unwieldy if you have to use it in multiple places. 

 

Did you figure it out with what you posted, or are you still trying to figure it out?




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
678
Regular Contributor

Re: Reusable Functions Framework setup

i cannot use as Run Test Case as i am using this functions as i want to use this functions/piece of groovy in some other groovy script 

msiadak
Community Hero

Re: Reusable Functions Framework setup

I think I understand what you want now. You want to have a function defined at the Library Test Case level, and you want to basically have that be a part of later groovy scripts without having to copy/paste the code.

 

Unfortunately I do not think this will work as you want, but you may be able to set up an external groovy script library that might. There's some documentation here: https://support.smartbear.com/readyapi/docs/testing/scripts/library.html




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
678
Regular Contributor

Re: Reusable Functions Framework setup

yes, i am looking some thing like this but i tried this solution but it didn't worked for me as 

 

i want to use function defined library test case in events 

msiadak
Community Hero

Re: Reusable Functions Framework setup

nfortunately I am pretty sure that will not work the way you want. You would either need to use the external script library or copy the functions as needed to other groovy scripts. 

 

Alternatively, you could write the "Function" groovy script in such a way that it returns the expected result instead of just being a function. From there, you might be able to call that groovy script from another and use the response it returns. 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
sanj
Super Contributor

Re: Reusable Functions Framework setup

I think of as setup just have grovy libraries and call it as required.

Here are some examples

https://www.soapui.org/scripting-properties/tips-tricks.html

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors