Promise To Upload File - how to add all files in directory - robotframework

Currently I have to give single file name to upload the file.
How do I let robot to keep selecting the files in 'Files' directory then click upload?
*** Settings ***
Library Browser
Library OTP
Library BuiltIn
Library OperatingSystem
*** Test Cases ***
Upload Files
${promise}= Promise To Upload File ${CURDIR}/Files/doc1.txt
Click ${Button-Upload}
${upload_result}= Wait For ${promise}

I managed to do it , however the result can be fine tuned.
this solution did click upload - select file - click upload - select file.
finding solution to click upload - select multiple files (manual way: use keyboard ctrl + click to select more files).
*** Settings ***
Library Browser
Library OperatingSystem
Resource ../Resources/BrowserParameters.robot
Resource ../Resources/BrowserResources.robot
#Select Browser: chromium or firefox
Test Setup Test Setup Browser=chromium
Test Teardown Test Teardown
*** Test Cases ***
001-01-Upload-20-Videos
Click ${Page-Inference}
#{my_file_list}= OperatingSystem.List Files In Directory ${path_to_directory}
FOR ${file} IN #{my_file_list}
${result}= Upload Video ${path_to_directory}${/}${file}
END

Related

Robot Framework - run keyword if file exists

How can you run keywords in the robot framework if the file exists in the filesystem?
For example:
Run Keyword If ${filename} exists Delete File
OperatingSystem library could be used for this, even though there's not exactly any keyword for what you need. But you can get creative and perhaps use Get File, Get File Size, List Files In Directory, Run And Return Rc or even something else. There are also keywords like File Should Exist, File Should Not Exist, Should Exist. Perhaps you can change your code so you can use these.
Or you create your own simple library:
Libraries/file.py
import os
def file_exists(file):
return os.path.isfile(file)
import it and use it like you mentioned in your question:
Tests/test.robot
*** Settings ***
Library ../Libraries/file.py
*** Test Cases ***
Test File Exists
${fileExists}= File Exists test.robot
Run Keyword If ${fileExists} is True Log To Console Exists!
When I need this kind of action, I code something like that... maybe can work for you.
*** Settings ***
Library Process
*** Variables ***
#{FILES} ${CURDIR}/someFolder/aaa.pdf
... ${CURDIR}/someFolder/bbb.pdf
*** Test Cases ***
Check and Delete Files
FOR ${file} IN #{FILES}
${out} = run process ls ${file}
run keyword if ${out.rc} == 0 Delete File ${file}
END
*** Keywords ***
Delete File
[Arguments] ${f}
${o} = run process rm -f ${f}
Should Be Equal As Integers ${o.rc} 0
Get the File status and then use the status as
${file_exists}= Run Keyword and Return Status File Should Exist test.robot
IF ${file_exists}
Log File Exists
END

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

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/

RobotFramework AutoIT NotePad Test Passes but doesnt launch Notepad

I have this very simple robot script to launch notepad.exe and type some text. The Test passes, but it doesnt launch notepad.
I am using Windows 10, python 3.7.1 and here are my versions of python packages:
Appium-Python-Client==0.31
decorator==4.3.0
docutils==0.14
kitchen==1.2.5
Pillow==5.4.1
pywin32==224
robotframework==3.0.4
robotframework-appiumlibrary==1.5.0.1
robotframework-autoitlibrary==1.2.2
robotframework-seleniumlibrary==3.2.0
selenium==3.141.0
six==1.11.0
urllib3==1.24.1
My robot scripts reads like this:
*** Settings ***
Library AutoItLibrary
*** Test Cases ***
AutoIT Notepad Test
Run notepad.exe
Wait For Active Window Untitled - Notepad
Send This is some text
What am I doing wrong?
If you have notepad in the default location, try this:
*** Settings ***
Library AutoItLibrary
*** Variables ***
${notepad} C:\\Program Files\\Notepad\\notepad.exe
*** Test Cases ***
Run ${notepad}
Send This is some text
I think I figured it out. The test was passing be notepad was getting launched in a hidden window. I gave it the addtional argument and it passed:
*** Test Cases ***
AutoIT Notepad Test
Run notepad.exe ${EMPTY} 1
Wait for active window Untitled - Notepad
Send Typing some text

How to create _init_.robot and use it for all robot files in the directory in robot framework?

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:

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