I have a spreadsheet where each row contains a SOAP request, concatenated from the data in that row. So cell G2 is a SOAP request, cell G3 is a different SOAP request, cell G4 is another SOAP request and so on. I've looked to see what is the best method for transferring those 100+ SOAP requests into SoapUI (free version) and running them all in one batch. I've not found anything that gives me the full working solution yet. Could someone suggest the best method please? Thanks in advance!
I won't tell you how to do it, but I can tell you how I did it. Concatenating XML in Excel is messy and error-prone, especialy if you have less-technical people writing the test cases. I asked for the data (parameters) in Excel.
I wrote a Groovy script that gets the data (there's a nice script that abstracts it for you), and for each test case, saved the values as properties:
new ExcelBuilder("data/MyRegressionSheetV1.2.xls").eachLine([labels:true]) { row ->
Map payLoad = [:]
if (cell(0)) {
payLoad['MyName'] = cell(0)
payLoad['MySurname'] = cell(1)
//and so on
payLoad['ExpectedResult'] = cell(12)
testRunner.testCase.testSuite.project.setPropertyValue("Name", payLoad['MyName'])
testRunner.testCase.testSuite.project.setPropertyValue("Surname", payLoad['MySurname'])
//and so on
def MyScenario = testRunner.testCase.testSuite.testCases["SOAP Request1"].run( null, true )
then made the SOAP requests with parameterised values:
<parm:Name>${#Project#Name}</parm:Name>
<parm:Surname>${#Project#Surname}</parm:Surname>
//and so on
While in the loop, you can get the response values and if you have expected results, you can compare them programmatically:
def responseSOAP = context.expand('${SOAP Request1#Response}')
def responseSection = responseSOAP =~ /requestAnswer>(.*)<\/requestAnswer/
def response = responseSection[0][1]
if (response.equals(payLoad['ExpectedResult'])) {
testResult = 'Pass'
}
}
Opensource SoapUI is very capable, and Groovy is a very cool programming language. A lot is possible once you get your head around how they work together.
EDIT:
If you want to replace the entire request, you can access it with the XmlHolder:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//this gets a handle on the current request XML
def oldHolder = groovyUtils.getXmlHolder( 'SOAP Request1#Request' )
//your String XML from the spreadsheet must be parsed into XML
def newHolder = new XmlSlurper().parseText(MyXMLFromSheetAsString)
//replace
context.requestContent = newHolder.xml
Related
I want to use the requests.post tool to automatically query domain name attribution on this websitea website,But the return value is always empty, I guess it is because the post method failed to transfer the data to the textarea
url = 'http://icp.chinaz.com/searchs'
data = {
'hosts':'qq.com',
'btn_search':'%E6%9F%A5%E8%AF%A2', '__RequestVerificationToken=':'CfDJ8KmGV0zny1FLtrcRZkGCczG2owvCRigVmimqp33mw5t861kI7zU2VfQBri65hIwu_4VXbmtqImMmTeZzqxE7NwwvAtwWcZSMnk6UDuzP3Ymzh9YrHPJkj_cy8vSLXvUYXrFO0HnCb0pSweHIL9pkReY',
}
requests.post(url=url,data=data,headers=headers).content.decode('utf-8')
I'd be very grateful if you could point out where I'm going wrong
I have tried to replace headers and so on.
I have a Google Spreadsheet with internal AppsScript code which process each row of the sheet and perform an urlfetch with the row data. The url will provide a value which will be added to the values returned by each row processing..
For now the code is processing 1 row at a time with a simple for:
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
var range = sheet.getDataRange();
for(var i=1 ; i<range.getValues().length ; i++) {
var payload = {
// retrieve data from the row and make payload object
};
var options = {
"method":"POST",
"payload" : payload
};
var result = UrlFetchApp.fetch("http://.......", options);
var text = result.getContentText();
// Save result for final processing
// (with multi-thread function this value will be the return of the function)
}
Please note that this is only a simple example, in the real case the working function will be more complex (like 5-6 http calls, where the output of some of them are used as input to the next one, ...).
For the example let's say that there is a generic "function" which executes some sort of processing and provides a result as output.
In order to speed up the process, I'd like to try to implement some sort of "multi-thread" processing, so I can process multiple rows in the same time.
I already know that javascript does not offer a multi-thread handling, but I read about WebWorker which seems to create an async processing of a function.
My goal is to obtain some sort of ThreadPool (like 5 threads at a time) and send every row that need to be processed to the pool, obtaining as output the result of each function.
When all the rows finished the processing, a final action will be performed gathering all the results of each function.
So the capabilities I'm looking for are:
managed "ThreadPool" where I can submit an N amount of tasks to be performed
possibility to obtain a resulting value from each task processed by the pool
possibility to determine that all the tasks has been processed, so a final "event" can be executed
I already see that there are some ready-to-use libraries like:
https://www.hamsters.io/wiki#thread-pool
http://threadsjs.readthedocs.io/en/latest/
https://github.com/andywer/threadpool-js
but they work with NodeJS. Due to AppsScript nature, I need a more simplier approach, which is provided by native JS. Also, it seems that minified JS are not accepted by AppsScript editor, so I also need the "expanded" version.
Do you know a simple ThreadPool in JS where I can submit a function to be execute and I get back a Promise for the result?
I am currently using Flask to create a website and have come across an interesting issue. There is some code that gives the user the option to input a value in for about 20 separate input fields. What I am trying to do is construct a button that would allow the user to paste in a column from an Excel table. Essentially, a button that will look at the clipboard, take the field, convert the string into an array, and place the values into each input in the order they appear in the list.
So far, I have been able to get the clipboard into a string using tk.Tk().clipboard_get(), and believe that I can get this value by making an XMLHttpRequest, but have had little luck in making it actually work.
Some code for what I am trying to accomplish:
Python:
#app.route('/some/path/here', methods = ['GET'])
def paste():
try:
values = tk.Tk().clipboard_get()
values = values.replace('\n',',')
return values
except:
return None
HTTP:
<button type="button" style="float: right" onclick="Testing()">Paste</button>
<p id="textHere"></p>
JavaScript:
<script>
function Testing() {
var wvpst = new XMLHttpRequest();
wvpst.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200) {
var list = this.responseXML;
// list = list.replace(/'/g,"").replace(/ '/g,"");
// list = list.split(", ");
document.getElementById("textHere").innerHTML = list;
}
}
wvpst.open("GET","{{ url_for('paste') }}",true);
wvpst.send();
}
</script>
For now, I am just trying to get the list of values copied from an Excel sheet, but nothing is being returned when the button is pressed. Am I simply using XMLHttpRequest incorrectly or is there something else I need to do to get this to work?
Set a debug breakpoint inside
if (this.readyState == 4 && this.status == 200) {
}
and inspect your response. Set another on the first line of your function in Flask. Those should give you visibility into where the breakdown is.
A few other, perhaps more important notes:
Point 1) In your flask try/except, on failure you should serve a response, just a 500 response. Replace return None with:
return app.make_response('Couldn't parse clipboard information!'), 500
Point 2) There is no need to pass this information to your server for processing. You can accomplish this within the javascript of the front end and save your server some processing and your client some time waiting on an HTTP response.
Have the user paste their content into a textbox or another element, and then access the value from there.
Direct clipboard access isn't something most browsers give up freely, and so best to avoid that route.
Summary:
Your xmlhttprequest looks fine to me. I would guess that your try in flask is failing and returning something useless if anything at all.
Do this in javascript.
How can I grab all the text in a website, and I don't just mean ctrl+a/c. I'd like to be able to extract all the text from a website (and all the pages associated) and use it to build a concordance of words from that site. Any ideas?
I was intrigued by this so I've written the first part of a solution to this.
The code is written in PHP because of the convenient strip_tags function. It's also rough and procedural but I feel in demonstrates my ideas.
<?php
$url = "http://www.stackoverflow.com";
//To use this you'll need to get a key for the Readabilty Parser API http://readability.com/developers/api/parser
$token = "";
//I make a HTTP GET request to the readabilty API and then decode the returned JSON
$parserResponse = json_decode(file_get_contents("http://www.readability.com/api/content/v1/parser?url=$url&token=$token"));
//I'm only interested in the content string in the json object
$content = $parserResponse->content;
//I strip the HTML tags for the article content
$wordsOnPage = strip_tags($content);
$wordCounter = array();
$wordSplit = explode(" ", $wordsOnPage);
//I then loop through each word in the article keeping count of how many times I've seen the word
foreach($wordSplit as $word)
{
incrementWordCounter($word);
}
//Then I sort the array so the most frequent words are at the end
asort($wordCounter);
//And dump the array
var_dump($wordCounter);
function incrementWordCounter($word)
{
global $wordCounter;
if(isset($wordCounter[$word]))
{
$wordCounter[$word] = $wordCounter[$word] + 1;
}
else
{
$wordCounter[$word] = 1;
}
}
?>
I needed to do this to configure PHP for the SSL the readability API uses.
The next step in the solution would be too search for links in the page and call this recursively in an intelligent way to hance the associated pages requirement.
Also the code above just gives the raw data of a word-count you would want to process it some more to make it meaningful.
I'm getting a text which contains ${somethingElse} inside, but it's just a normal String.
I've got a class:
class Whatever {
def somethingElse = 5
void action(String sth) {
def test = []
test.testing = sth
assert test.testing == 5
}
}
Is it possible with groovy?
EDIT:
my scenario is: load xml file, which contains nodes with values pointing to some other values in my application. So let's say I've got shell.setVariable("current", myClass). And now, in my xml I want to be able to put ${current.someField} as a value.
The trouble is, that the value from xml is a string and I can't evaluate it easily.
I can't predict how these "values" will be created by user, I just give them ability to use few classes.
I cannot convert it when the xml file is loaded, it has to be "on demand", since I use it in specific cases and I want them to be able to use values at that moment in time, and not when xml file is loaded.
Any tips?
One thing you could do is:
class Whatever {
def somethingElse = 5
void action( String sth ) {
def result = new groovy.text.GStringTemplateEngine().with {
createTemplate( sth ).make( this.properties ).toString()
}
assert result == "Number 5"
}
}
// Pass it a String
new Whatever().action( 'Number ${somethingElse}' )
At first, what we did, was used this format in xml:
normalText#codeToExecuteOrEvaluate#normalText
and used replace closure to regexp and groovyShell.evaluate() the code.
Insane. It took a lot of time and a lot of memory.
In the end we changed the format to the original one and crated scripts for each string we wanted to be able to evaluate:
Script script = shell.parse("\""+stringToParse+"\"")
where
stringToParse = "Hello world # ${System.currentTimeMillis()}!!"
Then we were able to call script.run() as many times as we wanted and everything performed well.
It actually still does.