如何使用groovy更改端点URL

时间:2015-05-13 03:13:34

标签: groovy soapui

我在测试套件级别使用了以下内容

result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT']);

在运行测试套件时,我得到下拉菜单以选择一个属性。现在选择属性后,它必须为所有测试用例设置终点URL并运行。

由于

2 个答案:

答案 0 :(得分:4)

每个testStep都有一个endpoint属性,这是要为此testStep调用的端点网址。如果您要更改testStep中每个testCase内的每个testSuite的所有端点,您可以循环更改此属性。为此,您可以使用例如具有以下代码的groovy testStep

def result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])
def testcases = testRunner.testCase.testSuite.getTestCaseList()
// for all testCases in your test suite...
testcases.each { testcase ->
    // for all testStep inside testCase...
    def teststeps = testcase.getTestStepList() 
    teststeps.each { teststep ->
        teststep.setPropertyValue('endpoint','http://yourUrl')
    }
}

如果您希望在Setup script testSuite内进行同样的操作,则需要更改代码,因为上下文中没有testrunner(相反,您可以使用直接testSuite var)。因此,如果您想将代码放在Setup script内,而不是在groovy testStep内,您可以使用以下代码:

def result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])
def testcases = testSuite.getTestCaseList()
testcases.each { testcase ->
    def teststeps = testcase.getTestStepList() 
    teststeps.each { teststep ->
        teststep.setPropertyValue('endpoint','http://yourUrl')
    }
}

希望这有帮助,

答案 1 :(得分:1)

您还可以设置所有endpoint属性,加usernamepassword,如下所示:

  • 打开界面查看器(右键单击界面)
  • 转到“服务端点”标签
  • 选择要用于测试会话的端点
  • 单击“分配”,然后选择要为此端点分配的位置。

快乐测试!