Contributions
Re: Randomizing DataSource rows: data loops gets stuck
If you just need the entire line from a text file, you can do something like the following: 1. Create a DataSource as a Data Generator for random integers to use as the line number 2. Create a Groovy Script step that reads the line from the file: String readLine( File f, int n ) { String line = null; f.withReader { r -> while( n-- > 0 && ( ( line = r.readLine() ) != null ) ) ; } return line; } def lineNum = context.expand('${Get Random Line Number#lineNum}') as Integer; File infile = new File("C:\\local\\files\\lesmis.txt") String line = readLine(infile, lineNum ) log.info("$lineNum: $line"); return line; 3. Create a DataSource Loop step that points back to the Groovy Script step. 4. Put your steps between the Groovy Script step and the DataSource Loop, referencing the Groovy Script step result property: ${Get Random Row#result} This method reads every row in the file up to the selected one each time through, so it will be slower on larger files, butdoes not require loading all rows into memory. 1000 reads from a 50000 line file took about 15 seconds to complete. Code adapted from http://stackoverflow.com/questions/8223264/read-a-specific-line-of-a-file-with-groovy8 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.2KViews0likes0CommentsRe: Output raw request and response including headers to a file
How about this: myRequestStep = testRunner.testCase.getTestStepByName('my test step name') myFile.append(new String(myRequestStep.testRequest.messageExchange.rawRequestData)) myFile.append(new String(myRequestStep.testRequest.messageExchange.rawResponseData))7.4KViews2likes1CommentRe: passing values from groovy script to soap request
From your description it sounds like you are trying to update a Property 'num1' within a Properties step called 'Input Numbers', but the method you are using would only update the test cases own properties, not those within a Property step. Try using the GroovyUtils setProperty method: def gu = new com.eviware.soapui.support.GroovyUtils( context ) gu.setPropertyValue('Input Numbers', 'num1', lines_first[i])2.1KViews0likes0CommentsRe: capture values under similiar XPath in an array with groovy
[tt:1zk7u0pu]holder.getDomNodes[/tt:1zk7u0pu] returns an array of DomNodes, not another holder object so you can't use XPath on it. An alternative would be to get the count of fault nodes and modify the XPath to access values for each one. def indicators = [] def faultsPath = "//cth:companyTradingHistoryResponse[1]/cth:companyTradingHistoryReport[1]/thf:faults[1]" // convenience for (n in 1..holder.getDomNodes(faultsPath + "/thf:fault").size()) { indicators << holder.getNodeValue(faultsPath + "/thf:fault[$n]/thf:code/text()") + "_" + holder.getNodeValue(faultsPath + "/thf:fault[$n]/thf:faultString/text()") }3.6KViews0likes0CommentsRe: how to import xmls and save responses
You have to use Groovy scripts to do this in SoapUI free version. Get a list of file names then submit contents of each file in the request step. First Groovy step to get list of files: def fileList = [] new File("C:\\requests").eachFile { f -> if (f.isFile() && f.name.endsWith('.xml')) { def filename = f.name[0..-5] fileList.add(filename) } } if (fileList.size() < 1) { testRunner.fail("No request files") } context.put('fileList', fileList) Followed by request step with this in the body: ${=new File("C:\\requests\\" + (context.get('fileList')).last() +".xml").text} Followed by another Groovy step to remove the file from the list, write the response to a file and loop back to the request as long as there are more files: def fileList = context.get('fileList') def fileName = fileList.pop() def response = context.expand( '${Test Request#Response}' ) def f = new File("C:\\responses\\${fileName}_Response.xml") f.write(response, "UTF-8") if (fileList.size() > 0) { testRunner.gotoStepByName('Test Request') }12KViews0likes0CommentsRe: Groovy Script does not work
Sure you can. There are lots of great examples out on the web like this http://www.pspaeth.de/index.php/techarea/43-java/72-dialogs-in-groovy.html that will run from a Groovy script step. Modifying that example like this works for me: import groovy.swing.SwingBuilder import java.awt.FlowLayout as FL import javax.swing.BoxLayout as BXL def s = new SwingBuilder() s.setVariable('myDialog-properties',[:]) //-- 1 --// def vars = s.variables //-- 2 --// def dial = s.dialog(title:'Get Credentials',id:'myDialog',modal:true, pack:true, show:true) { //-- 3 --// panel() { boxLayout(axis:BXL.Y_AXIS) panel(alignmentX:0f) { flowLayout(alignment:FL.LEFT) label('User ID') textField(id:'userid',columns:10) //-- 4 --// } panel(alignmentX:0f) { flowLayout(alignment:FL.LEFT) label('Password') textField(id:'password',columns:10) //-- 4 --// } panel(alignmentX:0f) { flowLayout(alignment:FL.LEFT) button('OK',preferredSize:[80,24], actionPerformed:{ vars.dialogResult = 'OK' //-- 5 --// dispose() }) button('Cancel',preferredSize:[80,24], actionPerformed:{ vars.dialogResult = 'cancel' dispose() }) } } } log.info 'and the result is: ' + vars.dialogResult log.info 'the userID entered is: ' + vars.userid.text log.info 'password is: ' + vars.password.text testRunner.testCase.testSuite.setPropertyValue("ID",vars.userid.text) testRunner.testCase.testSuite.setPropertyValue("PW",vars.password.text);1.9KViews0likes0Comments