I'm trying to build a SOAP request with Groovy/Java.
However, I didn't found any information on web and on Katalon documentation.
There is a lot of documentation for REST testing, but not for SOAP ...
https://docs.katalon.com/katalon-studio/docs/create_rest_api_requests_manually.html#introduction
https://docs.katalon.com/katalon-studio/docs/web-services-builder.html
https://api-docs.katalon.com/
My objective is to do something like :
// THIS CODE IS WRONG !!!! It's just to give you an idea of my need
RequestObject requestObject = new SOAPRequestBuilder()
def variables = new HashMap<String, String>()
variables.put('variable', 'some text')
requestObject.setVariables(variables)
def response = WS.sendRequest(requestObject)
Someone has any idea how to do that? Thank you for help.
Update 1
I found this solution but I don't know if it is a best pratice ...
def request = findTestObject('RequestObject', [('variable') : 'some text'])
def response = WS.sendRequest(request)
If you're looking for something product-agnostic, you could use groovy-wslite, which handles both REST and SOAP. For example:
def client = new SOAPClient("http://...")
def response = client.send(SOAPAction: ...) {
body {
...
}
}
Related
SoapUI. I have a pretty old version of SoapUI (version 2.0.2)
We know in Soapui, we can present Alert, and input Dialogs..
Which work great..
I have the following SOAP Response and would like to read the question to present as a dialog.
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:Response xmlns:ns1="http://some.name.space.com">
<ns1:payload>
<ns1:Question>
<ns1:questionText>How much is that doggie in the window?</ns1:questionText>
</ns1:Question>
</ns1:payload>
</ns1:Response>
</soapenv:Body>
</soapenv:Envelope>
I would like to read or present the "questionText" to the tester..
def ui = com.eviware.soapui.support.UISupport;
ui.showInfoMessage("Hello World");
But, instead read the question (the questions do change) and to be something like:
def ui = com.eviware.soapui.support.UISupport;
ui.showInfoMessage("testStep.xmlResponse.questionText");
And then have where the tester can input their answer..
def ui = com.eviware.soapui.support.UISupport;
ui.prompt("Input Answer","Answer");
Thanks for the information at - Can I pause for console input in a SOAPUI groovy script?
Here is what I have been able to find so far on this (which does not work at this point):
// pulled information from:
// http://www.soapui.org/Developers-Corner/extending-soapui.html
import com.eviware.soapui.support.XmlHolder;
def ui = com.eviware.soapui.support.UISupport;
def holder = new XmlHolder ( messageExchangeContentAsXml)
holder.namespaces["ns1"] = "http://some.name.space.com"
def node = holder.getDomName ("//ns1:Response[1]/ns1:payload[1]/ns1:Question[1]/ns1:questionText[1]")
ui.showInfoMessage(node.questionText);
The error that I am getting at this point is:
org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: messageExchangeContentAsXml for class: Script12
And I think I should be able to "pass" that on to the next request fairly easily.
Thanks.
I have figured this out..
http://www.soapui.org/Developers-Corner/extending-soapui.html
http://www.soapui.org/Scripting-Properties/tips-a-tricks.html
http://forum.soapui.org/viewtopic.php?t=2597
Reading from properties, we need the following:
def ui = com.eviware.soapui.support.UISupport;
groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def propId = context.getProperty( "userName", "userName" );
ui.showInfoMessage( propId );
Reading from the Response in SOAPUI, we need to do the following:
def ui = com.eviware.soapui.support.UISupport;
groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
holder = groovyUtils.getXmlHolder("TestRequest#Response");
holder.namespaces["ns1"] = "http://some.namespace";
def responseId = holder.getNodeValue("//ns1:userName");
ui.showInfoMessage( responseId );
I have code like:
https://gist.github.com/daaatz/7665224
but dont know how to test request.
Trying mydomain/secured?user=John&password=p4ssw0rd etc but nothing works.
Can some one tell me or show example in js+html how to check is it working fine ?
Thanks
I've never used BasicAuth in Spray, so i'm not sure if this would be the complete answer, but i hope this will help you.
At first. in spray there is a great spray-testkit written on top of akka testkit. You should definitely check out SecurityDirectives test on github, this will show you how to test basic authentication. A little example, to make this simpler:
As for your route example, i would better edit to the following one:
val myRoute =
(path("secured") & get) {
authenticate(BasicAuth(myUserPassAuthenticator _, realm = "secure site")) {
userName => complete(s"The user is '$userName'")
}
}
}
Adding get directive will specify that this route expects a Get request and sealRoute is obsolete cause RejectionHandler and ExceptionHandler are provided implicitly with runRoute. It is used only in tests, if you want wo check exceptions/rejections.
Now in your tests you should construct auth entities, similar to the test one:
val challenge = `WWW-Authenticate`(HttpChallenge("Basic", "Realm"))
val doAuth = BasicAuth(UserPassAuthenticator[BasicUserContext] { userPassOption ⇒
Future.successful(Some(BasicUserContext(userPassOption.get.user)))
}, "Realm")
And you test case:
"simple auth test" in {
Get("security") ~> Authorization(BasicHttpCredentials("Alice", "")) ~> {
authenticate(doAuth) { echoComplete }
} ~> check { responseAs[String] === "BasicUserContext(Alice)" }
}
In Get("security") specifies that your test will send a Get request on "/security", then add Authorization to the test request, some action and the check part to test the request.
I've never tried to test BasicAuth, so there could be some mistakes.
I would look into CURL for testing routes in web applications, but I've also used the chrome extension Postman with great results as well.
I've to make a new Component in JIRA
I found out the POST url /rest/api/2/component for making new component, but i'm unable to know what type of inputs to be given.
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://localhost:8080/rest/api/2/component/");
String authorization = JiraRequestResponseUtil.conversionForAuthorization();
postRequest.setHeader("Authorization", authorization);
StringEntity input = new StringEntity("\"name\":\"Component 1\",\"description\":\"This is a TEST JIRA component\" ,\"leadUserName\":\"fred\",\"assigneeType\":\"PROJECT_LEAD\",\"isAssigneeTypeValid\":\"false\",\"project\":\"TEST\"");
input.setContentType("application/json");
postRequest.setEntity(input);
HttpResponse response = httpClient.execute(postRequest);
this is the code i'm implementing.
Output i'm getting is Failed : HTTP error code : 400
Plz help.
we can't tell you. You need to find documentation on the service you are posting to.
The above code is correct, just add the { & } to the JSON string.
I'm trying to download the response of an HTTP GET request as an Array[Byte] in Scala using dispatch, but the documentation is not helping and online searches didn't turn out to be helpful.
Additionally, I need to retrieve the value of a header in the response.
Could anyone please provide a working snippet, possibly with a custom header?
Thanks in advance!
Came up with my own way:
val (someHeaderVal, buf) = Http x (url(fileUrl) <:< Map("ACustomHeader" -> "MyValue") >:+ {
(headers, req) => req >> {
stream => (headers("ResponseCustomHeader").head, IOUtils.toByteArray(stream))
}
})
This seems to work just fine.
I want to test my secured webservice to the following:
UrlMapping correct, so are the following services available or not?
Test GET/POST/PUT/DELETE and their rendered feedback as well as errors
Test error messages when logged in and not logged in
Can somebody give me some hints how to do this? I have no clue how accessing the grails security service and as well running tests against my controllers when logged in and when not. As well I need some Mock Server or something to test against my controllers or?
Sorry I am very new to this topic but I want to go in the right direction before loosing control over my webservices.
Thank you for your help!
We use the REST Client plugin along with the functional testing plugin to test all our web services.
For example...
void testCreateTag() {
def name = 'Test Name'
def jsonText = """
{
"class":"Tag",
"name":"${name}"
}
"""
post('/api/tag') {
headers['x-user-external-id'] = securityUser.externalId
headers['x-user-api-key'] = securityUser.apiKey
headers['Content-type'] = 'application/json'
body {
jsonText
}
}
def model = this.response.contentAsString
def map = JSON.parse(model)
assertNotNull(map.attributes.id)
Tag.withNewSession {
def tag = Tag.get(map.attributes.id)
assertNotNull(tag)
assertEquals(name, tag.name)
}
}
I have similar code which uses the built in (groovy 1.8) JsonSlurper which I think might be more reliable and only needs the functional test plugin but not the REST Client plugin.
String baseUrlString = 'http://localhost:8080/**YOURAPP**'
baseURL = baseUrlString
post('/j_spring_security_check?')
assertStatus 200
assertContentDoesNotContain('Access Denied')
get("/*your test URL*/")
def jsonObj = new JsonSlurper().parseText(this.response.contentAsString)
assertEquals(jsonObj.your.object.model, **yourContent**)