bqualtersOccasional ContributorJoined 3 years ago14 Posts4 LikesLikes received1 SolutionView All Badges
ContributionsMost RecentMost LikesSolutionsRe: Using variables and running tests with driver script causes fails I think I found a way to do what I want by setting the TestRequest property directly in the script at runtime - not sure WHY I have to do this if I designate the field to reference a property BUT this way I just figured out works so...if it works it works. I'd like to know WHY the other way doesn't though... Re: Using variables and running tests with driver script causes fails I set the HexKey value after running SQL using the following command - it works as I see the vlaue int he Property frame. (I write out whatever queried columns exist in the SQL as test case properties with the Alias supplied in the SQL's as the property names in the end.) testRunner.testCase.testSuite.testCases[currTest].setPropertyValue(rowData[currFlds]+recordNum, rowData[currFlds+1]) Re: Using variables and running tests with driver script causes fails I was using code in a way to set the property variable but - I thought if I put ${#TestCase#HexKey} for example in the Request itself that it would automatically use whatever value was stored in the TestCase property referenced. The value may change from one run to the next as I run an SQL to retrieve a valid value from the database and write that value as the HexKey testcase property BEFORE having the Groovy script driver call the test step to execute. The Request works if I manually trigger it's execution (as the value has already been written to that property from previous script attempt to run it where the SQL gets the value - it doesn't go away) but if I run the script it fails and returns-->{"Message": "No HTTP resource was found that matches the request URI 'http://api.xxxxx.xxxxx1.xxx.sc.xxx.com/xxxxx /createauditbycase/'."} (I replaced parts of the URL with xxx's obviously) - Below is a pictur eof how I have the request set up - works manually -(The Not Found message IS EXPECTED as using bad value) but try to run it with a command from Groovy and get the above error mentioned. It looks like it sent a null value I guess. I execut eit in the script with these commands--> status = tstep.run(testRunner,context); result = status.getStatus().toString(); If I hard code the value in the Value column pictured it works both ways - manually and through the script. This is obviously not good so I need to understand what is wrong. Re: Using variables and running tests with driver script causes fails Still not sure why this is happening--> I can not seem to get the test steps to execute using the referenced variables (either as part of the request or part of the assertion) - for example, I run a SQL - it retrieves an OrderKey - which I write as a Property at the testcase level - then I sub in that value using the parameter in the API Request of the test step and instead of using the hardcoded value I supply ${#TestCase#OrderKey} in the parameter value column - this works if I trigger the execution of the step manually as it uses the value currently stored in the test case Property called OrderKey BUT--> when I run the script to get it to execute this step it fails even though the SQL has run and defined the value in the test case property (OrderKey) successfully - it fails to make the request and throws an error. If I manually execute it again at this point with the retrieved value from the SQL - it works. The same goes for the Assertions - if I reference a property - it fails when run through the script (which I removed the variablized "submission" value and hardcoded it) - but if I click the Request to run manually with same setup - it works. Sooo...what's the deal? Re: Using variables and running tests with driver script causes fails TNeuschwanger-Thanks for the response! At this point I have figured out how to do what I wanted in terms of being able to loop through all the tests in the suite one at a time, then through each test step in each case, run dynamic data retrieval SQL's and use the values for checkpoints, BUT I am still trying to figure some things out - especially the use of assertions if they fail in the groovy script (not in the embedded groovy script of a step mind you - just in the Groovy Script test that acts as my driver). If the assertion fails the script errors out - that doesn't seem to make sense as I thought it would simply cause the test to fail - so I built my own code to do the check at this point. The assert seems to have made itself useless because of this fail possibility. Also, using the messageExchange object seems to only be available if you are in a Script Assertion step within a test step - I don't know what I need to import in a regular Groovy script to have access to that so I worked my way around it. I get an error when I try to use messageExchange so...not sure what to do other than not use it here. I can use it in the embedded Assert Script but that defeats the purpose of having ONE SCRIPT for all test cases. The point of what I am trying to do is make it so that all the guys on my team, WHO HAVE NEVER DONE API testing or used this tool or written Groovy scripts, can create test cases simply through an excel spreadsheet. I will (eventually) read from an Excel file what the desired test is to create and dynamically create it - assertions and all, dynamically through the driver script - much like I currently do with our functional testing in UFT. I just started with SoapUI - in my free time for the last month or so - and found it cumbersome (the free version mind you as work is too cheap to pay for anything) to build a single test case manually - you have to get the wsdl, make all the header settings, set up properties, do data prep with the AUT to get to initial condition, then make your assertions for each step one by one within the tool, not to mention the ridiculously poor debugging tools and meaningless error messages that tell you the error is on line 12 when it's actually on line 378 etc. Also, am I missing capabilities like putting breakpoints and viewing runtime variable values while the script is in progress? If so, please advise as I am all ears and hoping it gets better. So anyway, I am writing a script that runs in whichever test suite you place it, and utilizes the various property levels to make as much of the testing dynamic with the focus being FUNCTIONAL testing. My big problem right now is figuring out how to make sure the test steps use the property values I put in the api variable (parameter) places - for example, I think I mentioned above, each of my tests is to be written with a SQL statement that finds a valid piece of data that meets needed initial conditions - writes the result to a test case property, and that test case property is referenced in the parameter space for the API call - when the script runs - it fails - don't know why as log doesn't tell me. BUT, after the run, since the data has been retrieved and written to the testcase property being referenced, if I click Run manually to run it again - it works and uses the value the SQL retrieved. So..what's the deal there? I will be the first to admit I am NOT a Java / Java Script / object oriented programming languages person. I am self taught at everything I do and as such - what I've learned MAY BE WRONG! So if you have some advice -I will take it. Also, in regards to the logs that SoapUi provides - they suck. Maybe I'm missing something but they simply tell you whether or not the test step passed or failed - but lack the details as to WHY. For example, I created 5 test cases - ran them at the Test Suite level and generated the report. The only info given is the basics and the response package BUT there was nothing about which assertion failed even for the assertions I created with the built-in tool. If I have 5 or 6 different checks I want to know WHICH one failed IN THE REPORT LOG so I don't have to go open up the test steps individually and see which are green and which are red...what am I missing? Again - I have written my own checkpoints now and don't need the built in ones unless I want to use them so I can turn the step green or red and make it look pretty that way. Seems to me, if you grab the response and convert it to a string you can easily do almost ALL the checks that are "built-in" with very little effort using the Groovy commands - ie contains, count etc. The manual creation part is very cumbersome and time consuming. Let me know what you think - especially on the parts where I have actual questions and not so much the complaints - I complain alot for a non-developer type person - I know that. But hey, with a lack of knowledge comes a willingness to blame others! Using variables and running tests with driver script causes fails I am trying (maybe foolishly?) to write a Groovy script to run a series of test cases in a test suite. The script would/should be able to 1) get all the testnames to run in the test suite, 2) loop through execute each test in order found in suite A- execute any SQL queries defined in testcase properties and create the dynamic property/value pairing at testcase level 3) loop through steps in each called test run while utilizing any defined variables(properties) referenced for input or assertions 4) produce informative log on each test/step so others know what was test It is these last two part that have gotten me in a knot--I can not seem to get the test steps to execute and use the referenced variables (either as part of the request or part of the assertion) - for example I may run a SQL - it retrieves an OrderKey - which I write as a Property at the testcase level - then I try to sub in that value using the parameter in the API Request and subbing in ${#TestCase#OrderKey} - it works if I run it manually and it uses the value I manually put in the property but when I run the script to get it to execute this step it fails even though the SQL has run and defined the value in the test case property (OrderKey) successfully - it fails to make the request and throws an error. If I manually execute it again at this point with the retrieved value from the SQL - it works. The same goes for the Assertions - if I reference a property - it fails when run through the script (which I removed the variablized "submission" value and hardcoded it) - but if I click the Request to run manually with same setup - it works. Sooo...what's the deal? the command I use to run the step is --> (beginning of the loop) def Steps = it.getTestStepList() Steps.each //loop thru each step in test case as found by previous command { tstep = tcase.getTestStepByName(it.Name); status = tstep.run(testRunner,context); and then the rest of the steps follow - does something need to be done to enforce the variablization in the script? Big question number 2 - can Assertion scripting be done in a regular Groovy script or do you have to go to the Request and bring up the Script Assertion file and code it there? If it can be done directly in a standalone Groovy script - an example would be cool too! Everytime I try I get that the messageExchange object is invalid or unavailable... Any help is appreciated - but keep in mind - I am a NEWBIE so please don't assume I know anything....THANKS! Trying to figure out how to do script assertions and copied this code from other post and get error //imports import groovy.json.JsonSlurper //grab the response def ResponseMessage = messageExchange.response.responseContent // replace "(starting&ending), [](starting&ending) and \ with space from response def TrimResponse =ResponseMessage.replaceAll('^\"|\"$','').replaceAll('^\\[|\\]$','')replaceAll('\\\\','') //define a JsonSlurper def jsonSlurper = new JsonSlurper().parseText(TrimResponse) //verify the slurper isn't empty assert !(jsonSlurper.isEmpty()) The Request returns an ERROR as expected but I was trying to do a string content check on the error message - seems I can't do that as it can't parse the file I guess...any help? KEEP IN MIND - I AM A NEWBIE! Error message returned by script is--> Unable to determine the current character, it is not a string, number, array, or object The current character read is 'I' with an int value of 73 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 0 Invalid CASEID: 9999999999 ^ Re: Reading Excel Data with groovy and execute request Saw this on another post - thought it might be helpful...it's something I'm about to try myself - looks pretty straightforward - 1) define the workbook where the Excel sheet is stored 2) define the sheet name In the workbook (file) as there can be many sheets to a file 3) get the number of rows and columns dynamically and store in arrays to allow to use in loop creation 4) loop through the data first by row and then within each row loop through columns 5) write out the contents of each cell based on the row/cell identifier -instead of writing out the value - assign the value of the cell to a variable and use it to drive your test -if you have this in an Excel file the date format is set by the file itself... import jxl.* Workbook workbook = Workbook.getWorkbook(new File("D:/SOAPUI/ConversionRate.xls")) Sheet sheet1 = workbook.getSheet("DataDriven") def rows = sheet1.getRows() def cols = sheet1.getColumns() log.info "Row Count =" + rows log.info "Column Count =" + cols for(i=1;i<rows;i++) { for(j=0;j<cols;j++) { Cell cell = sheet1.getCell(j,i) log.info cell.getContents() } } Hope this helped...as I said - I'm new too so ...not sure if there is a formatDate command or such you could use...anyone...? import jxl.* Workbook workbook = Workbook.getWorkbook(new File("D:/SOAPUI/ConversionRate.xls")) Sheet sheet1 = workbook.getSheet("DataDriven") def rows = sheet1.getRows() def cols = sheet1.getColumns() log.info "Row Count =" + rows log.info "Column Count =" + cols for(i=1;i<rows;i++) { for(j=0;j<cols;j++) { Cell cell = sheet1.getCell(j,i) log.info cell.getContents() } } Re: New to SoapUi and programming...can anyone tell me what "No signature of method..blah blah" means? And THAT folks...is how you answer a question! Thanks Chris - tons of info here. My problem is I am a self taught WinRunner /UFT tester who has zero classroom training on scripting of any sort, so I carried alot of expectations over to Groovy that I shouldn't - like a good built in reference manual. But hey..that's why it's free...the error messages are NOT very intuitive - as you pointed out with the split example..I thought since it showed the (string,string) that it recognized the syntax but that I needed to load a library to be able to use it...again - BOOKMARKING this answer as a reference for future stuff. I am making pretty good progress on creating an engine to automatically run my functional testing stuff - knowing the basics of the language will make it alot easier so THANK YOU! Re: New to SoapUi and programming...can anyone tell me what "No signature of method..blah blah" means? Believe it or not I figured out most of this myself BUT I think what you presented has some "cleaner and easier" ways of doing it - However, I tried the replace command just like what you have for a parenthesis and it kept telling me I couldn't split it by that - I changed my command to see if it would work with a letter instead of the parenthesis and it did work - so I was confused. I appreciate everything you did here and will save this answer off as a reference for other things later but I still have the BIG question of - if you are told that the method you are trying to use (let's forget about this specific example - I am talking generally) is not available and you know it's a valid function (in my case I am assuming they are valid as I've seen them in responses to other people's questions) - HOW do you find the library that must be loaded to allow you to use it?