I am trying to make a testcase in robotframework with SSHLibrary and running into an error trying to connect with the FTP server. The error I get is keyword login.login expects 0 arguments and gets two. I do not really understand why it does expect 0 arguments.
the resource file in which the keyword file exists has the following code:
*** Settings ***
Library SSHLibrary
*** Keywords ***
lOGIN
Set Default Configuration 30s
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
The test I like to run looks like:
*** Settings ***
Documentation Example of testing an accrual for TLOG
Resource ../Resources/login.robot
*** Variables ***
${HOST} sitenv
${USERNAME} crmapplication
${PASSWORD} Company11*
*** Test Cases ***
logintositenv
login.login
Any idea what is going wrong? I am especially surprised I cannot get it to work because I used the open connection and login keywords from SSHLibrary before when I was trying out a few things and it worked fine.
As you said login.login That tells me you have probably another library that has keyword login. In this case you have to specify that you want to use SSH library.
You can do this with
SSHLibrary.Login
Here you can have a look how to import library with custom name and use keywords
Related
I've got several working Robot Framework tests that I'm trying to consolidate into one test suite and run through a template. The tests are functionally the same, just being executed from a different URL. So that's the one parameter that's different. I'm trying to pass the URL into each test case, but I am getting an error: "Keyword 'Setup' expected 0 arguments, got 2."
*** Settings ***
Documentation Login tests
Library Zoomba.GUILibrary
Suite Setup Setup
Test Template Template 1
*** Variables ***
${browser} chrome
${url1} https://<test.url1>
${url2} https://<test.url2>
${url3} https://<test.url3>
*** Keywords ***
Setup
Open Browser ${url} browser=${browser} options=add_argument("<argument>")
Maximize Browser Window
Set Selenium Speed 0.2s
Log To Console Setup complete. Logging in...
Template 1
[Arguments] ${url} ${browser}=${browser}
Setup ${url} ${browser}
<Login tests>
*** Test Cases ***
Site 1 Login
${url1}
Site 2 Login
${url2}
Site 3 Login
${url3}
Anybody have any ideas? Please let me know, thanks!
You are calling Setup with two arguments, like the error says:
Template 1
[Arguments] ${url} ${browser}=${browser}
Setup ${url} ${browser}
<Login tests>
There are 2 files
Testcase/feature1.robot
POM/feature2.robot
feature1.robot
*** Settings ***
Library SeleniumLibrary
Resource ../POM/feature2.robot
*** Variables ***
${username} xxxxxxxx
${password} xxxxxxxx
*** Keywords ***
Login in DataRPM
#[Arguments] ${username} ${password}
Input Text ${email_id} ${username}
feature2.robot
*** Settings ***
Documentation This contains all the locaters of Login Page
*** Variables ***
${email_id} xxxxxxxx
But here I don't want to use the email_id locator to be mentioned in the variable section. If I am mentioning the ${email_id} in this feature file I am able to go ahead without any error. I want to use the locator in the feature2.robot file which is under my POM directory. Then I want to call the variable from feature2.robot.
I have mentioned the path in the feature1.robot but still I am getting error.
[ ERROR ] Error in file feature1.robot': Resource file 'path' contains
a test case table which is not allowed.
The error is pretty descreptive, while you not showing use you probably have test cases implemented in feature2.robot and in that case it is a suite file.
But you are trying to use feature2.robot as a resource file, and as the error message states, resource files are not allowed to have test case table.
You should create a third file like POM/locators.robot:
*** Settings ***
Documentation This contains all the locaters of Login Page
*** Variables ***
${email_id} xxxxxxxx
and use this in both feature1.robot and feature2.robot like:
Resource ../POM/locators.robot
Resource locators.robot
From Robot Framework 3.1 *.resource file extension is supported, so if you have version 3.1, you should use locators.resource to be more explicit about that this file is a resource file and not a test suite.
your question is not clear, However , i would try to show an error free example using your code only, with slight modification.
feature1.robot
*** Settings ***
Resource ../Data/Feature2.robot
*** Variables ***
${username} pankaj
${password} xxxxxxxx
*** Test Cases ***
Login
Login in DataRPM
*** Keywords ***
Login in DataRPM
#[Arguments] ${username} ${password}
log to console ${email_id}
log to console ${username}
Feature2.robot
*** Settings ***
Documentation This contains all the locaters of Login Page
*** Variables ***
${email_id} pankajigec26#gmail.com
if you run feature1.robot you will not get into any error .
In your case , please check if you are running the same code which you have pasted here.
I am trying to include_init_.robot file in the test suite. I have added a test implementation to check the method it would work, however I am unable to figure out it's execution. Code is as follows:
init.robot
*** Settings ***
Documentation Suite description
Suite Setup Initialization In Progress
*** Keywords ***
Initialization In Progress
log many THE CODE WORKS NOW
test#1.robot
*** Settings ***
Documentation Suite description
*** Test Cases ***
Test Case Execution
log many TC EXECUTED
Code used to run the test: pybot folder_name
The name of the first file is incorrect. You have
_init_.robot
while it should be
__init__.robot
When you do that the log will show this:
Using SSHLibrary currently I execute ssh commands in test suite file or keyword file. Is it possible to do that in my current library file? Meaning my library function just forms the string now. I wanted to executed that in ssh connection in library file.
test/testsuit.robot
*** Settings ***
Library SSHLibrary
Library ${EXEC_DIR}/lib/mylib.py WITH NAME llib
Suite Setup open_connection_and_login
Suite Teardown Close All Connections
*** Variables ***
${HOST} 10.x.x.x.x
${USERNAME} myuser
${PASSWORD} mypassword
*** Test Cases ***
example test
${sshstring}= llib.form_the_sshstring ls
${output}= Execute Command {sshstring}
*** Keywords ***
open_connection_and_login
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
lib/mylib.py
def form_the_sshstring(input):
sshstring = "{}".format(ls)
return sshstring
Expecting something like..
*** Test Cases ***
example test
${output}= llib.run_the_sshstring ls
/lib/mylib.py
import SSHLibrary
def run_the_sshstring(input):
sshstring = "{}".format(ls)
out = SSHLibrary.SSHCleint(sshstring)
return out
From within your library file you can get a reference to the imported SSHLibrary -- and thus, it's keywords -- with the built-in keyword Get Library Instance. With that, you can call the SSHLibrary keyword Execute Command
Example:
# mylib.py
from robot.libraries.BuiltIn import BuiltIn
def run_the_sshstring(input):
sshlib = BuiltIn().get_library_instance("SSHLibrary")
result = sshlib.execute_command(input)
return result
I want to import library SeleniumLibrary into Robot test file but resulted not found. What could be the error?
I have installed SeleniumLibrary into C:\Python27\Lib\site-packages and set the environment variables. I"m using python 2.7.9
*** Settings ***
Documentation This is a simple test for Robot Framework
Library SeleniumLibrary
#Set Selenium Speed 2 seconds
*** Variables ***
#${homepage} http://www.amazon.com
#${chrome_browser} Chrome
*** Test Cases ***
Test title "Amazon"
[Tags] DEBUG
Open Browser http://www.amazon.com chrome
[Teardown] Close Browser
*** Keywords ***
Please help. Thanks.
Your SeleniumLibrary looks perfectly fine, the problem is the way you are calling the KW.
The error you are getting here because of below line
Open Browser http://www.amazon.com chrome
There should be two or four spaces between Keywords and Arguments and Arguments and ... , otherwise it will treat whole line as KW , which never going to exist
so change it like this
Open Browser http://www.amazon.com chrome
if it still throw an error, paste it here.
Solve by using four spaces between keywords and argument and argument.