Ask a Question

Is it possible to use contents from a file within setup/teardown

SOLVED
shaijujanardhan
Occasional Contributor

Is it possible to use contents from a file within setup/teardown

I have a testsuite where I need to do a setup and teardown for each of the testcases. Currently I have the same code copy pasted in all the tests. But from a maintenance point of view this is not scalable. Is there a way I can load contents of an external groovy script from disk and then use it within setup or teardown?

shaijujanardhanan
1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: Is it possible to use contents from a file within setup/teardown

Possible.
Another way is to use events, however, need to see what the script is doing as certain objects might or might not be available in that context. Would you please show what the scripts are doing?

Please take a look at the events page, "List of events"
https://support.smartbear.com/readyapi/docs/testing/handling-events.html


Regards,
Rao.

View solution in original post

10 REPLIES 10
nmrao
Community Hero

Re: Is it possible to use contents from a file within setup/teardown

Possible.
Another way is to use events, however, need to see what the script is doing as certain objects might or might not be available in that context. Would you please show what the scripts are doing?

Please take a look at the events page, "List of events"
https://support.smartbear.com/readyapi/docs/testing/handling-events.html


Regards,
Rao.

View solution in original post

shaijujanardhan
Occasional Contributor

Re: Is it possible to use contents from a file within setup/teardown

Hi @nmrao ,

 

I am trying to do auto reporting to Xray as when tests get executed. So before the test runs I add them to an execution as shown below

 

def execution_id = testCase.testSuite.project.getPropertyValue( "execution_id" )
def test_id = testCase.getLabel().split('_')[0]
ProcessBuilder pb = new ProcessBuilder("batch script to invoke xray api")
Process process = pb.start()
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()))
def serr = null
while ((serr = stdError.readLine()) != null) {
log.info(serr)
}

Thanks for pointing me to the events page. But I also would like to know how to load external files within setup/teardown 

 

shaijujanardhanan
nmrao
Community Hero

Re: Is it possible to use contents from a file within setup/teardown

If it is event then you will need to copy the script only once.


Regards,
Rao.
nmrao
Community Hero

Re: Is it possible to use contents from a file within setup/teardown

There is api to set to setup and teardown scripts. Even this you might need ony once if the tests are ready.


Regards,
Rao.
shaijujanardhan
Occasional Contributor

Re: Is it possible to use contents from a file within setup/teardown

Hi @nmrao ,

 

Using the events did the job for me. But I would still like an option where I can source external files from within the setup/teardown section. Is that possible?

shaijujanardhanan
nmrao
Community Hero

Re: Is it possible to use contents from a file within setup/teardown

Of course. It is possible.
Like I said already, need to write a utility to do so using API


Regards,
Rao.
shaijujanardhan
Occasional Contributor

Re: Is it possible to use contents from a file within setup/teardown

Hi @nmrao ,

 

Thanks for the help. I understood it now. I can write scripts within ReadyAPI and then invoke it from setup/teardown as required. But you also mentioned some api to set setup and teardown. Can you please point me to the doc for that

shaijujanardhanan
nmrao
Community Hero

Re: Is it possible to use contents from a file within setup/teardown

shaijujanardhan
Occasional Contributor

Re: Is it possible to use contents from a file within setup/teardown

Hi @nmrao 

Thanks for your help

shaijujanardhanan
cancel
Showing results for 
Search instead for 
Did you mean: