Search code examples
robotframework

What keyword to use to change directory in Robot Framework?


this is just really a very basic robot test case/script. This is exporting .csv file from web.

 *** Settings ***
Library  SeleniumLibrary
Library  OperatingSystem

*** Variables ***
${DIR}            C:\\Users\\xxxxx\\Reports

*** Test Cases ***
Sample exporting of csv file

    empty directory  ${DIR}
    ${prefs} =    Create Dictionary    download.default_directory=${DIR}
    open browser  https://xxxxxxxxxxxxxxxxx.com  headlesschrome  executable_path=${BROWSERDRI}  options=add_experimental_option("prefs",${prefs})
    input text  //*[@id="name"]  xxxxx
    input password  //*[@id="password"]  xxxxx
    click button  //*[@id="button_primary"]
    click element  //*[@id="content-header"]/div/span[3]/a/div
    click element  //*[@id="exportDropdown"]/ul/li[3]/a
    click link  //*[@id="exportCsvColumns_control"]/div/div[1]/div/a[2]
    click button  //*[@id="exportSubmit"]
    sleep  5s
    move file  oldfilename  newfilename
    close browser

As you can see the file will be downloaded in C:\Users\xxxxx\Reports. Now, I want to rename the file. So I just put "move file oldfilename newfilename" and the error is:

C:\Users\xxxxxxx\PycharmProjects\ExportFiles\oldfilename' does not exist.

And that is where my .robot file is located. How can I go back to C:\Users\xxxxx\Reports so that I can change the filename using 'move file'? Or if you have a better suggestion? Goal is just to change the filename of the downloaded file. Please bear with me as I am just practicing Robot. Thank you in advance.


Solution

  • You have to give the full name of the file to the keyword - if you don't, it defaults to the current working dir of the parent process, which happens to be the suite's/the robot binary:

    Move File  ${DIR}\\oldfilename    ${DIR}\\newfilename