Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
785 views
in Technique[技术] by (71.8m points)

soapui - How to parse a URL to fetch it's parameters in groovy?

I am new to groovy scripting and looking on to parse the URL and print it's parameter.

This url is : https://www.google.com/?aaa=111&bbb=222&ccc=33&dd=1484088989_b23f248ac6e5d9a9b47475526bb92ee1

How can i fetch dd parameter from the URL?

I appreciate your help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to add a groovy script.

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def testCase = context.testCase;
def testStep = testCase.getTestStepByName("NAME_TESTStepRequest");  
def endpoint =testStep.getPropertyValue('Endpoint');
log.info endpoint;
def url = new URL(endpoint)
//def url = new URL("https://www.google.com/?aaa=111&bbb=222&ccc=33&dd=1484088989_b23f248ac6e5d9a9b47475526bb92ee1")

// get all query params as list
def queryParams = url.query?.split('&') // safe operator for urls without query params
// transform the params list to a Map spliting 
// each query param
def mapParams = queryParams.collectEntries { param -> param.split('=').collect { URLDecoder.decode(it) }}
// assert the expected values
log.info mapParams['aaa']
//assert mapParams['aaa'] == '111'
log.info mapParams['bbb']
//assert mapParams['bbb']== 'abc'
log.info mapParams['dd']
//assert mapParams['dd']=='023423'

Please you check this post.Get query params from request url soapui using groovy


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...