SoapUI Beginner Tutorial 8 – GROOVY Scripting in SoapUI | Getting Started
Today we will learn:
—————————–
1. What is Groovy
2. How to add groovy scripts in SoapUI
3. How to do basic coding in groovy in SoapUI
4. Basic Object Oriented Programming. (Classes and Objects)
References
https://en.wikipedia.org/wiki/Apache_Groovy
https://www.soapui.org/apidocs/com/eviware/soapui/model/testsuite/TestRunner.html
Code Snippets
=============
import java.io.*;
log.info (” Hello World … “);
int a = 10 ;
int b = 20 ;
int c = a+b ;
log.info (” Result is : “+c) ;
// this is a single line comment
/*
* This is
* multiline comment
*/
//log
//context
//testRunner
log.info testRunner.metaClass.methods*.name.unique().sort()
======================
class Hello{
def log;
def context;
def testRunner;
def Hello(log, context, testRunner){
this.log = log
this.context = context
this.testRunner = testRunner
}
def sayHello(String name){
log.info (” Hello “+name);
}
}
context.setProperty(“Hello”, new Hello(log,context,testRunner))
========================
def testStep = testRunner.testCase.getTestStepByName(“Hello”)
testStep.run(testRunner, context)
context.Hello.sayHello(“Raghav”)
============================
project = testRunner.testCase.testSuite.project ;
tcase = project.testSuites[“TestSuite3”].testCases[“TestCase1”] ;
hello = tcase.getTestStepByName(“Hello”);
hello.run(testRunner, context)
context.Hello.sayHello(“Raghav”)
project = testRunner.testCase.testSuite.project ;
tcase = project.testSuites[“TestSuite”].testCases[“TestCaseName”] ;
hello = tcase.getTestStepByName(“Hello”);
log.info testRunner.metaClass.methods*.name.unique().sort()
context.setProperty(“Hello”, new Hello(log,context,testRunner))
def hello = testRunner.testCase.getTestStepByName(“Hello”);
hello.run(testRunner, context)
def ref = context.Hello;
ref.printHello(“Raghav”);
==============================================
SoapUI Playlist –
Like on Facebook – https://www.facebook.com/automationstepbystep/
Subscribe on:
Youtube – http://youtube.com/automationstepbystep
________ ONLINE COURSES TO LEARN ________
Visit – http://automationstepbystep.com/
source
Leave us a comment Cancel reply
COMMON QUESTIONS
Categories
- Agile Coach
- ARTIFICIAL INTELLIGENCE
- Block chain
- Business Analyst BA
- DATA science
- Development
- Devops Automation
- Dotnet
- Education
- Free Job training and assistance
- Information
- Infrastructure automation
- Interview questions
- JAVA
- jobs
- Learn
- Machine learning
- Python Automation
- QA Automation
- RPA Automation
- SAP crm
- Scrum master Agile
- Skill
- UI Design
- Uncategorized
34 Comments
Automation Step by Step
May 10, 2022 21:48 pmOnline courses – https://automationstepbystep.com/
FosterSB
May 10, 2022 21:48 pmYour videos are very helpful and well organized. I like the use of notepad! When you get to the crux of a helpful point perhaps slow down a tad so that I needn't pause the video (if you're still making these years later). Thanks!
ashish naidu
May 10, 2022 21:48 pmHi Raghav, your teaching is amazing and very easy to follow and did a hands on too and it was very productive. But in this video I was unable to follow much of it, I lost it at the very beginning itself maybe due to as I have zero programming knowledge. So, can you guide and assist me how to overcome this gap. Thanks again!
Sagar Sagar
May 10, 2022 21:48 pmcontext Analogy…if i understand it correctly … once we create a class and its methods, then we call it from different class. But, here we need to define variable to the class -def testStep = testRunner.testCase.getTestStepByName("Hello"); .this is something like deciding which which fun activity to go in the amusement park. Once we decide, we need a different passes/tickets to play the different rides. these pass/tickets are "Context" testStep.run(testRunner, context); . Once we get the pass we get access to that ride/area in amusement park. Once we do enter there we can play the ride which is actual function calling activity. context.Hello.sayHello()
Lol..just trying to figure it out.confirm if this right and easy way to understand context..because context object is used in different languages as well for example dart in flutter.
F.R.I.E.N.D.S
May 10, 2022 21:48 pmThank You Raghav , It is very useful and very understanding .
LOL world
May 10, 2022 21:48 pmwhat is the purpose to write run method? Why we have pass those 2 arguments and from where they will get value?
Prashant Mainali Music
May 10, 2022 21:48 pmCan we call this class from a different project if yes then how?
Prashant Mainali
May 10, 2022 21:48 pmHey can anyone answer that is it important to name groovyStep same name as the class itself
Ash Win
May 10, 2022 21:48 pmWhat is the difference between context and TestRunner as both the usage are same??
Rijo John Patric
May 10, 2022 21:48 pmDo we have the feature for auto suggestion, what we experience in eclipse
@Raghav Pal
harsh singh
May 10, 2022 21:48 pmNot working for me
Roopashree Db
May 10, 2022 21:48 pmHi Raghav..
How to stop testcases running in infinite loop
It is not stopping..it is running continuously
vasu vasu
May 10, 2022 21:48 pmHi Raghav is groovy scripting same in readyapi and soupui tools
Puja Nagraj
May 10, 2022 21:48 pmI'm getting java.lang.NullPointerException:Cannot invoke method sathi() on null object
Minu Ahamed
May 10, 2022 21:48 pmHi Raghav, I have one query.In the 'CallHello' test step , why did you write testStep.run(testRunner,Context) ? I could not understand the need for that line of code.
Thanks,
Minu
Balpreet Singh
May 10, 2022 21:48 pmI got confused by listening "Hello" multiple times.
Yatishankar Bandyopadhaya
May 10, 2022 21:48 pmI strongly believe complete newbies like me find it very difficult to understand why are we starting with groovy in the first place. so far i had understood loading the WSDls, end point URLs, sending the request, getting a valid response, creating a test suite>test case>test step. From a practical standpoint it would be helpful for me to know why do i need to learn groovy after this. In my project on webservice testing i didnt need it. So if you could start with a basic intro as to why do we need groovy here will be helpful
UHS Bangalore
May 10, 2022 21:48 pmWe have implemented this groovy explained in the video, its a big success for the project. Thank you!
Jyothirmai Siva Ram
May 10, 2022 21:48 pmHi Raghav,
Very well explained. Can you please provide syntax too? Example: to call a class that is defined in another test case. tcase=project.teststeps("").testcases("");
kambala vinodkumar
May 10, 2022 21:48 pmHello Raghav, I have written this code to execute the case, but getting null pointer exception error at statement number 4.
project = testRunner.testCase.testSuite.project ;
tcase = project.testSuites["TestSuite3"].testCases["TestCase2"] ;
tstep = tcase.getTestStepByName("GetCountryISOCode");
def status = tstep.run(testRunner, context)
def result = status.getStatus().toString();
log.info (" >>>> "+result)
Phil B
May 10, 2022 21:48 pmThanks again for your great course.
Is it possible to run a Selenium script using a Groovy step in a SoapUI test case? Do you go into that later in your video series? At work we have a step that needs to be carried out from a screen interface because there is no WSDL for it.
Also, I have a specific question about something I want to do on a project for my job. Would you consider doing a one-to-one session with me? I don't think it would take very long.
Prabhat Adhikary
May 10, 2022 21:48 pmHi Raghav, You are an awesome teacher. As a student, the only thing that makes us more clear is if you give a meaningful name to a particular test case or test suit or for any method you are using will help us to understand in the best way. I am getting too much confused on name like test suit 1, test case 2, and so on. sorry about that. Else Everything is perfect.
Nagendran prakash rao
May 10, 2022 21:48 pmThank you Raghav, that was very useful. I've connected to the DB successfully through JDBC request and successfully retrieve the records using SQl queries.. How can I compare the response values against the DB returned values using Groovy script? Can you advise please?
Sana Sayed
May 10, 2022 21:48 pmGood explanation sir of every topic…keep it up
Mayank Jain
May 10, 2022 21:48 pmNicely explained about groovy scripting thanks a lot!!!
Mahmoud Omar
May 10, 2022 21:48 pmHello, Ragav Thanks for the brilliant presentation But testStep.run(testRunner, context) not defined into hello class
István Máté
May 10, 2022 21:48 pmRaghav very thank you for all these tutorials and that you give us for free! You are the best! I also have a youtube channel where I explain different things. You are my role model. I'd like to have a question, I have written a groovy script where I read data from excel and I'd like to do that my only test case loops through the rows that are in excel. So one row in excel stores all the data for one test case and each line means a different test case, but the test case form (all the request, etc) are the same.
Or in other words, I have only one test case which contains all the necessary things. It has a groovy script which reads the rows from excel and every row means a complete run of the test case.
p.s. I have a soapUI project where I have setup scripts which contain a class but it doesnt contain these variables that you say the class should contain.
Another question which I'd like to have at the end of the video, what is the reason of these method invocations order: project = testRunner.testCase.testSuite.project ?
shivaji288
May 10, 2022 21:48 pmHi I am getting while executing callHello groovy script java.lang.NullPointerException: cannot invoke menthod info () on null object line number 5 .
Abhishek Sharma
May 10, 2022 21:48 pmHello Sir, Thankyou for such great informational videos . Always follow your videos. Also please can you once upload a token handling video for Jmeter. Actually i am trying to handle dynamic tokens in Jmeter and not getting the exact results with regular expressions. I will be very thankful in case you can help me out that Groovy scripting in J meter as well.
Kamal
May 10, 2022 21:48 pmI like the way you explain things
thanks
Vipin Tekade
May 10, 2022 21:48 pm@Automation Step by Step
project =testRunner.testCase.testSuite.project;
tcase = project.testSuites("TestSuite3").testCases("TestCaseName1");
hello = tcase.getTestStepByName("Hello");
hello.run(testRunner, context)
context.Hello.sayHello("Vipin")
For this Program i didn't got the proper output ;
groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.WsdlProject.testSuites() is applicable for argument types: (java.lang.String) values: [TestSuite3] Possible solutions: getTestSuites() error at line: 2
VIPIN TEKADE
May 10, 2022 21:48 pmHi Ragav
project =testRunner.testCase.testSuite.project;
tcase = project.testSuites("TestSuite3").testCases("TestCaseName1");
hello = tcase.getTestStepByName("Hello");
hello.run(testRunner, context)
context.Hello.sayHello("Vipin")
Output : got this below error please help .
groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.WsdlProject.testSuites() is applicable for argument types: (java.lang.String) values: [TestSuite3] Possible solutions: getTestSuites() error at line: 2
Pragati Shukla
May 10, 2022 21:48 pmThanks for the wonderful video. Please let me know how to run more than on e test steps or test cases using single statement
Ramzi Jelassi
May 10, 2022 21:48 pmThanks for the video