Luixv
Luixv

Reputation: 8710

Robot Framework File Upload

I have to write a test where a file has to be uploaded. Is this possible using Robot Framework?

Thanks

Upvotes: 0

Views: 5658

Answers (7)

Robert Szabo
Robert Szabo

Reputation: 1

If Choose File not works, -e.g.: SharePoint Upload File does not work -then AutoIt is a good option. See the example:

1. Install Autoit library-t. (No need to install Autoit.exe.)

Powershell:

    pip install robotframework-autoitlibrary


2. Robot Framework:

*** settings ***
         Library           SeleniumLibrary
         Library           AutoItLibrary      
     
*** Test Cases ***
      File Upload SP
         Open Browser    https://yoursparepoint.com/sites/   chrome
         Wait Until Element Is Enabled    xpath=//*/text()[normalize-space(.)='Upload']/parent::*    #waiting until Upload menu is became active.
         Sleep    1
         Click Element    xpath=//*/text()[normalize-space(.)='Upload']/parent::*    #Click on Upload menu
         Click Button    //button[@name='Files']    #Click on File menu
         AutoItLibrary.Wait For Active Window    Open    ${SPACE} #Wait to "Open" window appear.
         AutoItLibrary.Control Set Text    Open    ${SPACE}    Edit1    C:\\Temp\\filetoupload.txt    #Sending filename (with path) to inputfield
         AutoItLibrary.Control Click    Open    &Open    Button1 #Click on OPEN Button (Submit)

Upvotes: 0

indrajit narvekar
indrajit narvekar

Reputation: 143

I used this lot many times I just wrote one function in Robot Framework which takes 2 arguments 1 filename 2 Browse Location

File Upload for Creative
[Arguments]         ${file}=
...                 ${browsrLocator}=
${NORMAL_PATH_UPLOAD_FILE_NAME}      Normalize Path       ${DataFiles}/${file}
Choose File         ${browsrLocator}        ${NORMAL_PATH_UPLOAD_FILE_NAME}
Sleep   3s

Thats it ..

Upvotes: 0

Royalyn H
Royalyn H

Reputation: 31

Choose File will work the best

eg :to import a file from execution directory for more details on file path check operating system library

Click Element    ${IMPORT}
Choose File      ${LOCATE_FILE}    ${CURDIR}${/}filename.txt
Click Element    ${VALIDATE_IMPORT}

Upvotes: 0

Brandon Olson
Brandon Olson

Reputation: 639

This, as well as other problems that involve clicking outside of the DOM, can be solved in a few ways. Choose File might be able to be used, but I've never tried it and I've seen a couple of other tricks to do the same thing.

The first is using AutoIT to click outside the DOM, just like a user would if he were doing a manual test. I've never worked with it myself, but I've seen it used in Robot Framework to minimize the window, open up MS Paint, and draw a line, so I'm pretty sure it can be used for this as well.

The second way is by creating a Robot Framework keyword to click by a snipped image outside the DOM. This is what I use all the time to click on buttons that I can't reach normally with Robot Framework. Use the Snipping Tool to snip a picture of where you want to click with the location in the center. It's a little finicky, but easy to use, so I like it. Here's the Python 2.7.13 code for it.

def click_by_image(self, image_name):
    if self.selenium_lib is None:
        self.selenium_lib = BuiltIn().get_library_instance('ExtendedSelenium2Library')
    pag.click(pag.locateCenterOnScreen(str(image_name)))

Assuming you're familiar with creating new Robot Framework keywords (see other questions/answers for details, that is outside the scope of this question), implementing this should be pretty straightforward.

EDIT: I have recently switched over to Choose File, since it can be assumed that the Windows (or the OS you're running) GUI is working and that it's possible to do manually what Robot Framework is automating. It's also faster by sometimes several clicks, more reliable, and can run in the background while you're paying attention to another window.

Upvotes: 0

Savyasachi
Savyasachi

Reputation: 151

ChooseFile will paste file path in given locator.This is simply like Input Text only. You Can use AutoIT for this record autoit script and convert it to au3 file and run as below Run And Return RC auitscriptforfileupload.au3

Upvotes: 0

Selenium Master
Selenium Master

Reputation: 166

Choose File keyword can type in the file path with name in the file upload text field. However, the keyword cannot interact for selecting the file in the window where you click on a file and then click on the Open button. To click on a file in the Open File Window and click on open button, you can use Robot Framework AutoItLibrary keywords. Check out the video tutorial for Robot Framework File Upload.

Upvotes: 0

sath garcia
sath garcia

Reputation: 36

There is a Choose File keyword in SeleniumLibrary

Upvotes: 2

Related Questions