SoapUI Beginner Tutorial 8 – GROOVY Scripting in SoapUI | Getting Started

34 Comments



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

34 Comments
    • blank
      FosterSB
      May 10, 2022 21:48 pm Reply

      Your 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!

    • blank
      ashish naidu
      May 10, 2022 21:48 pm Reply

      Hi 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!

    • blank
      Sagar Sagar
      May 10, 2022 21:48 pm Reply

      context 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.

    • blank
      F.R.I.E.N.D.S
      May 10, 2022 21:48 pm Reply

      Thank You Raghav , It is very useful and very understanding .

    • blank
      LOL world
      May 10, 2022 21:48 pm Reply

      what is the purpose to write run method? Why we have pass those 2 arguments and from where they will get value?

    • blank
      Prashant Mainali Music
      May 10, 2022 21:48 pm Reply

      Can we call this class from a different project if yes then how?

    • blank
      Prashant Mainali
      May 10, 2022 21:48 pm Reply

      Hey can anyone answer that is it important to name groovyStep same name as the class itself

    • blank
      Ash Win
      May 10, 2022 21:48 pm Reply

      What is the difference between context and TestRunner as both the usage are same??

    • blank
      Rijo John Patric
      May 10, 2022 21:48 pm Reply

      Do we have the feature for auto suggestion, what we experience in eclipse
      @Raghav Pal

    • blank
      harsh singh
      May 10, 2022 21:48 pm Reply

      Not working for me

    • blank
      Roopashree Db
      May 10, 2022 21:48 pm Reply

      Hi Raghav..
      How to stop testcases running in infinite loop
      It is not stopping..it is running continuously

    • blank
      vasu vasu
      May 10, 2022 21:48 pm Reply

      Hi Raghav is groovy scripting same in readyapi and soupui tools

    • blank
      Puja Nagraj
      May 10, 2022 21:48 pm Reply

      I'm getting java.lang.NullPointerException:Cannot invoke method sathi() on null object

    • blank
      Minu Ahamed
      May 10, 2022 21:48 pm Reply

      Hi 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

    • blank
      Balpreet Singh
      May 10, 2022 21:48 pm Reply

      I got confused by listening "Hello" multiple times.

    • blank
      Yatishankar Bandyopadhaya
      May 10, 2022 21:48 pm Reply

      I 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

    • blank
      UHS Bangalore
      May 10, 2022 21:48 pm Reply

      We have implemented this groovy explained in the video, its a big success for the project. Thank you!

    • blank
      Jyothirmai Siva Ram
      May 10, 2022 21:48 pm Reply

      Hi 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("");

    • blank
      kambala vinodkumar
      May 10, 2022 21:48 pm Reply

      Hello 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)

    • blank
      Phil B
      May 10, 2022 21:48 pm Reply

      Thanks 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.

    • blank
      Prabhat Adhikary
      May 10, 2022 21:48 pm Reply

      Hi 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.

    • blank
      Nagendran prakash rao
      May 10, 2022 21:48 pm Reply

      Thank 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?

    • blank
      Sana Sayed
      May 10, 2022 21:48 pm Reply

      Good explanation sir of every topic…keep it up

    • blank
      Mayank Jain
      May 10, 2022 21:48 pm Reply

      Nicely explained about groovy scripting thanks a lot!!!

    • blank
      Mahmoud Omar
      May 10, 2022 21:48 pm Reply

      Hello, Ragav Thanks for the brilliant presentation But testStep.run(testRunner, context) not defined into hello class

    • blank
      István Máté
      May 10, 2022 21:48 pm Reply

      Raghav 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 ?

    • blank
      shivaji288
      May 10, 2022 21:48 pm Reply

      Hi I am getting while executing callHello groovy script java.lang.NullPointerException: cannot invoke menthod info () on null object line number 5 .

    • blank
      Abhishek Sharma
      May 10, 2022 21:48 pm Reply

      Hello 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.

    • blank
      Kamal
      May 10, 2022 21:48 pm Reply

      I like the way you explain things
      thanks

    • blank
      Vipin Tekade
      May 10, 2022 21:48 pm Reply

      @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

    • blank
      VIPIN TEKADE
      May 10, 2022 21:48 pm Reply

      Hi 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

    • blank
      Pragati Shukla
      May 10, 2022 21:48 pm Reply

      Thanks for the wonderful video. Please let me know how to run more than on e test steps or test cases using single statement

    • blank
      Ramzi Jelassi
      May 10, 2022 21:48 pm Reply

      Thanks for the video

Leave us a comment