ServiceV 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.4KViews0likes16CommentstestRunner.testCase.getTestStepByName("my").setPropertyValue("id","42") not working in script ...
Hello, I tried to write a groovy script an to set values of a testrequest, and to excecute that afterwards. It looks like this: testRunner.testCase.getTestStepByName("my").setPropertyValue("id", "42") def whatis = testRunner.testCase.getTestStepByName("my").getPropertyValue( "id" ) log.info "Value of id by testRunner.testCase.getPropertyValue: "+whatis testRunner.runTestStepByName("my") The result in the log gives Value of id by testRunner.testCase.getPropertyValue: null where I expected it to be 42, so also running "my" is not possible since it has no property values Where is the problem? I don`t see where and what is going wrong? Thanks, P.S. "my" looks like this: <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ilUserAdministration"> <soapenv:Header/> <soapenv:Body> <urn:addGroup soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <id xsi:type="xsd:string">?</id> </urn:addGroup> </soapenv:Body> </soapenv:Envelope>Solved5.5KViews0likes3CommentsGroovyUtils 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.8KViews0likes12CommentsLaunch Browser in Incognito/Private Mode
Thought of sharing the code in the community for launching browsers in their incognito modes. The function is parameterized such a way to run for the browsers Internet Explorer, Edge, Chrome and Firefox. Hope it will be useful for more people. function runIncognitoMode(browserName){ //var browserName = "firefox" //iexplore,edge,chrome,firefox if (Sys.WaitBrowser(browserName).Exists){ var browser = Sys.Browser(browserName); Log.Enabled = false // To disable the warning that might occur during closing of the browser browser.Close(); Log.Enabled = true // enabling the logs back } if(browserName=="edge"){ Browsers.Item(btEdge).RunOptions = "-inprivate" Delay(3000) Browsers.Item(btEdge).Run(); }else if (browserName=="iexplore"){ Browsers.Item(btIExplorer).RunOptions = "-private" Delay(3000) Browsers.Item(btIExplorer).Run(); }else if (browserName=="chrome"){ Browsers.Item(btChrome).RunOptions = "-incognito" Delay(3000) Browsers.Item(btChrome).Run(); }else if (browserName=="firefox"){ Browsers.Item(btFirefox).RunOptions = "-private" Delay(3000) Browsers.Item(btFirefox).Run(); } Sys.Browser(browserName).BrowserWindow(0).Maximize() }3.8KViews8likes3CommentsHow do I wait for a user to perform an action?
In a Script test, how do I prompt the user to perform some action, then continue the script after the user indicates the action is complete? For example, I need to interact with a CAPTCHA on a form, so I need to tell the user to satisfy the CAPTCHA then click on something to continue the automated test.Solved3.7KViews0likes9CommentsCan't import files in Python
I'm simply trying to use an import statement to import some constants in a python test script and its not working. the file I'm trying to import is in my project and in the same directory as the file that's trying to import it.I've looked through the specifics of usage for Python and even copied the file into <TestComplete>\Bin\Extensions\Python\Python34\Lib folder but still nothing. The specifics of usage also says you can"changethe sys_path variable explicitly and then import the module" but Sys doesn't even have a "path" property.Solved2.3KViews0likes2CommentsIn 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.2KViews1like2CommentsAdd 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.1KViews0likes2CommentsCompare text property of two objects
Hello, I am having a simple issue trying to compare two text values in keyword test where one value is greater than other. I had used compare property checkpoint, and the comparision is not correct.(you can see it from the printscreen). After that i had tried to do it in script, same with compare property checkpoint and the result was the same as in the keyword test. Also i had tried to do with if then statement:if (raspSr > vkIznos) then Log.message('ok') else log.error('notok') where i had defined my two variables as a String( var raspSr: string; var vkIznos: string), but it doesnt help. I constantlly get the incorrect results for everything mention above. I am sending you the printscreen results, any help will be welcomed.Solved1.7KViews0likes4CommentsError while generating script log using tear down script
Hi, I am trying to generate script log using tear down script and I am getting the error "groovy.lang.missingpropertyexception no such property testrunner for class" while executing the below code : testRunner.testCase.testSuite.project.testSuites["Utilities"].testCases["Reporting"].testSteps["Groovy1"].run(testRunner, context); I have also tried defining this but it didnt work def r = testRunner.testCase.testSuite.project.testSuites["Utilities"].testCases["Reporting"].testSteps["Groovy1"].run(testRunner, context); Please help1.7KViews0likes6Comments