首页 > 解决方案 > 机器人框架 - 未找到关键字 - 使用 IP 地址作为目标

问题描述

我收到一个“没有名称的关键字......”错误,如下所示。我认为这与我的测试用例引用 IP 地址有关,但不确定?

请参阅下面的测试代码和 CLI 输出,感谢帮助

*** Settings ***
Documentation   Suite - Open Connections and do a simple comparison test
Suite Setup     Device Open Connection      @{TARGET}
Suite Teardown  Device Close Connection     @{TARGET}
Library         OperatingSystem
Library         /Users/xxx/Desktop/CI/RobotTestingFramework/Libraries/pybot_jrouter.py    target=${TARGET}    WITH NAME    ${TARGET}
Library         /Users/xxx/Desktop/CI/RobotTestingFramework/Libraries/iplib.py
Resource        /Users/xxx/Desktop/CI/RobotTestingFramework/Resources/device_resources.robot
Resource        /Users/xxx/Desktop/CI/RobotTestingFramework/Resources/version_resources.robot

*** Variables ***
${USERNAME}    xxx
${PASSWORD}    Juniper123
${path}    ./Report
@{TARGET}    192.168.1.100
${OSversion}    12.1R1.9

*** Test Case ***
Check Software Version
    [Documentation]    Test - Version Check
    [Tags]    version
    FOR    ${target}    IN    @{TARGET}
    Check Software Version    ${target}    ${OSversion}
    END

检查版本软件 -

*** Settings ***
Resource    /Users/xxx/Desktop/CI/RobotTestingFramework/Resources/device_resources.robot
Library     String
Library     Collections
Library     XML

*** Keywords ***
Check Software Version
    [ARGUMENTS]    ${device}    ${software-version}
    ${get-software-details}    Command Executor    ${device}    show version    xml    //junos-version
    Should Be Equal    ${software-version}    ${get-software-details}    The Junos OS version is different than expected!

打开连接 -

*** Settings ***
Documentation   A resource file with reusable keywords for 'executing the command in device',initiate device connection and tear down device connection.It can be used for any devices such as  SWITCH,ROUTER,FIREWALL.     NOTE: It has to be developed further to make it complete generic


*** Keywords ***

Device Open Connection
    [Arguments]    @{devices}
    FOR    ${device}    IN    @{devices}
    Run Keyword    ${device}.Open Connection
    END






Check Version :: Suite - Open Connections and do a simple comparison test     
==============================================================================
Check Software Version :: Test - Version Check                        | FAIL |
Parent suite setup failed:
No keyword with name '192.168.1.100.Open Connection' found.

标签: automationrobotframework

解决方案


免责声明:我可以告诉你为什么它会抛出错误,但你可以改变它以使其得到修复——如果不知道最终目标、库等,很难推断出意图。

错误指出:

父套件设置失败:
找不到名称为“192.168.1.100.Open Connection”的关键字。

您的套件设置 - 错误的来源 - 是Device Open Connection @{TARGET},例如使用参数调用关键字列表“TARGET”的成员(例如扩展列表)。该关键字正在对其传递的所有参数进行循环,并且执行以下操作:

Run Keyword    ${device}.Open Connection

,其中“设备”是当前循环的值。
内置Run Keyword就是这样做的 - 它需要一个关键字名称并执行它。所以你有效地传递了“192.168.1.100.Open Connection”,并期待 - 什么?:) 执行此类关键字的框架?但是您还没有定义它,并且-该消息失败了。

这是我(至少)无法进一步提供帮助的时刻 - 这就是您看到错误消息的原因,但是从这里获取它的位置 - :)。
也许,这些库中某处有一个方法/关键字“打开连接”,它需要 IP 地址;我不知道,我只是从这里开始猜测。


推荐阅读