在 Robot Framework 中使用什么关键字更改目录?

What keyword to use to change directory in Robot Framework?

这只是一个非常基本的机器人测试 case/script。这是从网络导出 .csv 文件。

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

如您所见,文件将下载到 C:\Users\xxxxx\Reports。现在,我想重命名该文件。所以我只是输入“移动文件旧文件名新文件名”,错误是:

C:\Users\xxxxxxx\PycharmProjects\ExportFiles\oldfilename'不存在。

这就是我的 .robot 文件所在的位置。我怎样才能回到 C:\Users\xxxxx\Reports 以便我可以使用 'move file' 更改文件名?或者你有更好的建议吗?目标只是更改下载文件的文件名。请耐心等待,因为我只是在练习机器人。提前谢谢你。

你必须给关键字提供文件的全名 - 如果你不这样做,它默认为父进程的当前工作目录,恰好是套件's/the机器人二进制:

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