How to set the header as content-type and authentication for robotframework
*** Variables ***
${PORT} 36504
${HOST} https://staging-product..co/api/products
${HeaderName} Content-Type
${HeaderValue} application/json
${HeaderName1} Authorization
${HeaderValue1} Token token=zkzg1VPnhcMm7uv,email=cctest7#gmail.com
*** Settings ***
Resource variables.txt
Library HttpLibrary.HTTP
Test Setup Create HTTP Context ${HOST} https
*** Test Cases ***
Set Headers
POST https://staging-product..co/api/products
Full-URL GET to MytestSsite
GET https://staging-product.connect.co/
Taken from the HTTP Library Documentation (https://peritus.github.io/robotframework-httplibrary/HttpLibrary.html)
Set Request Header | header_name, header_value |
Sets a request header for the next request.
header_name is the name of the header, e.g. User-Agent header_value is the key of the header, e.g. RobotFramework HttpLibrary (Mozilla/4.0)
A further simple example would be:
Set Request Header Content-Type application/json
or using your variables above:
Set Request Header ${HeaderName} ${HeaderValue}
Here is a full example:
Create HTTP Context ${HOST} http
${Request_Body} Get File ${xmlFilename} encoding=${Request_Body_Encoding}
Set Request Header ${HeaderName} ${HeaderValue}
Set Request Body ${Request_Body}
Log ${Request_Body}
POST ${URL}
Response Status Code Should Equal ${ResponseStatusCode}
Related
The 'dummy.restapiexample.com' site provides a nice demo REST service. Retrieving data is simple in Robotframework via de Request library.
Creating a body with dictionaries works! When I use JSON bodies, I get these errors.
Test 1: POST to reqres.in gives http status: 400
*** Settings ***
Library RequestsLibrary
*** Variables ***
${RestApiB} = https://reqres.in
*** Test Cases ***
Create a new user
Create Session restSession ${RestApiB}
${jsonString} = To Json {"name":"jjxx","job":"devxx"}
${headers} = Create Dictionary Content-Type=application/json
${response} = Post Request restSession /api/users json=${jsonString} headers=${headers}
Should Be Equal As Strings ${response.status_code} 201
I want to have a conditional header based on a header I want to get from the upstream.
For some reason it always gets translated to default.
Configuration:
upstream service decides if a header called x-no-iframe-protection should exist.
main nginx:
map $http_x_no_iframe_protection $x_frame_options {
yes "";
default "SAMEORIGIN";
}
server {
...
add_header X-Frame-Options $x_frame_options;
...
}
No matter what I try - I get both headers:
$ curl -v myhost
...
< x-no-iframe-protection: yes
< x-frame-options: SAMEORIGIN
...
Just to clarify - I use the x-no-iframe-protection just as a trick to remove x-frame-options in specific cases. I'm OK with it staying (although it is not needed once parsed by nginx)
Anyways - how can I make it get caught in order to replace the header value?
An HTTP transaction contains request headers and response headers. From the context of your question you are setting the value of a response header based on the value of another response header (which was received from upstream).
Nginx stores request headers in variables with names beginning with $http_ and response headers in variables with names beginning with $sent_.
In addition, response headers received from upstream may also be stored in variables with names beginning with $upstream_http_.
In your configuration you use the variable $http_x_no_iframe_protection, whereas you should be using either $sent_x_no_iframe_protection or perhaps $upstream_http_x_no_iframe_protection.
All of the Nginx variables are documented here.
try using $upstream_x_no_iframe_protection to access upstream response header.
I am trying to implement soap calls testing through Robot framework.Tried various solutions that I could find on google, nothing works.
The same is working when I am testing through SOAP UI. Am I missing something , I am not sure.
new test
[Tags] abcd
Add Doctor Import http://schemas.xmlsoap.org/soap/encoding/
&{headers}= Create Dictionary Content-Type text/xml SOAPAction "" Host bfx-b2b....
${auth}= Create List Test Password3#
Create Session getPlans https://bfx-b2b.../wsdl/ProductService.wsdl auth=${auth} verify=True
${file_data}= Get Binary File ${CURDIR}/request.xml
Log ${file_data}
${byte_string}= Encode String To Bytes ${REQUEST} UTF-8
${resp}= Post Request getPlans https://bfx-b2b..../B2BWEB/services/IProductPort data=${byte_string} headers=${headers}
Log ${resp.text}
Log ${resp.status_code}
I am getting below 500 error in response.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
ESS_eBiz_Operations#uhc.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
Few Soap UI details -
Endpoint that I am hitting on SOAP UI -https://bfx-b2b.../B2BWEB/services/IProductPort
Raw data -
POST https://bfx-b2b.../B2BWEB/services/IProductPort HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 1822
Host: bfx-b2b...
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Cookie: SMCHALLENGE=YES
Cookie2: $Version=1
Authorization: Basic V2VsbHRoaWVfVGVzdDpQYXNzd29yZDMj
See if this example will help you:
*** Settings ***
Documentation Test with SOAP (WSDL) with two parameters that returns the country passing the IP
Library SudsLibrary
*** Variables ***
${ip} 150.162.2.1
*** Test Cases ***
ConsultaIP
Create Soap Client http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl
${result} Call Soap Method ResolveIP ${ip} null
${country} Get Wsdl Object Attribute ${result} Country
${Latitude} Get Wsdl Object Attribute ${result} Latitude
${Longitude} Get Wsdl Object Attribute ${result} Longitude
log The IP ${ip} belongs to the country ${country}, Latitude: ${Latitude} Longitude: ${Longitude}
I'm trying to get the response header that named com.coradiant.appvis in robot framework
there are no resources that can help ,, this is my code
*** Settings ***
Library HttpLibrary.HTTP
Test Setup Create HTTP Context ${HOST}
*** Variables ***
${PORT} 80
${HOST} http://vw-tlv-idnqa31${PORT}/EventsApps/EventsApps/WebForm.aspx
${APPVIS_HEADER}
*** Test Cases ***
Checking Appvis test
Get the appvis response header
*** Keywords ***
Get the appvis response header
${APPVIS_HEADER} = get response header com.coradiant.appvis
Log ${APPVIS_HEADER}
You must make a request before you can get the header. You can use the GET keyword to make the request, assuming you need the headers for a GET request.
below is the begining of a script for testing a rest interface on a device , this device has a https server with Digest Authentication.
This is where i am encountering a problem below I have it set up I do not get an error so i assume
Set Digest Auth admin secret is valid
if it is what can I not authenticate:
#script
*** Settings ***
Resource variablesreal.txt
Library HttpLibrary.HTTP
Library PycURLLibrary
Library OperatingSystem
Test Setup Create HTTP Context ${HOST} https
*** Variables ***
${HEADER1} Content-Type: text/xml; charset=UTF-8
*** Test Cases ***
Set Digest Auth
Log Variables
Verbose
Add Header ${HEADER1}
Add Header version:1
Next Request Should Not Succeed
GET https://${HOST}/views
Set Digest Auth admin secret
GET https://${HOST}/views
Response Status Code Should Equal 200
Response Body Should Contain views
Log Response Status
Log Response
here is the out put from pybot hls.txt
==============================================================================
Hls
==============================================================================
Set Digest Auth | FAIL |
Request should have succeeded, but was "401 Unauthorized".
------------------------------------------------------------------------------
Hls | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: /home/robm/code/BDD/pycurl/hl/output.xml
Log: /home/robm/code/BDD/pycurl/hl/log.html
Report: /home/robm/code/BDD/pycurl/hl/report.html
any ideas on Digest authentication?
I ended up adding this to RequestKeywords.py
def create_digest_session(self, alias, url, auth, headers={}, cookies=None, timeout=None, proxies=None, verify=False):
""" Create Session: create a HTTP session to a server
`url` Base url of the server
`alias` Robot Framework alias to identify the session
`headers` Dictionary of default headers
`auth` List of username & password for HTTP Digest Auth
`timeout` connection timeout
`proxies` proxy server url
`verify` set to True if Requests should verify the certificate
"""
digest_auth = requests.auth.HTTPDigestAuth(*auth) if auth else None
return self._create_session_local(alias, url, headers, cookies, digest_auth, timeout, proxies, verify)