【问题标题】:soapui transfer test suite property to test case using a scriptsoapui 使用脚本将测试套件属性转移到测试用例
【发布时间】:2014-11-19 23:27:39
【问题描述】:

我开发了一些 SoapUI 案例,它们通过从文件中读取属性在每个测试案例的开头设置一个属性。这很好用,然后我可以在每个测试请求步骤中通过语法${propertyA} 访问每个属性(比如说propertyA)。

现在我意识到每个测试用例的属性之一是相同的,所以我想我为此创建了一个测试套件属性,并从测试用例属性文件中删除了属性定义。首先我的测试用例都失败了,因为现在'propertyA'已经不为人知了,但我发现(根据http://www.soapui.org/Scripting-Properties/property-expansion.html)一种解决方案是将propertyA的每个引用替换为#testSuite#propertyA

不过,这有点乏味,所以我想在每个测试用例的开头创建一个 groovy 脚本,它从测试套件属性创建一个测试用例属性。根据 http://www.soapui.org/Scripting-Properties/tips-a-tricks.html我还以为是脚本之类的

def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue("propertyA")
testRunner.testCase.setPropertyValue("propertyA", testSuiteProperty)

应该做的工作。如果我log.infotestSuiteProperty 的值确实给出了所需的值,并且如果我将 testCase 属性分配给某个变量和log.info 它,它会显示正确的值。

但是,在下一个测试步骤中,propertyA 是未知的。只是为了确保我尝试在那里使用${#testCase#propertyA},但这也是未知的。我在这里做错了什么?

【问题讨论】:

    标签: groovy automated-tests soapui


    【解决方案1】:

    我认为您的问题是${#testCase#propertyA} 中的testCaset 必须为大写:${#TestCase#propertyA}。如果我在您的代码中添加一个常规测试步骤:

    def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue("propertyA")
    testRunner.testCase.setPropertyValue("propertyA", testSuiteProperty)
    

    然后我使用以下 xml 添加一个 SOAP 测试步骤:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="http://www.openuri.org/">
       <soapenv:Header/>
       <soapenv:Body>
          <open:procesa>
             <open:selector>${#TestCase#propertyA}</open:selector>
          </open:procesa>
       </soapenv:Body>
    </soapenv:Envelope>
    

    它可以正常工作,但是如果我使用${#testCase#propertyA},则找不到属性值。

    此外,您还可以检查是否在 SOAP 测试步骤请求左侧的 raw 选项卡中使用了正确的值。在此选项卡中,请求显示为用其值替换的属性。

    希望这会有所帮助,

    【讨论】:

      猜你喜欢
      • 2016-08-04
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多