cancel
Showing results for 
Search instead for 
Did you mean: 

wants to execute project from REST API Request in Test server

Occasional Contributor

wants to execute project from REST API Request in Test server

I am trying to execute a project by doing REST API Request as below, 

 

import requests
import json
import xml.dom.minidom

xml = xml.dom.minidom.parse('C:\xxx\foo.xml')
data = xml.toprettyxml()

headers = {
'access-control-allow-origin': '*',
'accept': 'application/json',
'content-type': 'application/xml',
'authorization': 'Basic xxxxxxxx',
}

params = (
('async', 'true'),
)

R = requests.post('http://testserver:8080/v1/readyapi/executions/xml', headers=headers, params=params, data=data)
print R.content
print R

 

in output i am getting,

Validation of the project failed with the following messages:
The test step DataSink has a DataSink accessing a local resource and can't be processed by the TestServer
The test step DataSink has a DataSink accessing a local resource and can't be processed by the TestServer

I found we can send a zip file to execute a project. In that zip file i can send data file. Right now, because of data file is missing. it's giving me this error. I found in documentation that, i can make this request, /readyapi/executions/composite

I don't know how to make this composite request. It's saying you will be passing zip file. but also, it's asking for the name of project file (.xml).  can't understand how to pass both,

 

I am trying this in python. I am totally new to this tool. My goal is to automate test execution and test result by REST API, integrate this with CICD process. 

 

can someone share example? how to achieve this and make successfully execution request to test server with REST API?

 

Thank you for help!

 

5 REPLIES 5
Staff

Re: wants to execute project from REST API Request in Test server

Where are you trying to execute the project from?

Generally, you would need a composite project in .zip format.You can get the appropriate project like this:

pZ9iBf5

 

Then, send a request to the /v1/readyapi/executions/composite endpoint with the project attached as binary data and application/zip content type.I do not think you need accept header generally and specify the testcase/testsuite in the request parameters.

You do not need the xml project in this case.

 

The cURL command would be:

curl --user Tester:test -H "Content-Type: application/zip" -X POST --data-binary "@c:\work\samplecompositeproject.zip" -k https://localhost:8443/v1/readyapi/executions/composite?testCaseName=TestCase1&testSuiteName=TestSuite1

 

 

P.S. If you can comment on what you found confusing or want expanded on in documentation please send me a pm or write it in this topic, because i cannot find any xml mentions in the http://readyapi.smartbear.com/testserver/howto/project/composite topic.

API Bloom
Occasional Contributor

Re: wants to execute project from REST API Request in Test server

Hi IgorG,

 

Thank you for your response. I have followed 4 steps you mentioned to export composite project and tried RestAPI Call. 


headers = {
'access-control-allow-origin': '*',
'accept': 'application/json',
'content-type': 'application/zip',
'authorization': 'Basic xxxxxxxxxxxxxxxxxx,
}

params = (
('async', 'true'),
)

data = open('C:\sampletest.zip','r')


R = requests.post('http://testserver:8080/v1/readyapi/executions/composite', headers=headers, params=params, data=data)

 

I got an error

invalid literal/lengths set (500 error)

 

------------------------

Let me explain you. I don't want to confuse you.

I have tried this first in Ready API Desktop version (SOAP UI) and it worked fine. all test run and finished successfully. Now, I am trying to setup Ready API Test server as a centralized test server and wants to request same test project. as i mentioned in first message. When i tried to request test execution with XML ( v1/readyapi/executions/xml ) but i got an error as below,

 

Validation of the project failed with the following messages:
The test step DataSink has a DataSink accessing a local resource and can't be processed by the TestServer. 

 

I got to know that this error is because of test server is not able to find Data file (excel files). But i don't know how to feed data file to test server. because with desktop version. when you import project, it imports everything by itself. how does this work with test server? can you explain me or redirect me to the documents where i can find this details?

 

Thanks again for your time!

 

Occasional Contributor

Re: wants to execute project from REST API Request in Test server

I tried with another project and i got it working. I can successfully make request to execute project. It looks like because of Data sink that project didn't work. it can be something related to security of that file or something. 

I got it working with another project. but My execution is in "Pending" state. When i made api call to check log (v1/readyapi/executions/'+executionId+'/logs') I got error message that,

Execution is pending due to missing file dependencies.
<Response [202]>

 

Then i tried to feed the excel file. by making a request,

 

from pyexcel_xls import get_data

Data = get_data('C:\Testserver\PricingAPI\PricingAPI.xls')

 

R = requests.post('http://localhost:8080/v1/readyapi/executions/'+executionId+'/files', headers=headers, params=params, data=Data)
print R.content
print R 

 

headers = {
'access-control-allow-origin': '*',
'accept': 'application/json',
'content-type': 'multipart/form-data',
'authorization': 'Basic xxxxxxxxxxxxx',
'type' : 'formData'
}

 

params = (
('async', 'true'),
)

#############################################

In response, I am getting 400 Bad request, 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 400 </title>
</head>
<body>
<h2>HTTP ERROR: 400</h2>
<p>Problem accessing /v1/readyapi/executions/a5f4f57b-6140-49f9-81ad-fc8327c511c6/files. Reason:
<pre> Bad Request</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>

---------------------------------------------------------------------------

 

can someone tell me what is wrong with my request, why it's giving 400 bad request. 

 

Any help would be appreciated!

 

Thank you.

Staff

Re: wants to execute project from REST API Request in Test server

What you should first do is call a test without a file.  So for testserver if you are sending in a SoapUI project, call:

POST /readyapi/executions/xml

 

Then that should come back with an execution ID waiting for an excel file.  Then the execution ID that came back would be appended into the follow up call:

POST /readyapi/executions/{executionId}/files

 

You can also do this with our SDKs.  That's kind of described here - http://readyapi.smartbear.com/testserver/howto/code/datasources 

Occasional Contributor

Re: wants to execute project from REST API Request in Test server

I am doing same steps as you mentioned. But it's not accepting file. its giving me Bad request 400 error when i make a request to provide a file with execution ID.  

POST /readyapi/executions/{executionId}/files

 

I have provided this part of code in my earlier reply. I can't use SDK. because i want to implement this code in python. 

 

can you please take a look in my code, why it's throwing 400 bad request error? 

 

Thank you!

 

New Here?
Join us and watch the welcome video: