Robotframework:未找到变量 $CUSTOM_VARIABLE
Posted
技术标签:
【中文标题】Robotframework:未找到变量 $CUSTOM_VARIABLE【英文标题】:Robotframework: Variable $CUSTOM_VARIABLE not foundRobotframework:未找到变量 $CUSTOM_VARIABLE 【发布时间】:2021-11-05 09:16:39 【问题描述】:我创建了一个机器人框架测试用例,如果我将 xpath 直接硬拷贝到关键字中,它似乎可以工作。
例如:
*** Variables ***
$MAIN_FOLDER=//span[text()=" AutomationTestFolder "]
*** Keywords ***
Folder tear down
navigate to process designer
wait until element is visible $FRAME 180s
select frame $FRAME
#finds the created folder
wait until element is visible xpath=//span[text()=" AutomationTestFolder "]
click element xpath=//span[text()=" AutomationTestFolder "]
#below it is basically the same xpath as the one above. The above one works, the below one does not
open context menu $MAIN_FOLDER
#press on delete
wait until element is visible xpath=//li[a[contains(@data-selected-option, "DELETE")]] 10s
click element xpath=//li[a[contains(@data-selected-option, "DELETE")]]
#confirm delete
wait until element is visible xpath=//button[contains(@class, "btn-modal btn-modal-primary hide-focus")]
click element xpath=//button[contains(@class, "btn-modal btn-modal-primary hide-focus")]
为什么不能使用自定义变量?它实际上是相同的 xpath
【问题讨论】:
【参考方案1】:这不是我们在机器人框架中使用变量的方式。
试试这个:
$MAIN_FOLDER //span[text()=" AutomationTestFolder "]
或
$MAIN_FOLDER= Set Variable //span[text()=" AutomationTestFolder "]
【讨论】:
【参考方案2】:考虑这段代码:
*** Variables ***
$MAIN_FOLDER=//span[text()=" AutomationTestFolder "]
您已经定义了一个名为 $MAIN_FOLDER=//span[text()=" AutomationTestFolder "]
的变量,其值为空。
您需要在变量名后有两个或多个空格(以及可选的=
):
$MAIN_FOLDER= //span[text()=" AutomationTestFolder "]
【讨论】:
以上是关于Robotframework:未找到变量 $CUSTOM_VARIABLE的主要内容,如果未能解决你的问题,请参考以下文章
08:robotframework变量文件与python测试库