Robotframework and SSHLibrary issue with a network router - robotframework

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 ;)

Related

Robot Framework Telnet: EOFError: telnet connection closed

I am connecting a network switch using telnet, please see my script below. This script keeps showing "EOFError: telnet connection closed" error message after running 80-90 iterations when executing the username command. I searched google and tried to find the root cause, unfortunately, no success. I would be thankful if you can guide me to address this issue:
*** Settings ***
Library Telnet
*** keyword ***
Telnet Connection
Telnet.Open Connection ${IP} prompt=$
Telnet.Set Prompt (>|#|> |# |:|Password:| |) prompt_is_regexp=true
Telnet.Execute Command username
Telnet.Execute Command password
Telnet.Execute Command show something
sleep 2s
Telnet.read
Telnet.Execute Command exit
sleep 2s
Telnet.read
*** Test Cases ***
Telnet Connection
:FOR ${I} IN RANGE 0 10000
\ Telnet Connection
Use Login keyword to connect: https://robotframework.org/robotframework/latest/libraries/Telnet.html#Login
Check also:
https://robotframework.org/robotframework/latest/libraries/Telnet.html#Connections
You can also get return value from Execute Command and log it on the screen with Log To Console keyword.

Robot Framework: I got [Errno 10057] A request to send or receive data was disallowed after try to run Robot script for automate test Mainframe

I got the error: [Errno 10057] after I try to run Robot script for automate test Mainframe.
*** Settings ***
Library Mainframe3270
*** Test Cases ***
Example
Open Connection HostTest
Change Wait Time 0.9
Set Screenshot Folder C:\\Temp\\IMG
${value} Read 2 13 10
Take Screenshot
Close Connection
error: [Errno 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
I don't know what something wrong in my Robot code or configuration, can anyone explain please. This is my first time to do the Robot in Mainframe.

ROBOT FRAMEWORK - Create session with AUTH and Headers - Getting TypeError: __init__() takes exactly 3 arguments (2 given)

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

SFTP SSHLibrary Unable to Connect

Im unable to connect to SFTP with below script, any ideas why?
*** Variables ***
${HOST} = mysite.com
${USERNAME} = username
${PASSWORD} = password
${PORT} = 22222
${keyfile} = /Users/victor/.ssh/
*** Test Cases ***
Open Connec
Open Connection stage1.globalcashcard.com alias=LaborReady port=22222
Enter Credentials
Login ${USERNAME} ${PASSWORD}
List Dir
List Directory /
Close ALL Conns
Close All Connections
Side NTOE:
I Even tried it with
Login with P. Key
Login With Public Key username /Users/username/.ssh/known_hosts
Results log
Status:
FAIL (critical)
Message:
SSHException: SSH session not active
00:00:00.004
KEYWORD SSHLibrary . List Directory /
Documentation:
Returns and logs items in the remote `path`, optionally filtered with `pattern`.
Start / End / Elapsed:
20170607 14:18:33.338 / 20170607 14:18:33.342 / 00:00:00.004
14:18:33.342
FAIL
SSHException: SSH session not active
I'm able to login with Filezilla without any issues. On thing I did notice is that I cannot login via terminal with below command
ssh username#stg1.mysite.com -p 22222
I get prompted to enter password when I enter then I get below message
shell request failed on channel 0
I able able to connect via Terminal with below command
sftp -o "Port 22222" username#stg1.mysite.com
Could this be the issue?
SSH and SFTP are different protocols. That is what you validated with your experiences.
When you use SSHLibrary you can use similar functions you get in SFTP, but not the exact commands.

Login to citrix machine using Robot framework

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}

Resources