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.
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.
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
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.
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}