Recent Discussions
How to check for the existence of a value in Groovy script
I have an existing Groovy script (for an assertion) that I need to change to check whether a variable exists, but not caring about the actual value. The script is using results from the test step. def expectedMsgs = [""" {"msgType":"Message","message":{"variable1":"<value>","variable2":[{"variable2a":"<value>","variable2b":"<value>","variable2c":"<value>","variable2d":"<value>"}]}} def msg = context.receivedMessage def isMatch = expectedMsgs.stream().any { em -> org.skyscreamer.jsonassert.JSONCompare.compareJSON(em, msg, org.skyscreamer.jsonassert.JSONCompareMode.LENIENT).passed()} log.info ("Websocket message #${context.messagetCount} ${isMatch ? "matched" : "did not match"} the list of expected string") assert(isMatch) Some of these values I do want to check an exact response is received and that's easy enough. But some of them, I just want to make sure the variable itself is present and value isn't null. Can't sort out how to handle that part. Thanks! Jonathan17Views0likes0CommentsScripting in ReadyAPI Virtualization for Dynamic Mocks
Hey Everyone. I wanted to make a post about scripting in ReadyAPI Virtualization for the purpose of creating dynamic mocks. Scripted samples always help when I'm trying to achieve something, so I hope that these scripts will help guide you with dynamic mocks. I've primarily used two resources to learn how to work with dynamic mocks. The first is a support document for SoapUI OS. This page has a comprehensive overview on working with mock services and provides examples on how to accomplish various tasks when working with the virtual service scripts. https://www.soapui.org/docs/soap-mocking/creating-dynamic-mockservices/ The second resource that I've found to be useful is our documentation on Virtual service scripting.I find that this page is better than the previous one above at explaining the scripting objects that ReadyAPI uses. here:https://support.smartbear.com/readyapi/docs/virtualization/configure/scripting.html My intent here is to provide some scripted samples that I've worked on. I'd also like to hear if anyone has requests on scripted tasks with virtual services in ReadyAPI.110Views0likes3CommentsGroovy script for dynamic response in Readyapi
Our scope of need is to get a dynamic response if the user hits the API request incorrectly and they need to get different response. I have created in readyapi rest, soap, and jdbc protocols with static responses when the user wants to access the response, but when the user requests with payload incorrectly example ( wrong I'd -xxxxx) , they receive the same response from readyAPI. I would like to create script to handle dynamic response; could you please share an example?114Views0likes2CommentsHow do you reuse your ReadyAPI Groovy scripts if you want to run tests in a pipeline?
"Create custom Groovy classes, embed your reusable Groovy scripts into their methods, save them as separate files with the .groovy extension and voila - your Script Library is ready. You just need to point ReadyAPI where to find it (Preferences>ReadyAPI > Script library). If you change anything in those external classes, ReadyAPI will detect this and reload the classes automatically." Does this work if you're running the tests in a pipeline or from a commandline on your local machine? How would you point your commandline run script to the groovy script library? And where would you recommend keeping this library if it is being used in multiple projects? We have multiple projects but kept within the same repo (not using git's integration with readyapi, as this doesn't allow for multiple projects in the same repo). Ideally what I want is for someone to pull down the tests from git and then just open up readyApi and be able to run the tests. I don't want them to have to do lots of configuration to be able to run the tests.107Views0likes2CommentsSwitching Environments Groovy Scripting
I am running automation on a Test Suite. There are 5 Private environments and 5 corresponding Public environments. I can kick off the automation in Jenkins with a starter Environment, i.e. QA. Each run will have to switch to Public 75% through. So in a run, it will have to switch from QA to Public QA, and 4 more switches to follow on the subsequent Jenkins job. I have a script that can switch environments that I borrowed from Smartbear support: def env = context.testCase.testSuite.project.getEnvironmentByName("Public QA2"); context.testCase.testSuite.project.setActiveEnvironment(env) But it does not solve my dilemma. Since I am running the same test suite for all environments I need a script that will switch depending on the current environment. I am by far no JS or JSON coder, I get by, but it needs it to run like this: if QA then Public QA if QA2 then Public QA2 if UAT then Public UAT if ENV1 then Public ENV1 if SITE then Public SITE If someone could code that for me to run in a groovy script I would be forever indebted to you.94Views0likes4CommentsHow to disable "autocorrect/autofill" on SOAP requests
Using ReadyAPI to do a data driven test against a SOAP API. On each iteration, putting XML in the values for a properties test step. This is so that we can have some tests with missing elements, or other structural options. Using a placeholder in the SOAP request to grab those property values (see image). Whenever I save the project, ReadyAPI goes into my request, sees missing elements (because the placeholder puts them there during runtime) and "helps" me by shoving empty element tags in there for schema compliance. Next time I run the test, it fails because of extra tags... I have to remember to go into the request and delete the extra tags. One day I may forget and raise an embarrassing defect. Main Question: Is there a way to disable this "help" that keeps making things more complicated? (please support negative test cases - they're critical for robust testing) Thanks67Views0likes0CommentsHow to build SQL query using strings whose value should be retrieved from TestCase property
Suppose i have the following properties defined in the Test Case Properties FromTime =2023-11-15 23:00:00 ToTime =2023-11-16 23:00:00 I want to replace the time given in the below query with the above test case property variables. How to do that in ReadyAPI JDBC datasource ? SELECT * FROM Table1 where TagId = 4314 and Time > '2023-11-15 23:00:00' and Time < '2023-11-16 23:00:00' I am able to retrieve integer values like TagId and use it by adding 'Prepared Properties' within the JDBC datasource window. But if i add the string and use it inside the query, data is not fetched as the string is not interpreted properly.342Views1like7Commentshow to change test step name when save test results
Hi, I'm trying to save test result into a file with following scripts. def pName = context.currentStep.testCase.testSuite.project.name //get project name def pDate = new Date().format( 'yyyyMMdd' )//get current date def sDate = pDate.toString()//convert date to string def pTestSuite = context.currentStep.testCase.testSuite.name//get TestSuite name def pTestCase = context.currentStep.testCase.name//get TestCase name def filePath = 'E:/Data/Dean Ding/CRD files/CRD_results_test/'+pName+'_'+sDate+'/'+pTestSuite+'/'+pTestCase+'/'//compose the folder path File file = new File(filePath) if (!file.exists()) file.mkdirs()//create the destination folder fos = new FileOutputStream(filePath+ testStepResult.testStep.label + '.txt', true) pw = new PrintWriter( fos ) testStepResult.writeTo( pw ) pw.close() fos.close() but as my test step name contains symbols like : , " such special symbols which not accepted when create txt file due to naming convention, as there are more than 1000 cases it will take such long time to change my test step name,I found script to replace those symbols but don't know how to make it change when use above script to save test results. It will be much appreciated if anyone can provide the scripts.187Views0likes2CommentsTestEngine external JAR files - error - unable to resolve class
Background - We have test engine hosted on some linux server and we execute tests suing CURL cmd or POSTMAN. Given some external JARs When we add external JARs in /bin/ext folder of test engine server and re-start the test engine And run the tests using curl command from locally or using POSTMAN Then it throws error for groovy script test step saying unable to resolve class <className present in external JARs> on import statement itself. We have also configured .vmoptions of test engine server to read ext JARs but still it throws error. Locally, In ReadyAPI, we are placing those JARs in /bin/ext/ folder and it works perfectly fine. Any solution to this problem?178Views1like2CommentsCreate Selenium Tests in ReadyAPI
How to Create Selenium Tests in ReadyAPI?. Getting error. Not sure where it went wrong. I followed the steps in below link. https://support.smartbear.com/readyapi/docs/integrations/selenium/integrate.html Getting below error when I have tried sample code in Groovy scripts. Snippet: import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.By; System.setProperty("webdriver.chrome.driver", "C:/Program Files/SmartBear/ReadyAPI-3.42.1/bin/ext/chromedriver.exe"); def driver = new ChromeDriver() // Navigate to the ReadyAPI documentation driver.get("https://support.smartbear.com/readyapi/docs/") // Enter the search string def searchbox = driver.findElement(By.id("inputSearchBox")); searchbox.sendKeys("Groovy"); // Command to search for the typed text def searchbtn = driver.findElement(By.id("btnSearch")); searchbtn.click(); // List suggestions def allSuggestions = driver.findElements(By.xpath("//div[@id='search_results_container']/div/h5/a")) for (def suggestion : allSuggestions) { if(suggestion.getAttribute('href') != '') log.info(suggestion.getAttribute('href')) else log.error('The test failed.') } // Close the browser driver.quit(); Error: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script4.groovy: 7: unable to resolve class ChromeDriver @ line 7, column 14. def driver = new ChromeDriver() ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class ChromeDriver @ line 7, column 14.Solved200Views0likes2Comments