robotframework:无法找到文件夹外的关键字

robotframework : failed to locate keywords outside the folder

提问人:Jimmy 提问时间:3/28/2022 最后编辑:Jimmy 更新时间:3/29/2022 访问量:220

问:

folder structure

Project
  |
  |_ _folder1  (abc.robot)
  |
  |_ _folder2  (def.robot)
  |      |_ _ folder3 (ghi.robot)
  |
  |
  |
  setup.robot

文件夹 1 abc.robot 内部

#abc.robot 
#create session api call

*** Settings ***
Library     RequestsLibrary
Resource    /setup.robot

Post_new_user
    create session    newsession        ${url}
    ${body}=    create dictionary      mobile_prefix=${mobile_prefix}   mobile_number=${mobile_number}
    ${headers}=  create dictionary     Content-Type=application/json
    ${response}=    post request    newsession      newuser/register      data=${body}     headers=${headers}

    #validations
    ${status_code}=     convert to string    ${response.status_code}
    should be equal    ${status_code}       200

在文件夹2 def.robot

#def.robot
#test data driven with robot

*** Settings ***
Resource    ../../ghi.robot
Test Template  Registration Test

*** Test Cases ***
test1       +12     9999999991
test2       +12     9999999992
test3       +12     9999999993


*** Keywords ***
Registration Test
    [Arguments]    ${mobile_prefix}     ${mobile_number}
    a mobile prefix ${mobile_prefix}
    a mobile number ${mobile_number}
    Post_new_user

文件夹内3

#ghi.robot
#set of keywords / steps to call

*** Keywords ***
a mobile prefix ${mobile_prefix}
    set test variable  ${mobile_prefix}  ${mobile_prefix}

a mobile number ${mobile_number}
    set test variable  ${mobile_number}  ${mobile_number}

step.机器人

*** Variable ***
${url}=     https://example/com

使用机器人框架的测试数据驱动程序 但是当 def.robot 运行时 文件的位置总是有问题

  1. 资源文件“\setup.robot”不存在。
  2. 资源文件“ghi.robot”不存在。
  3. 未找到名称为“a mobile prefix ${mobile_prefix}”的关键字。

我错过了什么吗?

Python 机器人框架

评论

0赞 Sujit Neb 3/29/2022
请尝试以下操作: 资源文件 资源文件Resource ../setup.robotResource ../../folder2/folder3/ghi.robot
0赞 Jimmy 3/29/2022
已经尝试过了,但仍然遇到相同的错误:(
0赞 Shiva Prasad Adirala 3/29/2022
始终使用项目路径。我们有 2 个内置变量 ${EXECDIR}、${CURDIR}。请参阅用户指南。您的路径将类似于 ${EXECDIR}${/}setup.robot
0赞 Shiva Prasad Adirala 3/29/2022
友情链接 - robotframework.org/robotframework/latest/...

答:

0赞 Vyacheslav 3/29/2022 #1
#abc.robot 
...
Resource    ../setup.robot


#def.robot
...
Resource    ./folder3/ghi.robot

评论

0赞 Jimmy 3/30/2022
单“.”和双“..”有区别吗?
0赞 Vyacheslav 3/30/2022
..是父文件夹,但 .是当前文件夹
0赞 Vyacheslav 3/31/2022
@ningpra 你试过我的解决方案吗?