SoapUI Beginner Tutorial 6 - How to Get and Set Properties through GROOVY scripts

Sdílet
Vložit
  • čas přidán 4. 09. 2024
  • website - automationstep...
    Today we will learn:
    1. How to get property
    2. How to set property
    3. How to add property
    4. How to remove property
    5. How to loop through all properties
    References
    www.soapui.org...
    Notes
    // Get and Set Property
    //Project
    testRunner.testCase.testSuite.project.getPropertyValue("Name")
    testRunner.testCase.testSuite.project.setPropertyValue("Name","I am in Project")
    //TestSuite
    testRunner.testCase.testSuite.getPropertyValue("Name")
    testRunner.testCase.testSuite.setPropertyValue("Name","I am in TestSuite")
    //TestCase
    testRunner.testCase.getPropertyValue("Name")
    testRunner.testCase.setPropertyValue("Name","I am in TestCase")
    //TestStep
    testRunner.testCase.getTestStepByName("CountryCodes").getPropertyValue("Name")
    testRunner.testCase.getTestStepByName("CountryCodes").setPropertyValue("Name","I am in Test Step")
    //Global
    com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "Name")
    com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "Name","I am in Global Prop" )
    // Add Property
    testRunner.testCase.testSuite.project.addProperty("DOB")
    // Remove property
    //Project
    testRunner.testCase.testSuite.project.removeProperty("Name");
    //TestSuite
    testRunner.testCase.testSuite.removeProperty("Name")
    // Loop through properties
    testRunner.testCase.properties.each
    {
    key,value -
    log.info (testRunner.testCase.getPropertyValue(key))
    //log.info (key+" - "+value)
    }
    _______________________________________________________
    SoapUI Playlist -
    • SoapUI
    Like on Facebook - / automationstepbystep
    Subscribe on:
    CZcams - / automationstepbystep
    _______ ONLINE COURSES TO LEARN _______
    Visit - automationstepb...

Komentáře • 112

  • @mihalykelemen8053
    @mihalykelemen8053 Před 4 lety +10

    Hi Raghav,
    I'm Michael from Hungary. I will start as a junior automation tester in October and your videos are quite useful, so thank you very much. I have the intention to watch all of your videos. Your explanations are so clear and understandable. You are an excellent teacher. Thanks again.

    • @RaghavPal
      @RaghavPal  Před 4 lety +1

      Best of luck Mihály You can check all here - automationstepbystep.com/

  • @testingtrail
    @testingtrail Před 6 lety +9

    I really like the way you create a slide at the end with the overview and some tips, great!!

  • @jeremyhogan8614
    @jeremyhogan8614 Před 5 lety +3

    Very good Raghav, thanks for these tutorials

  • @sharatchandra2045
    @sharatchandra2045 Před 3 lety +1

    Exceleentway of teaching- to the point i would say. thanks

  • @performancetestengineer-go2294

    Excellent groovyscripting 100% use video Please do more videos iam waiting for your videos really great job

    • @RaghavPal
      @RaghavPal  Před 6 lety +1

      Great to know this Gowri. Keep watching.

  • @spritithakur4637
    @spritithakur4637 Před rokem

    Thanks alot for your guidance

  • @rakhirahman4069
    @rakhirahman4069 Před 6 lety +1

    Excellent work.Thak you for amazing work

    • @RaghavPal
      @RaghavPal  Před 6 lety

      Thanks for your comment Rakhi

  • @riteshkumar6403
    @riteshkumar6403 Před 6 lety +1

    Very informative video.

  • @goranmarinkovic9143
    @goranmarinkovic9143 Před 5 lety

    Very effective presentation

  • @munaversherif6613
    @munaversherif6613 Před 5 lety

    Great info on groovy scripting

  • @mayankjain9941
    @mayankjain9941 Před 4 lety +1

    Nice explanation thank you!! Do we need to preinstall Groovy script in our machine to follow this session?

    • @RaghavPal
      @RaghavPal  Před 4 lety +1

      No as long as you are working inside SoapUI

    • @mayankjain9941
      @mayankjain9941 Před 4 lety +1

      @@RaghavPal Thank for your reply.

  • @krishnadasari9863
    @krishnadasari9863 Před 5 lety +1

    Hi Raghav ,
    Very informative and helpful videos, can we create library class using groovy script ?
    can you please create videos for ServiceV groovy scripts how to handle endpoints communication with client applications

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Hi Krishan, I will do these topics

  • @niazmaksud1139
    @niazmaksud1139 Před 5 lety +2

    Hi,
    Excellent video. Just had a question - so getPropertyValue and context.expand is doing the same thing right? Both are used to fetch property values?

    • @RaghavPal
      @RaghavPal  Před 5 lety +1

      Hi Niaz, context is actually a placeholder. In this case you can say they are doing the same thing.

  • @chanushakaushal4300
    @chanushakaushal4300 Před 6 lety

    Excellent

  • @bhupendersingh8289
    @bhupendersingh8289 Před 5 lety +1

    Hi Raghav,
    Its nice video but some confusion in it .
    in your previous video you described to get the property value by Context class and in this video you get the property by testRunner class . can you tell me what is the difference between it and when we used these classes .
    And also let me know how i learn groovy upto soap level please refer material.
    Thanks .

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Hi Bhupender, sorry for the confusion, This will help you -
      stackoverflow.com/questions/25184307/what-t-is-the-difference-between-context-and-testrunner-in-soapui
      community.smartbear.com/t5/SoapUI-Open-Source/testRunner-Context-Object-in-groovy-script/td-p/34009
      There are some sublinks in the above page that will be useful

  • @girijaramanand7586
    @girijaramanand7586 Před 5 lety +1

    Very informative sessions. I would like to know if there is a option to extract execution report with the Test case title and result as Pass /Fail from Soap UI. If yes, can the execution report be exported to excel document

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Hi Girija, you can check the default reports generated. In case you need something customized can do that with groovy scripting
      www.soapui.org/reporting/reference/reporting-tab.html
      community.smartbear.com/t5/SoapUI-Open-Source/how-to-generate-report-in-SoapUI-5-3-0-free-version-i-am-looking/td-p/147608

  • @SerialWaffleStomper
    @SerialWaffleStomper Před 5 lety

    Dude, You're absolutely the best. I was loosing my mind looking for an answer and then I saw Your video. Totally saved my ass, thanks

  • @devarajr304
    @devarajr304 Před 2 lety +1

    How to get the value from request and pass it to the response.

    • @RaghavPal
      @RaghavPal  Před 2 lety

      Hi Devraj, I believe I have covered this in one of the videos in SoapUI playlist, and its related to property transfer

  • @latasingh7599
    @latasingh7599 Před 6 lety +1

    hi...could u please help me in setnodevalue and getnodevalue functions, as I am unable to pass values in request through groovy. so any demo script u can provide will be helpful. and also ur way of teaching is awesome, can grasp things quickly.

    • @RaghavPal
      @RaghavPal  Před 6 lety

      Hi Lata thanks for watching. What is the error its showing. Pls send me logs.

  • @maheshtaninki1693
    @maheshtaninki1693 Před 4 lety +1

    Without giving input request manually can we give as pick it from specific location

    • @RaghavPal
      @RaghavPal  Před 4 lety

      Hi Mahesh, yes you can use requests from external files. Can check some examples online

    • @maheshtaninki1693
      @maheshtaninki1693 Před 4 lety

      @@RaghavPal I can't able to find can you please help me my number is 9059342222

  • @ashishnaidu2487
    @ashishnaidu2487 Před 2 lety

    Hi Raghav, can you please share what is the syntax to 'Add a property' and 'Remove a property' and 'Loop through properties' at a Test Step level?

  • @krishnayadlapalli7972
    @krishnayadlapalli7972 Před 5 lety

    Raghav these 22 vedios are enough for handle Project in real time? or we need learn more about SoapUI to handle Realtime Project?

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Hi Krishna, these will be enough to get started with any enterprise project and this will lay the foundation. After this, with this knowledge base, you can explore more as per the project requirements. I created this course after my experience of creating a project for enterprise api automation testing with soapui free ver.

  • @abhijeetsingh089
    @abhijeetsingh089 Před rokem

    Raghav,
    Can you please make a video on attaching any png or jpg file in a SOAP UI TOOL

    • @RaghavPal
      @RaghavPal  Před rokem

      I will check and plan Abhijeet

  • @vaibhavchavan7361
    @vaibhavchavan7361 Před rokem

    Hi Raghav, I am able to get the property using context but getting error whenever I try to get the property with testRunner. The error is: "No such property. TestRunner for class: Script1". Any idea how to resolve this?

    • @RaghavPal
      @RaghavPal  Před rokem

      Hi Vaibhav,
      The error message "No such property. TestRunner for class: Script1" indicates that the TestRunner object is not recognized by the script. This can happen if the script is not executed in the context of a test case or if the TestRunner object is not imported correctly.
      To access the TestRunner object in a Groovy script in SoapUI, you need to make sure that the script is executed in the context of a test case. This means that the script should be associated with a test step or a test case in SoapUI.
      Here's an example of how you can access the TestRunner object in a Groovy script in SoapUI:
      // Import the TestRunner class
      import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
      // Get a reference to the TestRunner object
      WsdlTestCaseRunner testRunner = context.testCase.testSuite.project.testSuites["TestSuite 1"].testCases["TestCase 1"].run(new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(), false)
      // Get the value of a property using TestRunner
      def propertyValue = testRunner.testCase.testSuite.getPropertyValue("property_name")
      In the above example, we have imported the WsdlTestCaseRunner class, which is a subclass of TestRunner. We then get a reference to the TestRunner object using the run method of the WsdlTestCaseRunner class. Finally, we get the value of a property using the getPropertyValue method of the TestRunner object.
      Make sure that you replace "TestSuite 1" and "TestCase 1" with the actual names of your test suite and test case. You should also replace "property_name" with the name of the property that you want to get.

  • @vipintekade3750
    @vipintekade3750 Před 4 lety

    Hi Raghav , I didn't get tthe output for global Property
    log.info "Virtusa consulting services pvt ltd"
    def name6=context.expand('${#Global#Name}')
    log.info("Company name is : "+name6);
    Even if i give the value to the name global property through preferences .
    output:
    Tue Nov 12 22:55:46 IST 2019:INFO:Virtusa consulting services pvt ltd
    Tue Nov 12 22:55:46 IST 2019:INFO:Company name is :

    • @RaghavPal
      @RaghavPal  Před 4 lety

      Hi Vipin, the syntax seems correct and in the output you are getting blank but no errors. Pls check in Global settings if the property Name is added and has a value and project is saved

  • @akshayaramviswanathan1721

    In final concept of printing property by loop , we are passing key as argument , why is it printing the values???

    • @akshayaramviswanathan1721
      @akshayaramviswanathan1721 Před 4 lety +1

      Okay okay , understood. but when i tried this , i am getting only Null values printed even when there are values for the key

    • @RaghavPal
      @RaghavPal  Před 4 lety

      Hi Akshayaram, make sure you have saved the project and the spelling is correct (case-sensitive) with no leading or training spaces

  • @SuperNewbie23
    @SuperNewbie23 Před 3 lety

    Hi Raghav , thanks a ton for your videos !
    i hav a property named prop1 which can take only 3 values - A,B and C.
    Is it possible that during runtime , one of 3 random values will be set for prop1 ? if this is possible , Can you please share URL of the video ? thanks in advance !

    • @RaghavPal
      @RaghavPal  Před 3 lety +1

      Hi Vighnesh, you can do, Can do this with Groovy Script

    • @SuperNewbie23
      @SuperNewbie23 Před 3 lety

      Thanks Raghav , i found it and it works as below:
      def mylist = ["A","B","C","D","E"]
      Collections.shuffle mylist
      def key= mylist.first()

  • @abhijeetsingh089
    @abhijeetsingh089 Před rokem

    Raghav,
    Can you do getproperty and setproperty for dynamic values and pass it in another request/ response like we do it with property transfer
    .
    If yes,can you guide how?

    • @RaghavPal
      @RaghavPal  Před rokem

      Hi Abhijeet,
      Yes, you can use the getProperty and setProperty methods in SoapUI to retrieve and set property values programmatically. These methods can be used to work with dynamic values and pass them between requests and responses in a similar way to property transfer.
      Here is an example of how to use getProperty and setProperty methods in SoapUI:
      In your first request, use a script step to extract a value that you want to use in another request. For example, you could extract a value from the response using a regular expression:
      def response = context.expand( '${Request 1#Response}' )
      def pattern = /(.*)/
      def matcher = (response =~ pattern)
      def value = matcher.group(1)
      Set the extracted value as a property using the setProperty method:
      context.setProperty( 'my.property', value )
      In your second request, use a script step to retrieve the property value using the getProperty method:
      def value = context.getProperty( 'my.property' )
      Use the retrieved value in your second request. For example, you could use it as a parameter in the request:
      def request = "example.com/service?param=${value}"
      Using these methods, you can pass dynamic values between requests and responses in SoapUI just like you would with property transfer.

    • @abhijeetsingh089
      @abhijeetsingh089 Před rokem

      @@RaghavPal hi Raghav
      I tried the below mentioned steps to transfer dynamic values in soap ui just like property transfer using getproperty and setproperty,but unfortunately it didn't work.
      Can you please guide or make a video on how can we do it

    • @abhijeetsingh089
      @abhijeetsingh089 Před rokem

      @@RaghavPal Hi Raghav
      Please look into my below comment.
      The code that you gave didn't work.
      Can you please help me on the same or make a video on the same so that people at large would be benefited

    • @RaghavPal
      @RaghavPal  Před rokem

      I will check and try to do a video

    • @abhijeetsingh089
      @abhijeetsingh089 Před rokem

      @@RaghavPal thanks so much Raghav..
      If you can try to make the video soon,it will help me pass the show stopper of my project
      Thanks in advance

  • @dhananjaymalhotra7854
    @dhananjaymalhotra7854 Před 5 lety

    Hello Sir,
    For test suite property, I am getting null value in the output. However, I have set the value of Name property as " I am Test Suite."
    Also, when we do getpropertyvalue for test suite, how does it differentiate between test suite 1 and test suite 2 ? I have set properties for both the test suites.

    • @RaghavPal
      @RaghavPal  Před 5 lety +1

      Hi Dhananjay, pls check if there are any white spaces in your property name. Check of any spelling mistakes, case of characters.

    • @dhananjaymalhotra7854
      @dhananjaymalhotra7854 Před 5 lety

      @@RaghavPal Thank you for replying Sir. I added another property and it worked.
      I would be thankful if you could address my second query as well. I have added name property to both the Test Suites. However, when I execute getpropertyvalue, I see the value added for Test Suite 2 in the result. Why is it so?

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Pls show your code.

  • @aruns5896
    @aruns5896 Před 6 lety

    how to attach documents in SOAP UI ?Please share your videos

  • @hariprasadyadavali2524

    Hi Raghav, can't we get method names after dot operator in SoapUI as in eclipse ide. For example testRunner.testcase... Do we need to remember or what Raghav?

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Hi Hari, I believe this was introduced in ready api paid ver.

    • @hariprasadyadavali2524
      @hariprasadyadavali2524 Před 5 lety

      Hi Raghav thanks for your reply. I'm really appreciate for your work and time. You are really helping to the people by your teaching.

  • @tasueva
    @tasueva Před 5 lety

    Hi Sir, How can I set/get/add a Test Suite Property to a particular testsuite (e.x. Testsuite1 or TestSuite2)?
    Regards

    • @RaghavPal
      @RaghavPal  Před 5 lety

      Hi Mario, there is a video on that. pls check automationstepbystep.com/909-2/online-courses/

  • @nagakeerthi660
    @nagakeerthi660 Před 2 lety

    Hi Raghav,
    Could you please help me with groovy script to clone test suite from project to another

    • @RaghavPal
      @RaghavPal  Před 2 lety +1

      Hi Naga, this can help community.smartbear.com/t5/SoapUI-Open-Source-Questions/How-do-you-use-a-Groovy-script-to-clone-a-TestSuite-from-one/td-p/169552

    • @nagakeerthi660
      @nagakeerthi660 Před 2 lety

      Thank you for the quick response

  • @karthikeyan.ppandidurai5717

    Is there a way to send the null value in the string?

    • @RaghavPal
      @RaghavPal  Před 6 lety

      Where exactly you need to send null. Ideally if you keep it empty, it will be null

    • @karthikeyan.ppandidurai5717
      @karthikeyan.ppandidurai5717 Před 6 lety

      SOAPUi Request XML
      ...

      I want this value to go to the SAOP endpoint/ code as null(object). When I leave this empty it goes to the code as empty string.
      C# code
      [webmethod]
      public bool foo(string a, string b string c)
      Expecting this
      if(string c == null) do something.
      receiving this
      if(string c == string.empty) this is what I get now.
      Thank you, Raghav. The video series is really awesome and helpful.
      Automation Step by Step - Raghav Pal

    • @RaghavPal
      @RaghavPal  Před 6 lety

      Did you try using nil="true" in the request tag, like here . - blog.ginzburgconsulting.com/null-values-in-soap-requests/

  • @sjeeten
    @sjeeten Před 4 lety

    Hi Raghav! Loop code is not working for me. it is giving a very long error "org.codehaus.groovy.control.MultipleCompilationErrorsException". Pls suggest.

    • @RaghavPal
      @RaghavPal  Před 4 lety

      Hi Jeetendra, will need to check more details, Pls check if you find Caused By section in the logs

    • @sjeeten
      @sjeeten Před 4 lety

      @@RaghavPal sure, thank you

  • @vipintekade3750
    @vipintekade3750 Před 4 lety +1

    def testStepProp = testRunner.testCase.getTestStepByName("CountryCodes").getPropertyValue("Name")
    log.info("Test Step Property = "+testStepProp)
    Got the output as Null Pointer
    .

    • @RaghavPal
      @RaghavPal  Před 4 lety +1

      Hi Vipin, again check if you have added the property Name in the stop CountryCodes and has a value, and project is saved. It is case sensitive, Also check for any leading or trailing spaces in the name

    • @vipintekade3750
      @vipintekade3750 Před 4 lety

      @@RaghavPal
      Hi Ragahav i think it's a case sensative
      def testStepProp = testRunner.testCase.getTestStepByName("CountryCodes").getPropertyValue("Name")
      log.info("Test Step Property = "+testStepProp)

    • @RaghavPal
      @RaghavPal  Před 4 lety

      Vipin, Will have to see more details and logs to troubleshoot

    • @gergolamos161
      @gergolamos161 Před 2 lety

      Hi Ragahav I have a same issue. All properties are specified correctly.

  • @shantanutripathi4890
    @shantanutripathi4890 Před 6 lety

    Hi, The countryinfoservice WSDL is throwing error 503. Can you please let me know any other sample SOAP service

    • @RaghavPal
      @RaghavPal  Před 6 lety

      Hi Shaan, you can see here - quicksoftwaretesting.com/sample-wsdl-urls-testing-soapui/

  • @pragatishukla1720
    @pragatishukla1720 Před 4 lety

    How to set property at environment level?

    • @RaghavPal
      @RaghavPal  Před 4 lety +2

      Hi Pragati, there are 5 levels in SoapUI
      Project
      TestSuite
      TestCase
      TestStep
      Global properties (In settings)
      Now based on your needs you can set the properties at any level. If you want to set something globally that can be accessed throughout the project use Project level properties. For anything at suite level use properties at TestSuite level and so on. For env Project level properties will be best suited

    • @pragatishukla1720
      @pragatishukla1720 Před 4 lety +1

      @@RaghavPal thank you

  • @amritabharadwaj6349
    @amritabharadwaj6349 Před 4 lety

    Excellent work...when I run the script it shows script1$_run_closure1@3dd2b5d4

    • @RaghavPal
      @RaghavPal  Před 4 lety

      Hi Amrita, not familiar with this issue, Pls recheck with the video if there are any differences in the steps or setup

  • @komalpatil9856
    @komalpatil9856 Před 2 lety

    Hello Raghav,
    Thanks for sharing the contents on SOAP UI Groovy Scripting.
    By referring to your video,
    I tried to add/Set properties using Groovy scripting, but properties are getting added multiple times.
    Below is my code [SOAP UI Version 5.7.0]
    //addProperty
    testRunner.testCase.testSuite.addProperty("A2AusernameC0001")
    testRunner.testCase.testSuite.addProperty("A2ApasswordC0001")
    testRunner.testCase.testSuite.addProperty("Nickname")
    Make me correct if I did something wrong in the script.

    • @RaghavPal
      @RaghavPal  Před 2 lety

      Hi Komal, Can try
      testRunner.testCase.testSuite.setPropertyValue( )

    • @komalpatil6855
      @komalpatil6855 Před 2 lety

      I also tried with setPropertyValue() and result is the same that have for addProperty()

    • @RaghavPal
      @RaghavPal  Před 2 lety +1

      Check all the steps again