Robot Framework File Upload

2020-02-16 04:25发布

问题:

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

Thanks

回答1:

There is a Choose File keyword in SeleniumLibrary



回答2:

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.



回答3:

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



回答4:

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.



回答5:

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}


回答6:

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 ..