Ask a Question

Reusing a block of code

macheshmeh
Occasional Contributor

Reusing a block of code

a block of code is repeated in some of my tests , i want to create a class or function and call them to different tests instead of repeat the code each time , i know with keyword test we have the possibility the create data driven loop 

can we create data driven loop in script also ?

or there is another way to call this part of test?

 

thanks for your help

3 REPLIES 3
Kitt
Regular Contributor

like this?

function bigFunction() {
  // do a lot of stuff
  // do a lot of stuff
  // do a lot of stuff
  // do a lot of stuff
  // do a lot of stuff
  // do a lot of stuff
}

function test1() {
  bigFunction();
}

function test2() {
  bigFunction();
}

function test3() {
 bigFunction();
}
...

I'm not entirely sure what you are trying to accomplish - extracting data for your tests or running blocks of code, but I would suggest reviewing the DDT docs [here] 

[[ kITt: keep IT testing ]]
Marsha_R
Community Hero

If you know how to do what you want in a keyword test, the easiest thing to do is create the keyword test and then use the Convert To Script function. The script may need a little adjustment but I think it is easier this way than starting from nothing.

https://support.smartbear.com/testcomplete/docs/keyword-testing/converting-script.html


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
rraghvani
Valued Contributor

If you find yourself starting to implement the same functions, then it's probably best to create a separate project which has all your functions, which can then be called from other projects

 

For example,

rraghvani_0-1670576770495.png

 

cancel
Showing results for 
Search instead for 
Did you mean: