ReadyAPI - How to use code in the custom properties of a test step ?
Say we have a test step which actually calls/runs some test case. One of the properties, say ID has a variable value which is set by something else (script, another test step etc.). E.g. like this: ID :${TestCase-GetId#ID}. Can I use code inside the value box/field to alter the value of ID? This will be useful for ad hoc testing or could be used normally in the test. E.g. ID : ${TestCase-GetId#ID}.subString(0, 5). I don't want to create another groovy script for minor changes to property values. I know that we can prepend or append constants to the value easily like this - ID : MyId_${TestCase-GetId#ID}. But, I don't know if we can use code there instead. If we can use code, then are there any limitations (e.g. the code should be 100 characters or less) ? Keywords - script in custom properties editor, code in custom properties editor, alter the value of a custom property, code in the value of a custom property, script in the value of a custom property, code in the custom properties of a test step.Solved1KViews0likes2CommentsGroovyUtils XMLHolder throwing Xpath syntax error when XML node value contains escaped character.
GroovyUtils throwing error when XML node value contains escaped characters. In my script, I'm accessing a node that contains the description of an error. That node when read by my XMLHolder throws this error: Caused by: java.lang.RuntimeException: net.sf.saxon.trans.XPathException: XPath syntax error at char 9 on line 2 in {\nInvalid part number}: Unexpected token name "part" beyond end of expression It appears that the node I'm reading contains the value "\n", and when the holder tries to read it, it throws the error. How can I read the node, with the escaped value, and not bomb out?3.8KViews0likes12CommentsServiceV Pro: Default response unexpectedly replacing the scripted one
First thing first: I'm new to the ServiceV product, just got it few days ago. I'm creating a virt api where the following path is being used: /api/aicm/v1/subject/{subject_nr}/mandate/{creditor_id} where subject_nr and creditor_id represent the required TEMPLATE parameters. Beside the main success scenario (GET: -> HTTP 200 OK), where both arguments are made available in the URI, I'm trying to handle the following alternative scenarios in my virt api: a) GET: {subject_nr} is empty -> HTTP 400 Bad Request b) GET: {creditor_id} is empty -> HTTP 400 Bad Request c) GET: both {subject_nr} and {creditor_id} are empty -> HTTP 400 Bad Request The test paths associated with the four scenarios (1 main + 3 alts) are: 1. HTTP 200: /urds/wrd/api/aicm/v1/subject/0303200001/mandate/AB51TST405365330000 2. HTTP 400: /urds/wrd/api/aicm/v1/subject//mandate/AB51TST405365330000 3. HTTP 400: /urds/wrd/api/aicm/v1/subject/0303200001/mandate/ 4. HTTP 400: /urds/wrd/api/aicm/v1/subject//mandate/ I use the "Dispatch Strategy: Script" with default response returning HTTP 404 Not Found, and the following validation script to check the path arguments and return the appropriate response: assert log log.info("Executing dispatch script...") assert requestContext def props = requestContext.getProperties() assert props log.info("Request arguments: ${props}") def subNr = props["subject_nr"] def credId = props["creditor_id"] if (subNr.empty || credId.empty) { // return HTTP 400 return "GET 400 Bad Request" } log.info("subject_nr: ${subNr}") log.info("creditor_id: ${credId}") def isSubNrMatching = subNr ==~ /^\d{10}$/ log.info("subject_nr RegEx match is: ${isSubNrMatching}") def isCredIdMatching = credId ==~ /^(ab|AB)(\d{2})([a-zA-Z]{3})(\d{8})(0{4})$/ log.info("creditor_id RegEx match is: ${isCredIdMatching}") def areReqArgsValidated = isSubNrMatching && isCredIdMatching if (!areReqArgsValidated) { // return HTTP 400 return "GET 400 Bad Request" } log.info("Request arguments validated: ${areReqArgsValidated}") // return HTTP 200 return "GET 200 OK" Now, the problem is: Main success scenario and alternative scenario a) work just fine (meaning: in both cases I get the expected response dispatched by the script). With the remaining scenarios b) and c), a response with HTTP status code 404 is dispatched instead of the scripted one (400). This response is apparently not the default 404 response I created andselected in the "Default Response" drop-down list (which features a JSON payload in the body), for its body is empty. Additionally, no log output shows up in the script (or error) log tab, showing clearly thatthe dispatch strategy script is not executed. Any clue about why is this happening? Am I missing something fundamental, due to my lack of product knowledge?Solved6.4KViews0likes16CommentsIn ServiceV, how do I return a scripted response without it being overwritten in the Editor?
Hello, In one of my Virts, I have a Response typed out in XML in the Editor. I am using the "Script" tab to make Gzip and Base64 the message, as this is what our service expects. The script looks like this: def targetStream = new ByteArrayOutputStream() def zipStream = new GZIPOutputStream(targetStream) def data = mockResponse.getResponseContent().toString() zipStream.write(data.getBytes()) zipStream.close() def zipped = targetStream.toByteArray() targetStream.close() mockResponse.setResponseContent(zipped.encodeBase64()) This code "works" because it sends back the message as I expect. However, it has the side effect of changing the content of the Editor from XML to the encoded/GZipped message. Is there a way to do this so that it does not overwrite what is in the Editor. i.e. It would be beneficial to be able to see the message in plaintext. Thanks in advance.2.2KViews1like2CommentsHow to self-locate from inside a script step called from a different test case/test suite?
Hello, I am running SoapUI Pro (1.9). The problem I am facing is this: I have a Groovy script step in one test case (call it StepA in CaseA, SuiteA) call another Groovy test step in a different test case within a different test suite (call it StepB in CaseB, SuiteB). How can I determine StepB's location from within theStepB script? When I call StepB, I pass to it context and testRunner variables from StepA. If I query these objects from within StepB, all the methods and properties that return the current test step, test case or test suite give me StepA, CaseA and SuiteA respectively. I looked everywhere I could think of but I could not find any way of getting at StepB' own location (i.e. StepB, CaseB, SuiteB). Is there any way I can get what I want? Or perhaps an alternative solution to what I am trying to do? I am developing a kind of shared library within my project. I have done this before with stand-alone scripts that instantiate a class and attach it to context. Such scripts can be used from anywhere within the project. But this time the script that I am calling requires data steps and other scripts within the same test case, which is why I need to be able to determine what that "same test case" is from within the script. Thanks1.1KViews0likes2CommentsAdd or Build HTTP Request TestStep to Test Case through Groovy Script
Hello, I would like to create a new Test Step to an existing Test Case, I would like this to be an HTTP Request type. I've seen and completed examples of creating Groovy Test Steps to an existing Test Case, see below: def project = context.testCase.testSuite.project; def testSuite = project.getTestSuiteByName("Library"); def testCase = testSuite.getTestCaseByName("Modified Transactions"); def newStep = testCase.addTestStep("groovy", "HelloGroovy").setScript("log.info 'Hello'"); However, I would like to add an HTTP Request type and complete the necessary properties, endpoints and request, etc... It looks like this post is discussing somewhat what I want to do, how can I find the definition of all the step types, it only has EMAIL? Any help is most welcome.2.1KViews0likes2CommentsAssertion Test step gets False Failure
Hi, I am new to SoapUi and ran into some troubles for which I could not find an answer in already discussed topics. It may sound stupid, but here it goes. I have a test case with a Datasource, a request, an assertion step, DataSink and DataSourceLoop. The Request has a couple of assertions - Http Valid Codes (200) and a script assertion with below script: import groovy.json.JsonSlurper def response = messageExchange.response.responseContent def slurper = new JsonSlurper() def json = slurper.parseText response assert json.items.size > 0 Same assertions are added in the assertion script as well. Now the issue is: assertion added in request holds valid when the script is run. However, when the test case is run, the assertions in Assertion test case fail with errors: Status Code extraction failed Cannot read property responsecontent from null object I fail to understand why the same assertion is working when applied in the script but fails when added in the test case. Any leads on the issue would be of great help. Thanks!1.2KViews0likes1Comment'Node Missing' Message when field is in REST Response, but is empty
We have test scenarios which require us to validate when a given element is not passed in the request, the value for that element is empty in the response echo. We can see the element is returned in the echo and that its value is empty, which is the desired outcome. Our JSON and XML Message Content Assertions are failing in these scenarios with a 'Node Missing' message. I have read about this issue on several other forum posts and it seems the suggested solution is to write script assertions. In some cases in our test suite, we are referencing a common REST Request TestCase, returning the response as a custom property on that common TestCase, and running an Assertion TestStep on that response property from within many differentTestCase's. When I try to add a Script Assertion against that common REST Request TestCase, I am unable to because the 'Script' option on the 'Assertions' list is greyed out and disabled (screenshot below). So in order to make this work I will need to be able to either: 1) Assert an empty value from the standard Message Content Assertion assertion type without getting a 'Node Missing' message. or 2) Select the 'Script' option when asserting against a property that is returned from a 'Run TestCase' TestStep. I am using a licensed Ready! API version 1.7.0. thanks in advance for the help774Views0likes0CommentsCommand Line Update Script Library and Reload
Hello I'm looking for some help or guidance on anissue.My issue has to do with loading the external script library in Ready! API. I want to be able to update the location of the external script library to a location that is relative to the project file (e.g. "$PROJECT_PATH/scripts"), and then be able to make calls on classes in the script library. This also must be possible from a clean install of Ready! API and load of the project file, so I cannot just set it once and then forget it. So, I've written the following code which accomplishes this task. This code is executed on the project "Load Script" and subsequent calls in the same script on the Script Library work correctly. //Update "Script Library" setting def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def projectPath = groovyUtils.projectPath def isCommandLine = com.eviware.soapui.SoapUI.isCommandLine log.info "Load Script" com.eviware.soapui.SoapUI.getSettings().setString("Script Library", "${projectPath}/scripts") com.eviware.soapui.SoapUI.saveSettings() However, this only work when running from GUI. When running from Command Line OR GUI, I get errors that it cannot find classes present in my external Script Library: "groovy.lang.MissingPropertyException: No such property: mypackgefor class: Script1" "org.codehaus.groovy.control.MultpleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class mypackage.myclass ..." For continuous integration testing, I need this to work when invoking "testrunner.bat"/"testrunner.sh" and running tests. I've tried adding the following snippets of code, which do not seem to work either: //Update Groovy Script cache def engine = new com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory(isCommandLine) def classLoader = engine.getCoreClassLoader() def groovyClassLoader = new com.eviware.soapui.support.scripting.groovy.SoapUIGroovyClassLoader(classLoader, isCommandLine) groovyClassLoader.syncExternalClasses(true) and def core = com.eviware.soapui.SoapUI.getSoapUICore() core.reloadExternalLibraries() In the logs, I get messages that it did indeed set the Script Library path correctly and it is resetting the groovy class cache: INFO [SoapUIProGroovyScriptEngineFactory] Setting Script Library to [C:\path\to\script\library] INFO [SoapUIProGroovyScriptEngineFactory] Resetting groovy class cache due to 78 modified files Any advice on how to get this working from command line as well? EDIT: After further testing, my solution doesn't work even when using the GUI. EDIT2: Playing around some more and I found that in the GUI, if I move my Script Library calls out of the Project Load Script (where it's updating the Script Library path), it works just fine. However, command line execution still has trouble figuring out the Script Library calls (throws exceptions and such).1.5KViews0likes0Comments