【问题标题】:robot test cases passing formatted variables from python to robot file机器人测试用例将格式化变量从 python 传递到机器人文件
【发布时间】:2020-10-12 12:14:27
【问题描述】:

你能帮我吗?有没有办法将格式化字符串从 python 文件传递​​到机器人文件假设下面是我的特定语言 py 文件

English.py 文件分配了以下变量

FILTERED_TEXT_LANG = "{} Selected"

机器人测试用例设置变量如下机器人文件(user.robot)

${element} =     Set Variable    xpath=*//div[contains(@id,'org-selection-counter') and contains(text(),'${FILTERED_TEXT_LANG}.format(some_filtered_count)')]

这是必需的,因为不同的语言以不同的方式显示 some_filtered_count ,有没有办法可以从格式化的字符串进行更改,而不是 if else 条件

【问题讨论】:

    标签: python selenium xpath robotframework


    【解决方案1】:

    嗯,有办法,但不是这样:

    ${element} =     Set Variable    xpath=*//div[contains(@id,'org-selection-counter') and contains(text(),'${FILTERED_TEXT_LANG}.format(some_filtered_count)')]
    

    您不能直接在 RF 中使用 Python 关键字、方法等。但是您可以做的是在 RF 或 Python 中创建您的自定义关键字,您稍后在 RF 中使用它,它会将一种语言填充到字符串中。实际上,您甚至不需要创建任何东西,只需重复使用 String library 中已有的内容即可

    我可以想象这样的事情:

    ${str_with_language}=    Replace String    ${FILTERED_TEXT_LANG}    {}    ENG
    ${element} =     Set Variable    xpath=*//div[contains(@id,'org-selection-counter') and contains(text(),'${str_with_language}')]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-31
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多