我正在编写一个时髦的脚本来执行/自动化我的测试套件。在一个测试用例中,我有一个HTTPRequest,其中有一个请求URL,参数(用户名和密码)和方法(GET)来获取令牌ID,然后将令牌ID传递给下一步(SOAP请求)获取数据。
我被困在需要使用groovy传递参数(用户名和密码),请求URL和方法(GET)的地步。 我在一个测试用例下手动创建了一个测试步骤,我只需要通过参数即可
当我在线搜索时,我知道如何传递标头,URL到如下所示的SOAP请求
def headers = new StringToStringMap()
testRunner = new com.eviware............WsdlTestCaseRunner(myTestCase,null);
testStepContext = new com.eviware.soapui........WsdlTestRunContext(testsetp);
headers.put("apikey", "abcd")
teststep.getTestRequest().setRequestHeaders(headers)
teststep.getHttpRequest().setEndpoint(encpointurl);
testsetp.run(testRunner ,testStepContext )
但是我想知道如何将参数传递给http请求(测试步骤)并运行它。
答案 0 :(得分:1)
使用 groovy.json.JsonBuilder 类完全可以在 groovy 中完成。
def body = new StringToStringMap()
def jsonbildr = new JsonBuilder()
body.put("username","Hackme")
body.put("password","LockUout")
def root = jsonbildr body
jsonbildr = jsonbildr.toPrettyString()
log.info(jsonbildr)
testStep.setPropertyValue("Request", jsonbildr)
输出:
{
"password": "LockUout",
"username": "Hackme"
}
答案 1 :(得分:0)
Inside your groovy teststep, you may set the properties using something like:
def properties = testRunner.testCase.getTestStepByName("Properties"); properties.setPropertyValue("name", "value");
Add the parameters directly in your request using variables in the format ${Properties#name} and replace "name" with the actual parameter name. This can be done both in the request body and in the URL if you should wish to do so.