Ask a Question

How to access a variable outside a method in groovy ?

SOLVED
nmrao
Community Hero

Re: How to acces a varibale outside a method in groovy ?

We dont have visibility of the context. So, can't understand below statement.

But when i call from another class from another testsuite it says it cannot find expected_value.


Regards,
Rao.
_ivanovich_
Frequent Contributor

Re: How to acces a varibale outside a method in groovy ?

@nmrao 

please check image.

i tried to explain.

nmrao
Community Hero

Re: How to acces a varibale outside a method in groovy ?

Had a feeling the usage is not correct. If you want to re-use some code, then you have to use script library.
For more details, please refer below thread
https://community.smartbear.com/t5/SoapUI-Pro/Calling-custom-Groovy-script-from-Script-Assertion-in-...


Regards,
Rao.
_ivanovich_
Frequent Contributor

Re: How to acces a varibale outside a method in groovy ?

@nmrao 

Hi,

I'm using library.

the whole project is running fine with library.

I cannot post the whole part of the code for library.

but i'm invesgating...

Nastya_Khovrina
Moderator

Re: How to acces a varibale outside a method in groovy ?

Hi @_ivanovich_,

 

I've checked your screenshot and have some comments:

- you cannot write a script at one Groovy script test step, and, then, use its methods in another part of the project;

- you said that you use libraries, so that shouldn't be the case, but, inside the method, you use a test step response. To make your test_validate_name method independent, you can pass both values as parameters. 

 

Note that there is the RunTestCase test step. You can write a groovy script in this test case and run it when it's needed with different parameters. Maybe, this will help you.

sonya_m
Community Manager

Re: How to acces a varibale outside a method in groovy ?

Thank you everyone for help!

 

Hi @_ivanovich_ , please share your progress with us. Have you solved the issue?

Perhaps, Nastya's latest comment could help straighten things out a bit?


Sonya Mihaljova
Community and Education Specialist

HimanshuTayal
Community Hero

Re: How to acces a varibale outside a method in groovy ?

I think this screenshot makes me clear of your problem....please refer attached dummy project hope it will solve your problem..it explains 2 parts:

 

1) calling groovy script from same Test case

2) calling groovy script from diffrent Test Suite

 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
HimanshuTayal
Community Hero

Re: How to acces a varibale outside a method in groovy ?

@_ivanovich_  have you got any time to check the xml file which i have shared, hope it will resolve your issue, eager to know the result.... 🙂

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
_ivanovich_
Frequent Contributor

Re: How to acces a varibale outside a method in groovy ?

@HimanshuTayal 

Hi,

no it doesn't resolve the probleme, the context is not the same.

solution is in progress....

HimanshuTayal
Community Hero

Re: How to acces a varibale outside a method in groovy ?

@_ivanovich_ :

 

Didn't get "context is not the same", can you please breif more.


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
cancel
Showing results for 
Search instead for 
Did you mean: