Export result in text file by SoapUI - api

I am using dotmailer.com ESP and using SoapUI for calling API. I can get summary of the campaign in JSON format but also I want to extract summary of that campaign into a text file but couldn't find any way. Anyone can help?
Thanks.

You can do it using groovy. Simple add a groovy script testStep inside your testCase, there you can get the response from a previous testStep and save in a file. Since there are not many details in your question a generic way to do so could be:
// get the test step
def testRequest = context.testCase.getTestStepByName('Test Request')
// get the response
def response = testRequest.getPropertyValue('Response')
// create a file
def file = new File('C:/temp/response.txt');
// save the response to it
file << response
Hope it helps,

Related

Karate / Post Request : Unable to pass random generator variable in json payload

I am trying to create Karate feature file for API Testing.
It is a post request and we have to pass random number for 1 field i.e. order in request payload every time.
Now, I am trying to use this function in the same feature file to pass that random generated value in json payload before sending post request.
Could someone please have a look at my feature file and help.
Thanks
Also, Is there a way if i want to pass this same random value for a json payload created as a separate request.json payload file
Your requestPayload is within double quotes, so it became a string.
Here's an example that should get you going. Just paste it into a new Scenario and run it and see what happens.
* def temp1 = 'bar'
* url 'https://httpbin.org/anything'
* def payload = { foo: '#(temp1)' }
* request payload
* method post
And please read the documentation and examples, it will save a you a lot of time.

How to pass karate.prevRequest and response are the arguments from one feature file to another feature file

I wanted to pass karate.prevRequest and response are the arguments to another feature
Background:
* def KLog = Java.type('com.support.KaratePrint')
#SmokeTest
Scenario: Fetch random quote
* print 'My method executed' +KLog.scenarioInfo('Scenario_1', tcDetails.Scenario_1)
Given path '/api/users/'+pageNo.Pageno
When method GET
Then status 200
Here I wanted to pass KLog, Karate.prevRequest and response are the arguments to another feature
The documentation is
https://github.com/intuit/karate#calling-other-feature-files
The example file is
https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/callfeature/call-feature.feature
Please see the other files in the directory
https://github.com/intuit/karate/tree/master/karate-demo/src/test/java/demo/callfeature

How to passing json parameters for test api (restful) in katalon studio?

I created a demo test using reqres.in fake data API.
I want to create a user with a name and a job parameter, but the data format required is json.
In my Katalon test I tried to do that in the script tab:
My parameters are not sent to the API...
I didn't find how to do that in Katalon Studio (5.7) and I don't know if it's possible to do that.
Finally, i 've found a solution, for exemple i want to get a new token with a refresh_token_key, and send it in json format and modify my request object.
I get my refresh_token_ken, put it in a string variable, get my request object and modify the body like this :
RequestObject roRefresh_Token = findTestObject('Authentication/Refresh Token');
def jsonStr = "{'RefreshToken':'"+GlobalVariable.Refresh_Token+"'}";
roRefresh_Token.setBodyContent(new HttpTextBodyContent(jsonStr, "UTF-8", "application/json"));
WS.sendRequest(roRefresh_Token)
You didn't add parameters to the REST object.
Click the + Add button shown in the screenshot and add the following to the parameter table:
Name | Value
--------------------
name | ${name}
job | ${job}
That will change your request to https://reqres.in/api/users?name=${name}&job=${job} so when you send the request as you did in the OP, Ema and developer will go to the place of the placeholders for name and job.

How to pass a json file as a value for a key under request body of a feature file

enter image description hereI am creating a feature file using Karate framework and as per that i need to pass a json file as key value pair in the request body
eg
Given url
And def textJson = text1
And request{test:'test1.json',test2:'description text'}
when post
then status 200
enter image description here
the json file is read into a variable in another feature file and passed on to this feature file.
As of now i am getting the requested file is missing basically its not reading
Given url
And def textJson = text1
And request{test:'test1.json',test2:'description text'}
So if I understand this correctly, you intend to input the data from a json file into the test key under request. You are currently passing in a string instead of actually reading in a file. To read in a json file and save it as a variable try the following syntax.
And def test1 = read('test1.json')
And request { test1: '#(test1)'}
I am a little confused at some of the other syntax you have included. I can point out a couple other problems in the syntax.
Given url #You need to actually have a url after the url keyword
And def textjson = test1 #This does not seem to point to a reference
And request {test: 'test1.json', test2: 'description text'} # The test is not actually reading json in but the string "test1.json"
I wasn't exactly sure the scope of this question, but I hope that this helps.

karate | xml post method exeuction

I’m having issue with xml post request where post method is not executed. When I try to post same request body in post man it worked.My test is success with 200 but actual request is not executed.
Please let me know if I’m missing
To pass the request body,I’m calling through java object and payload is correctly constructed and printed.In execution test is success and doesn’t print response.But actually test is not executed.
Only headers are printed.
***************** create-user.feature*****************
Feature: create ims user for provided country
Requires country code,
Background:
# load secrets from json
* def createuser = Java.type('com.user.JavaTestData')
* def create = createuser.createUser("US")
Scenario: get service token
Given url imscreateuserurl
And request create
When method post
Then status 200
* print response
***************** create-user.feature*****************
Here is java class
public class JavaTestData {
private static final Logger logger = LoggerFactory.getLogger(JavaTestData.class);
public static String createUser(String countryCodeInput) {
logger.debug("create user for country code input", countryCodeInput);
Unless you post a full working example, no one can help you. Pretty clear that the value of create is null or empty.
Also I personally think you are wasting your time using Java. The whole point of Karate is to avoid using Java as far as possible.
Look at these examples for ideas: https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/xml/xml.feature
Edit: also refer to the doc on type-conversion: https://github.com/intuit/karate#type-conversion
#Peter, here is my feature file
Feature: create ims user for provided country
Requires country code,
Background:
# load secrets from json
* def createuser = Java.type('com.adobe.imscreateuser.JavaTestData')
* def create = createuser.createUser("US")
Scenario: get service token
Given url imscreateuserurl
And header Content-Type = 'application/xml; charset=utf-8'
And request create
When method post
Then status 200
* print response
I have performed print for create and showing complete payload.At when method post -> statement its going as null or empty...
Not sure where it is missing