I am trying to connect MySQL DB in robot framework. But I am receiving the following error:
Operational Error: (1045, u"Access denied for user
'ABC'#'Nd204-151-102-92.com' (using password: YES)")
I have used the Database Library and the following code :
*** Settings ***
Library Database Library
Library pymysql
*** Variable ***
${DBHost} value4
${DBName} value1
${DBPass} "value2"
${DBPort} port
${DBUser} value3
*** Keywords ***
Connect to DB
Connect To Database pymysql ${DbName} ${DBUser} ${DBPass}
${DBHost} ${DBPort}
${output}= Query select * from tables;
I'm going to go out on a limb and guess that you're adding quote marks around your username and password. The error message seems to imply this, and you added the following in a comment:
I am defining the username and password and in my variables section in the same robot file : like under*** Variables *** ${DBUser} = 'DBuser' and ${DBPass} = 'dbpassword'
Assuming the username is the six character string DBuser and the password is the 10 character string dbpassword, you need to define it like this:
*** Variables ***
${DBUser} DBuser
${DBPASS| dbpassword
Notice the lack of an =, and there are no quotes.
Related
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 ;)
I'm trying to connect to Sysbase but i have always the error
Suite setup failed:
OperationalError: ('08001', u"[08001] [Microsoft][ODBC SQL Server
Driver][DBNETLIB]Ce serveur SQL n'existe pas ou son acc\xe8s est
refus\xe9. (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL
Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)")
My code is:
*** Settings ***
Suite Setup Connect To Database pyodbc ${DBName} ${DBUser}
${DBPass} ${DBHost} ${DBPort}
Suite Teardown Disconnect From Database
Library Selenium2Library
Resource ../../../Keywords/Initialisation/Initialisation.robot
Library DatabaseLibrary
Library OperatingSystem
*** Variables ***
${DBHost} ""
${DBName} ""
${DBPass} ""
${DBPort} ""
${DBUser} ""
*** Test Cases ***
Récupérer CAB
${output} = Execute SQL String select "" from "" where ""= '80000204000048' ;
Log ${output}
I have installed databaselibrary
pip install robotframework-databaselibrary and pyodbc
">pip install pyodbc"
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}