WindowsError: [Error 123] while using Get Directory of SSHLibrary - robotframework

I'm trying to download a specific directory from Windows XP and Windows Server 2012 using a Get Directory method of SSHLibrary. This directory is on a different volume that the one in which the ssh connection it's established. For clarity when I open the connection this points to volume C:, the source directory is in volume D:. The issue that I'm seeing is that on my local machine the path to directory tries to include the volume letter resulting in something like: C:\path\to\robot\executable\D:\source\directory thus resulting in WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect:
Is there a way to not have this issue but result in a path like C:\path\to\robot\executable\source\directory and successfully download the directory? I've tried doing Execute command d: before Get Directory but no luck there. Also is there a way to open a connection pointing to a specific volume?
Code I used:
*** Settings ***
Documentation Suite description
Library SSHLibrary timeout=120 seconds
*** Variables ***
${HOST_XP} remote.win.xp.machine
${USER_XP} user
${PASSWORD_XP} pass
${DIR} D:\\source\\
*** Test Cases ***
Test Win XP
SSHLibrary.open_connection ${HOST_XP}
SSHLibrary.login ${USER_XP} ${PASSWORD_XP}
SSHLibrary.get directory ${DIR}
Edit1: various typo

I actually found out the problem for Get Directory method. In path variables / should be used and not \. So my DIR variable should be ${DIR} D:/source/

Related

Robot Framework:How to access a global variable from __init__ file

I have a __init__.csv file under Suit folder, and int this __init__.csv file I try to access a global variable which is defined in a resource file, but it reports "FAIL : Variable '${WORKSPACE_BASE_DIR}' not found".
Here's my code in __init__.csv
*Settings*
Suite Setup Setup Test Environment
Suite Teardown Cleanup Test Environment
Resource ../Resource/variables.tsv
Library SSHLibrary
*Keywords*
Setup Test Environment ${path}= Join Path ${WORKSPACE_BASE_DIR} ssh.log
Enable SSH Logging ${path}
Cleanup Test Environment Close All Connections
Code in variables.tsv
*Settings*
*Variables*
${ENVNAME} Windows
*Keywords*
Linux Set Global Variable ${WORKSPACE_BASE_DIR} a linux path
Windows Set Global Variable ${WORKSPACE_BASE_DIR} a windows path
Can someone tell me where goes wrong?
In the code you provided, you only set that variable if you call the Linux or Windows keyword. You're not calling either of those keywords anywhere.

Unable to run shell script from test case

I'm trying to invoke a shell scrip from within a .robot test case.
The .sh file is in the same folder as the .robot file
*** Settings ***
Library Process
*** Test cases ***
Run the shell script
Start Process ./getIDfromDB.sh shell=yes
I'm getting the error:
Setting variable 'Start Process ./getIDfromDB.sh' failed: Invalid variable name 'Start Process ./getIDfromDB.sh'.
Running on Ubuntu
Researched documentation for Robot framework but could not find a solution. Maybe digging in the wrong spot.
I'm not sure how you are trying to set the path of the shell script in the robot file. The error message seems to convey that something is wrong with the way you're initialising the variable to hold the path.
The following code should work:
*** Settings ***
Library Process
*** Variables ***
${pathToScript} ./getIDfromDB.sh
*** Test cases ***
Run shell script
${output} Run process ${pathToScript} shell=yes
The return code and the output displayed in the terminal are stored in the ${output} variable. You can access the details as ${output.rc} and ${output.stdout} respectively.
You can find more details about the result object here.
According error details the keyword is not recognized, I think, you need add extra spaces after keyword name:
Start Process ./getIDfromDB.sh shell=yes

PSFTP open for write: failure

I am uploading a file from a collection of different servers to one data server. I am using psftp and one out of 20+ servers is producing a permissions problem.
Remote working directory is /
psftp> cd Remote_Directory\
Remote directory is now /Remote_Directory/
psftp> put C:\folders\containing\file\FILE.zip
/Remote_Directory/: open for write: failure
psftp> quit
It appears like a permissions issue on the remote directory, however, why am I only getting the issue on one server? The batch is identical on all of the 20+ servers.
PUT command expects a file name at the end of the destination location.
Please try the following code
put C:\folders\containing\file\FILE.zip /Remote_Directory/FILE.zip
The path in the error message is an exact path to the remote file the psftp tried to create. See outfname in below code snippet:
req = fxp_open_send(outfname,
SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC,
&attrs);
...
printf("%s: open for write: %s\n", outfname, fxp_error());
As the path is obviously not correct (lacks file name), it seems that psftp got confused somehow. I believe it's likely due to wrong (back)slash you have used in the cd command.
Try cd Remote_Directory/.
In my case, it's a permission issue on the remote server, i.e. the account you are using to log on doesn't have the write permission for the remote folder.

How to open a program (*.exe) in Window by Robot Framework - AutoIT

I'm having trouble with opening a external Window program by Robot framework-Autoit.
Here is my code:
Notepad++
Run notepad++.exe
Or,
Notepad++
Run notepad++.exe C:\Program Files\Notepad++
The error displays as below
Notepad++ | FAIL |
Failed to run FileName='notepad++.exe', WorkingDir='C:\Program Files\'
But for internal Window program is Notepad, Paint - work OK
Most likely the problem is simply that notepad++ isn't in your PATH. If you have notepad++ installed in the default location, try running this complete test case:
*** Settings ***
| Library | AutoItLibrary
*** Variables ***
| ${notepad++} | C:\\Program Files\\Notepad++\\notepad++.exe
*** Test Cases ***
| Example
| | Run | ${notepad++}
If that works, it confirms that notepadd++ simply isn't in your PATH. You can either hard-code the path into your test cases or keywords like in the above example, or you can edit your PATH to include the directory where Notepad++ is installed.
I suspect your problem is with the PATH to your executable. In your first attempt you don't give a path at all and in the second you didn't surround it by double quotes to contain the space.
Put double quotes around your path
"C:\Program Files\Notepad++"
after add AutoItLibrary,press"F5" and search"run".
you can see the description about"run".
the program you want to run,must have"\\"&"full path" (like Bryan Oakley said)
====== ========== =========
Arguments:[ FileName | WorkingDir= | Flag= ]
Direct wrapper for AutoIt's Run method.
This is required in order to do error code translation into exceptions for Robot Framework.
FileName:The full path of the program (EXE, BAT, COM, or PIF) to run (see remarks).
WorkingDir:The working directory. This is not the path to the program

File has no test case table in Robot FrameWork

I've encountered a problem relating to Robot Framework test cases. After executing it, the console (cmd screen) displays error:
"[ ERROR ] Parsing 'Login_admin_page.txt' failed: File has no test case table."
Please take a look my test suite as well as test case and help me figure out the issue:
A. Structure of Test cases:
TS_test(folder)
--Login_admin_page.txt (--> main test case)
--resource.txt (--> resource file)
B. Content of test cases file:
Login_admin_page.txt
***Settings***
Documentation A resource file with reusable keywords and variables.
... This test is functionally identical to the example in
... valid_login.txt file
Resource resource.txt
Test Teardown Close Browser
***Test Cases***
Open Login page
Open Browser To Login Page
resource.txt
*** Settings ***
Documentation A resource file with reusable keywords and variables.
...
... The system specific keywords created here form our own
... domain specific language. They utilize keywords provided
... by the imported Selenium2Library.
Library Selenium2Library
*** Variables ***
${SERVER} http://google.com
${BROWSER} Firefox
${DELAY} 0
${VALID USER} admin
${VALID PASSWORD} admin
${INVALID USER} xyz
${INVALID PASSWORD} invalid
*** Keywords ***
Open Browser To Login Page
Open Browser ${SERVER} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Login Page Should Be Open
Login Page Should Be Open
Title Should Be Google
Use cmd and access to folder "TS_test", execute "pybot Login_admin_page.txt". The screen displays error.
Thanks.
The error File has no test case table can only occur in one circumstance: you do not have a testcase table. If you have a test case table but have no test cases, you'll get a different error.
A testcase table is denoted by a line that begins with one or more asterisks and then the phrase "Test Case" or "Test Cases". Case doesn't matter, and trailing asterisks are ignored. A fairly common pattern seems to be to use multiple asterisks on both ends of the line, eg: *** Test Cases ***
If you try to give a file without such a heading to robot, you will get the error you report. For example, trying to run robot on a completely empty file will give that exact error. Also, if you misspell "Test Case", you'll get the same error.
Given that, I'm wondering if your error is simply that you forgot to save the file before trying to run it.
Please set proper line endings.
In my case I've changed from Mac (CR) to UNIX (LF)
How about encoding of your test case files? I saved unicode encoded test file and I use to have the same error. Save your test case files in UTF-8 and It will fix your problem.
I have encountered similar file - parsing errors using Robot Framework in the past, mostly when trying to use Microsoft Word to author html files (not recommended!). I have always found that following the advice given in the Robot Framework user Guide about Debugging eventually helps me track the problem down.
In this case, I would recommend you try switching on Robot Framework's syslog output and looking through to see what it has managed to parse, if anything, from your test case file. I recently used this to figure out a nasty UTF-8 character encoding problem introduced into a html test case file by Microsoft Word (again, not recommended unless you really have to!).
(From the User Guide):
#!/bin/bash
export ROBOT_SYSLOG_FILE=/tmp/syslog.txt
export ROBOT_SYSLOG_LEVEL=DEBUG
pybot --name Syslog_example path/to/tests
I had the same problem happen to me, and in my case it was simply a missing new line after * Test Cases * and the start of the actual test table.
This happened when you copy past the content of the test case file. In my case I have copied test case content and paste in nano editor
It got pasted something like below without proper spacing
*** Settings *** Library Selenium2Library *** Variables *** ${BROWSER} firefox *** Testcases *** Hello Open Browser http://www.google.com browser=${BROWSER}
Then I have intend and aligned properly like below and its works
*** Settings ***
Library Selenium2Library
*** Variables ***
${BROWSER} firefox
*** Testcases ***
Hello
Open Browser http://www.google.com browser=${BROWSER}

Resources