Groovy Script to delete test cases that begin with value
Disclaimer - My knowledge of Groovy is very limited. I basically require a groovy script within my test case to delete test steps that begin with 'Order'. I have tried this below, but to no avail, but that's kind of what I want. No idea if the syntax is correct or not! testSuite.removeTestStep.startswith(Order) This script would ideally be at the bottom of the test case and delete all the test steps that begin with the word 'Order' Any help would be greatly appreciated. Many Thanks. Ben1.1KViews0likes5CommentsHow to set the custom properties on project level if the property is coming multiple time inResponse
Hi All , I need a suggestion how to set the custom properties on project level if the required property value will come multiple times in loop . Take an example , I have to set the custom properties for below property value : (a) Id (b) StreamingUrl but both property is coming multiple times in response so if I will apply the loop , I will be able to get it for all but then how to do set since I need to grab these values from one API and need to pass in different API to get the response . Please help , it's high priority to me since I am aware how to set if it will come one time but not sure how to do if it will come in loop . Please find the response json : ( I have given here the short data but it will repeat the same 20 times ) { "Shuffled": true, "TotalTracks": 20, "Tracks": [ { "Provider": "QQ", "TrackOptions": "212782314", "Album": { "Cover": "http://y.gtimg.cn/music/photo_new/T002R120x120M000002JdNyK4A9iuS_1.jpg", "ID": 3866362, "Title": "Fall" }, "Artist": { "ID": 243334, "Name": "I Am Dive" }, "ID": 212782314, "FavoriteURL": "Tidal/updatefav/212782314", "Length": 1202841, "StreamingUrl": "Tidal/streamingurl/212782314?recentdata=%7B%22album_id%22%3A3866362%2C%22album_mid%22%3A%22Fall%22%2C%22album_name%22%3A%22Fall%22%2C%22album_pic%22%3A%22http%3A%2F%2Fy.gtimg.cn%2Fmusic%2Fphoto_new%2FT002R120x120M000002JdNyK4A9iuS_1.jpg%22%2C%22album_title%22%3A%22Fall%22%2C%22singer_id%22%3A243334%2C%22singer_name%22%3A%22I+Am+Dive%22%2C%22song_id%22%3A212782314%2C%22song_mid%22%3A%22002GJTjz2lts7l%22%2C%22song_name%22%3A%22Lines%22%2C%22song_play_url%22%3A%22http%3A%2F%2Fisure6.stream.qqmusic.qq.com%2FC200004YCdgj3Jyf75.m4a%3Fguid%3D2000001669%26vkey%3DA120EEC7DF54154D994949A91259599CBAFC0A77BDF8113110FD892AB21F4D2178AD010CD466F2C94C4B1F511BA162AD6009A682CD07E5BB%26uin%3D%26fromtag%3D231%22%2C%22song_size%22%3A1202841%7D&contentProvider=QQ", "Title": "Lines" }, { "Provider": "QQ", "TrackOptions": "201700645", "Album": { "Cover": "http://y.gtimg.cn/music/photo_new/T002R120x120M000003JUUkf3IROdv_1.jpg", "ID": 1987801, "Title": "Elephant House" }, "Artist": { "ID": 1451930, "Name": "Elephant House" }, "ID": 201700645, "FavoriteURL": "Tidal/updatefav/201700645", "Length": 3138484, "StreamingUrl": "Tidal/streamingurl/201700645?recentdata=%7B%22album_id%22%3A1987801%2C%22album_mid%22%3A%22Elephant+House%22%2C%22album_name%22%3A%22Elephant+House%22%2C%22album_pic%22%3A%22http%3A%2F%2Fy.gtimg.cn%2Fmusic%2Fphoto_new%2FT002R120x120M000003JUUkf3IROdv_1.jpg%22%2C%22album_title%22%3A%22Elephant+House%22%2C%22singer_id%22%3A1451930%2C%22singer_name%22%3A%22Elephant+House%22%2C%22song_id%22%3A201700645%2C%22song_mid%22%3A%220020zFNr1CPwZ9%22%2C%22song_name%22%3A%22Camel+Mom%22%2C%22song_play_url%22%3A%22http%3A%2F%2Fisure6.stream.qqmusic.qq.com%2FC2000038gl8Z3FPq24.m4a%3Fguid%3D2000001669%26vkey%3DA7664B53C33E70B86BA26BD01FCD65F60D06730B53DBCFBF70699E8209154491549E713F7DB185EFBC52526368B7543954B07D715C23E2AC%26uin%3D%26fromtag%3D231%22%2C%22song_size%22%3A3138484%7D&contentProvider=QQ", "Title": "Camel Mom" },Solved1.5KViews0likes2CommentsHow to set Property Value of Sub Node of XML file in SOAP UI?
Hi Team, Thank you very much in advance. I have xml in the below structure and i need to update values to sub nodes using Groovy script to automate the TestScripts. <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:inb="http://sap.com/xi/FI-Processing"> <soap:Header/> <soap:Body> <inb:OrderItemMessageBulk> <MessageHeader> <CreationDateTime></CreationDateTime> </MessageHeader> <OrderItems> <MessageHeader> <CreationDateTime></CreationDateTime> </MessageHeader> <OrderItem> <DocumentItemID DocumentItemTypeCode="" SendingComponentID="" LogicalSystemID=""> </DocumentItemID> </OrderItems> </inb:OrderItemMessageBulk> </soap:Body> </soap:Envelope> How can i set Value of nodeDocumentItemTypeCode,SendingComponentID andLogicalSystemID in the above XML structure. Kindly guide me to solve the issue. Regards, Ramana.2.8KViews0likes9CommentsDisplaying Log Output as null when trying to set node value using groovy script
import com.eviware.soapui.support.XmlHolder import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext def request1 = testRunner.testCase.testSuite.testCases["GetEmp"].testSteps["GetEmpDtls"].getPropertyValue("Request") def xml1= new XmlHolder(request1) def getnode1=xml1.getNodeValue("saxon:parse(//tem:GetEmp/tem:InputParameters)//USER_ID") log.info ("GetNodeValue : " +getnode1) def setnode1=xml1.setNodeValue("saxon:parse(//tem:GetEmp/tem:InputParameters)//USER_ID" , "JACK") log.info ("SetNodeValue : " +setnode1) Log Output: Mon Mar 09 16:29:48 IST 2020:INFO:GetNodeValue : test Mon Mar 09 16:29:48 IST 2020:INFO:SetNodeValue : null Expected Logt Output is : SetNodeValue : JACK, BUT Actual Log Output is : SetNodeValue : null I want to set the node value in above scenario, why null value is displaying?, can you provide solution for above senario. In above script emoji icons are displaying, please find the attached script file.1.6KViews0likes4CommentsSoapui, Groovy problem with JSM connection
Hi! I have a Groovy script in SoapUI Open Source (5.5.4) & Hermes 1.14 which keeps sending JMS message to an IBM MQ queue. The relevant section of the code is the following (code is simplified just for the sake of readability): while (testRunner.testCase.testSuite.project.getPropertyValue('STOP'+n) != '1') { requestHolder.setNodeValue("//soapenv:Envelope/soapenv:Body/Payment/creditor/AccountNumber",accountNumber); testRunner.runTestStepByName('sendPayment' + n); } Multiple threads can be started with dedicated test steps (for example: sendPayment1 for Thread-1, sendPayment2 for Thread-2) Based on the logic above we send continously transaction to a payment hub. So far we had no problems using this method, but after moving to the production environment I keep getting MQ connection problems. It seems we're having trouble connecting to the queue manager, and according to the logs it's network issue - although our network experts said there was no problem with the network and all server (including the one that hosts the QM) were available in this time period. Did anybody experience this phenomenon? My biggest problem is not the outage anyway, but that the script stops working and for a more-days-long test it's a showstopper. Is there a way to catch this outage in SoapUI Groovy script? Try-catch-finally didn't workd - I think the exception was handled by another built-in class. All I see - unfortunately hours later - a log entry and a broken sending process in the database. Thanks in advance for sharing your thought with me on this issue! BR, Csaba ps.: And sorry for the foreign language in the log attached, I think error codes make understandable the excerpt. ps2: At the same time the proble occurs a ....FAILED.txt file appears in the log directory with the following content: Status: FAILED Time Taken: 10133 Size: 0 Timestamp: Fri Nov 29 14:07:59 CET 2019 TestStep: initiatePaymentOTM1 ----------------- Messages ------------------------------ [SOAP Response] Response is missing or empty ----------------- Properties ------------------------------ Endpoint: jms://HERMSESSION::queue_SOAPUI_WRAPPER_IN::queue_TEST__REPLY Username: Encoding: UTF-8 Password: ---------------- Request --------------------------- Request Headers: ---------------- Response -------------------------- Response Headers:596Views0likes0CommentsHow can I pick test case property inside a command line
For example, this is the snippet def foldername =context.expand( '${#TestCase#folderName}' ) def cmd='"aws s3 cp s3://<bucketName>/<folder>/' +foldername.toString() '<folderPathtoCopy>/' + foldername.toString()' --recursive"' def command='"C:/Program Files/Git/git-bash.exe" -c '+cmd def proc = command.execute() proc.waitForOrKill(100000) I want to download a folder from S3 which is upload by the foldername stored in test case property. foldername changes dynamically. I know there is some syntax errors but not able to solve it494Views0likes0CommentsAdd the responses to a list in Mockservice's OnRequestScript and refer it in the Project's testsuite
I have a mockservice that listens on port 80 and receive the JSON callback from a API server. Rightnow im using the below code in OnrRequest script to get the response and assign it to a project's property like below. mockRunner.mockService.project.setPropertyValue("ResponseBody",requestBody) In the testsuite, i poll for the "ResponseBody" and when it gets some value then I read the responsebody value and process it in the testsuite. After processing i will move to the next hit. The polling/waiting is consuming time and instead of waiting for the callback response i want to complete all the hits and finally process the callback responses collected in the mockservice. Is there anyway to collect all responses in the mockservice and refer the list in the testsuite? i tried below but Im not sure whether its correct or not. In the Mockservice's "Start Script" i put the below code def mockList=[] context.setProperty("MockResponseList",mockList) In the Mockservice's "OnRequest Script" i put the below code def requestBody = mockRequest.getRequestContent() def jsonResponseList=context.getProperty("MockResponseList") jsonResponseList.add(requestBody) 1)but i dont know how to refer the above jsonResponseList in the project's testsuites 2)jsonResponseList will stay the same for each OnrequestScript call? or it will be unique? 3)Is there anyway to collect all responses in the mockservice and refer the list in the testsuite? 4)What is the best way to collect all responses and process in one go?842Views0likes0CommentsList set in Context.setProperty of testSuite modifiable in testCase context but not string,int etc
In soapUI, I have a List in testSuite which I setup using context.setProperty is visible and modifiable in testcase1 and testcase2 . I'm able to modify the list in both testcases , but I'm not able to do the same for strings or integers or floats etc. Please see the below code and guide me accordingly. I know that we can use propertyValue to set/change string, but I don't want to use that as my string size is very huge and i have array of such strings. /*soapUI groovy code: //In TESTSUITE: List l=[] context.setProperty("list",l) String str="suite" context.setProperty("string",str) //In TESTCASE1: log.info("From TC1") arrlst=context.getProperty("list") for(lst in arrlst){ log.info(lst)} arrlst.add("First added in TC1") for(lst in arrlst){ log.info(lst)} //prints "First added in TC1" str=context.getProperty("string") log.info("The string is"+context.getProperty("string")) //prints "the string is suite" str="This is TC1!" log.info("The string is"+context.getProperty("string")) //still prints "the string is suite" context.setProperty("string",str) log.info("The string is"+context.getProperty("string")) //prints "the string is this is TC2" but its in TC1's local context //In TESTCASE2: log.info("From TC2") l1=context.getProperty("list") for(lst in l1){ log.info(lst)} //prints "First added in TC1" str=context.getProperty("string") log.info(str) //prints "the string is suite" not the value set in the testcase1 */ why im able to change/modify the list in other testcases but not the strings, integers etc?1.9KViews0likes4CommentsLet's talk Meta Programming to automatically refactor test cases in SOAPUI
One of SOAPUI's most powerful features and certainly my favourite is using Groovy forMeta-Programmingto factor and enhace my tests. I thought I would share the latest meta-coding script I've added to myReusable Script library. This script can be used to enhance and cleanup a TestSuite that is created automatically using the built in feature Interface -> Generate TestSuite. I import quite a lot of my REST API and this approach saves me a lot of grunt work. Script Features: Renames each RestReqest from "Request N" to something more appropiate following a basic BDD syntaxusing the HTTP Method and the resource description to provide appropriate description. e.g. "Request N" using a "HTTP GET /account" becomes "When /account is Retrieved" If the TestCase contains multiple requests these are split into new approriately named TestCases using the above convention to comply with the automated testing best practice of testing one thing at a time. Adds an Groovy script forGiven and Thenaround each Request step in each TestCase. To use this script. Define a Library TestSuite in the root of the project you want to refactor. Disable theLibraryTestSuite so that it doesn't get run in an uncontrolled manner. Define Meta-Programming Testcase to get this: Create a Groovy script in Meta-Programming and add the following code: Then simply run the Refactor Generate Tests. refactorGeneratedTests(testRunner.testCase.testSuite.project) cleanUp(testRunner.testCase.testSuite.project) def refactorGeneratedTests(def thisProject) { assert thisProject log.info "Processing ${thisProject.name}" for (testSuite in thisProject.testSuiteList) { if (!testSuite.isDisabled()) { log.info "- ${testSuite.name}" for (testCase in testSuite.testCaseList) { if (!testCase.isDisabled()) { log.info "-- ${testCase.name}" renameRequestSteps(testCase) forEachRequestMake(testCase) ensureBdd(testCase) } } } } } def renameRequestSteps(testCase) { assert testCase assert testCase instanceof WsdlTestCase def languageMap = [ "GET": 'Retrieved', "POST": 'Created', "PUT": "Updated", 'DELETE': 'Deleted'] log.info "languageMap : ${languageMap}" boolean isFirst = true for (testStep in testCase.testStepList) { log.info "--- ${testStep.name} ${testStep.getClass().getSimpleName()}" if (isREST(testStep)) { if (testStep.label.startsWith("Request")) { String restOperation = testStep.getOperation().getName() log.info "restOperation : " + restOperation String methodType = testStep.getRestMethod().getMethod() log.info "methodType : ${methodType}" actionName = languageMap.get(methodType) log.info "actionName : ${actionName}" String newStepName = "When ${restOperation} is ${actionName}" log.info "${newStepName}" testStep.setName(newStepName) } } } } def forEachRequestMake(testCase) { assert testCase assert testCase instanceof WsdlTestCase def languageMap = [ "GET": 'Retrieve', "POST": 'Create', "PUT": "Update", 'DELETE': 'Delete'] log.info "languageMap : ${languageMap}" boolean isFirst = true for (testStep in testCase.testStepList) { log.info "--- ${testStep.name} (${testStep.getClass().getSimpleName()})" if (isREST(testStep)) { String restOperation = testStep.getOperation().getName() log.info "restOperation : " + restOperation String methodType = testStep.getRestMethod().getMethod() log.info "methodType : ${methodType}" actionName = languageMap.get(methodType) log.info "actionName : ${actionName}" String newTestCaseName = "${actionName} ${restOperation} " log.info "${newTestCaseName}" if (isFirst) { testCase.setName(newTestCaseName) isFirst = false } else { // clone the test for each REST request testCase.testSuite.cloneTestCase(testCase, newTestCaseName); } } } } def ensureBdd(testCase) { assert testCase assert testCase instanceof WsdlTestCase givenStep = "Given content for the request" if (testCase.getTestStepByName(givenStep) == null) { testCase.insertTestStep("groovy", givenStep, 0) } thenStep = "Then the response is as expected" if (testCase.getTestStepByName(thenStep) == null) { testCase.addTestStep("groovy", thenStep) } } def isREST(def testStep) { assert testStep return testStep instanceof RestTestRequestStep; } def addHttpStatusAssertions(testStep) { assert testStep return testStep instanceof RestTestRequestStep; if (testStep.getAssertionCount() == 0) { testStep.addAssertion("Valid HTTP Status Codes").setCodes("200") testStep.addAssertion("Invalid HTTP Status Codes").setCodes("400, 500") } log.info testStep.getAssertionList() } def cleanUp(def thisProject) { assert thisProject log.info "${thisProject.name}" for (testSuite in thisProject.testSuiteList) { log.info "- ${testSuite.name}" for (testCase in testSuite.testCaseList) { log.info "-- ${testCase.name}" String actionName = testCase.name.split().head() log.info "-- ${actionName}" for (testStep in testCase.testStepList) { log.info "--- ${testStep.name} ${testStep.getClass().getSimpleName()}" if (isREST(testStep)) { if (testStep.name.contains(actionName)) { log.info("keep ${testStep.name} in ${testCase.name}") } else { log.info("remove ${testStep.name} from ${testCase.name}") testCase.removeTestStep(testStep) } } } } } } // https://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/teststeps/RestTestRequestStep.html // class com.eviware.soapui.impl.wsdl.WsdlProject // class com.eviware.soapui.impl.wsdl.WsdlTestSuite // class com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase // class com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep log.info context.getClass() log.info testRunner.getClass() log.info testRunner.testCase.getClass() log.info testRunner.testCase.testSuite.getClass() log.info testRunner.testCase.testSuite.project.getClass() log.info testRunner.testCase.testSuite.project.workspace.getClass() import com.eviware.soapui.impl.wsdl.WsdlTestSuite import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep870Views0likes0Comments