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.
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 am now trying to use SSHLibrary to ssh into a virtual router running on my PC and execute a simple ping test on the router and then present the result of the test case.
I can login to the router and also execute the command outside of the robotframework, but when I try to do this using robotframework I get a fail with an error message and not sure how i solve for this error message:
Here is my robotframework test script:
*** Settings ***
Library SSHLibrary
Suite Setup Open Connection And Log In
Suite Teardown Close All Connections
*** Variable ***
${HOST} 172.31.1.250
${USERNAME} admin
${PASSWORD} admin
*** Keywords ***
Open Connection And Log In
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
*** Test Cases ***
Ping test
${output} = Execute Command ping 1.1.1.1
Should Contain ${result.stdout} 64 bytes from 1.1.1.1
Here is the output I get when I execute the above test case:
==============================================================================
Sros
==============================================================================
Ping test | FAIL |
ChannelException: (1, 'Administratively prohibited')
------------------------------------------------------------------------------
Sros | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
What is this error message and how do I solve this:
**ChannelException: (1, 'Administratively prohibited')**
Does it matter what type of the router that I am login into is?
Thanks for your help.
Based on the feedback I have changed from Execute Command to Write.
So my script looks like this now:
*** Settings ***
Library SSHLibrary
Suite Setup Open Connection And Log In
Suite Teardown Close All Connections
*** Variable ***
${HOST} 172.31.1.250
${USERNAME} admin
${PASSWORD} admin
*** Keywords ***
Open Connection And Log In
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
*** Test Cases ***
Ping test
${result} = Write ping 1.1.1.1 count 1
Should Contain ${result.stdout} 64 bytes from 1.1.1.1
But now I get following error message:
==============================================================================
Sros
==============================================================================
Ping test | FAIL |
Resolving variable '${result.stdout}' failed: AttributeError: 'str' object has no attribute 'stdout'
------------------------------------------------------------------------------
Sros | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Also not I have checked using Wireshark that robot script does actually ssh into the router and establish a ssh session. I think the connectivity part of working fine.
Consider using
Write ping 1.1.1.1
${output}= Read delay=0.5s
to get the output in a var. It will now have the same behavior you have while doing it manually !
I hope it will help you ;)
How ti create session with AUTH and Headers using Robot framework?
I tried the below code:
*** Variables ***
${user} ='user1api'
${passwd} ='password!'
&{headers} Content-Type=application/json Authorization=Basic ABCDEF==
*** Keywords ***
DO Status Get API
${auth}= Create List user passwd
Create Session DOStatus https://test.abc.com/api/status/7661/job headers=${headers} auth=${auth}
${resp}= Get Request DOStatus /basic-auth/user/passwd
and ran into this error:
TypeError: __init__() takes exactly 3 arguments (2 given)
*** Settings ***
Library String
Library Collections
Library Selenium2Library
Library RequestsLibrary
*** Variables ***
${user} = user1api
${passwd} = password!
&{headers} Content-Type=application/json Authorization=Basic ABCDEF==
*** Keywords ***
Get DO Status API
${auth}= Create List ${user} ${passwd}
Create Session alias=DOStatus url=https://test.abc.com/api/status/7661/job headers=${headers} auth=${auth}
${resp}= Get Request DOStatus /
Should Be Equal As Strings ${resp.json()['transaction']['status']} success
Should Be Equal As Strings ${resp.status_code} 200
If you are using basic auth, you need to pass a tuple, assuming you are using the requests library.
If you are importing variables from a .yaml file, I think you could remove my Convert To Boolean and Evaluate keywords
The code:
*** Settings ***
Library requests
*** Variables ***
${user}= "test_user"
${pass}= "test_pw"
${url}= https://special.domain/some/api/endpoint
&{headers}= content-type=application/json accept=application/json
*** Keywords ***
api check test
${false}= Convert To Boolean False
${user_pass}= Evaluate (${user}, ${pass},)
${resp}= Get ${url} auth=${user_pass} headers=${headers} verify=${false}
Log To Console ${resp.status_code}
The result:
Api Validation :: API Validation
==============================================================================
Test API
...<warning goes here>...
200
Test API | PASS |
------------------------------------------------------------------------------
Api Validation :: API Validation | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
I think the reason the OP's code didn't work as expected was because of the single missing space when setting the auth variable and consequently producing a Python requests.auth.HTTPBasicAuth call of just (self, 'username & password') rather than (self, 'user', 'password'). The constructor signature expects __init__(self, username, password) . This can be fixed by simply adding a single space to the original code which instructs RobotFramework to consider the variables as 2 separate values in the list. See the difference between the assign of auth_bad and auth_good in the code below.
*** Settings ***
Library RequestsLibrary
*** Variables ***
${user} ='user1api'
${passwd} ='password!'
&{headers} Content-Type=application/json Authorization=Basic ABCDEF==
*** Keywords ***
DO Status Get API
${auth_bad}= Create List user passwd
Log To Console A bad authentication variable: ${auth_bad}
${auth_good}= Create List user passwd
Log To Console A good authentication variable: ${auth_good}
Create Session DOStatus https://192.168.1.254/api/status/7661/job headers=${headers} auth=${auth_good}
${resp}= Get Request DOStatus /basic-auth/user/passwd
*** Task ***
Basic Task
DO Status Get API
I have the same problem as you and I solved it.
I remove the headers in Create session.
You can refer my source:
Variables
${jira_url} https://example.com
${jira_user} user1
${jira_password} password1
Test Cases
Get All Testcase Of SC Project
${auth}= Create Dictionary ${jira_user} ${jira_password}
Create session alias=Get_Jira_Request url=${jira_url} auth=${auth}
${response}= Get Request Get_Jira_Request /rest/atm/1.0/testcase/search?query=projectKey%20=%20%22SC%22
Even I struggled for one day to figure it out.
Define:
&{dict} accept=text/plain Authorization=Basic
#{auth} ${user} ${pwd}
If we use Create List/ Create Dictionary, it does not work.
#{auth} Create list ${user} ${pwd}
Create Session em url=${url} verify=false auth=${auth}
=========
*** Variables ***
${user} user1api
${passwd} password!
&{headers} Content-Type=application/json Authorization=Basic
*** Keywords ***
DO Status Get API
#{auth} ${user} ${passwd}
Create Session DOStatus https://test.abc.com/api/status/7661/job headers=${headers} auth=${auth}
I hope this will solve the problem of create session
We are trying to automate a few Test Cases which require login to a Citrix machine using Robot framework.
Could someone please help provide a sample example to automate the same.
Thanks in advance.
Regards,
-kranti
You can create a keyword for Login into Citrix Machine which you can then call in your TestCases.
An example is shown as below:
*** Settings ***
Library SSHLibrary
*** Variables ***
${Citrix_machine} 192.168.0.1
${username} user
${password} password
*** Test Cases ***
Test1
Open Connection ${Citrix_machine}
Login ${username} ${password}
If you want to create a keyword of login then you can use the following steps:-
*** Settings ***
Library SSHLibrary
*** Variables ***
${Citrix_machine} 192.168.0.1
${username} user
${password} password
*** Test Cases ***
Test1
Login into Cluster
*** Keywords ***
Login into Cluster
Open Connection ${Citrix_machine}
Login ${username} ${password}
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}