【问题标题】:Robot FW : Builtin module : Set Suite Variable : How to overwrite the newly created variable to in the new scope?机器人固件:内置模块:设置套件变量:如何在新范围内覆盖新创建的变量?
【发布时间】:2020-05-12 23:49:04
【问题描述】:

Acc.to Variable scopes,我们有全局作用域、测试套件作用域、测试用例作用域和本地作用域。

参考Set Suite Variable documentation

如果一个变量已经存在于新范围中,它的值将被覆盖。

我的目标是写一个简单的代码sn-p,在实践中演示这句话。 这是技术问题

为了能够全面实现技术目标,新范围当前范围需要说明。例如,当前/新范围与全局范围、测试套件范围、测试用例范围和本地范围有何关系?

【问题讨论】:

  • 请阅读How to Ask 部分。在我看来,这个问题有 6 个不同的问题,并非所有问题都与技术问题有关。请edit您对单个技术主题的问题。
  • 我把问题简化了。

标签: robotframework built-in


【解决方案1】:

要准确理解您的要求有点困难,但我认为以下测试可能会说明这句话“如果新范围内已经存在变量,则其值将被覆盖。”

首先,此测试在第一个测试的测试范围内创建一个名为${var} 的变量。第二个测试验证变量在原始范围之外是不可见的。

第三个测试与第一个测试一样开始,创建一个测试范围的变量。然后它调用 Set suite variable 覆盖第三个测试的测试范围内的变量。

最后,第四个测试表明该变量现在可用于套件中的每个测试,因为该变量存在于套件范围内。

*** Test cases ***
Example 1
    # Set a variable in a test scope
    Set test variable  ${var}  test
    Should be equal    ${var}  test

Example 2
    # Verifies that the variable from the first test
    # is not available in this new test scope
    Variable should not exist  ${var}

Example 3
    # Set a variable in the test scope
    Set test variable  ${var}  test
    Should be equal    ${var}  test

    # Set a suite variable that has the same name as the local variable
    Set suite variable  ${var}  suite

    # Even though we set it as a suite scope, it overwrites the local
    # variable of the same name
    Should be equal  ${var}  suite

Example 4
    # Verify the suite variable from the previous test is visible
    # in this new test scope
    Should be equal  ${var}  suite

【讨论】:

  • 将“示例 3”测试与文档“如果新范围内已存在变量,其值将被覆盖。”相关联,我认为文档存在错误。更好的说法可能是“如果一个变量已经存在于测试用例范围内,它的值将被覆盖”。你同意吗?
  • @HKN:我认为目前的措辞是正确的。我的例子只是在说明它方面做得很差。我认为你想多了 - 关键字的工作方式与描述的完全一样,它将套件变量设置为一个值。它要么更改现有变量,要么创建一个新变量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 2015-12-16
相关资源
最近更新 更多