Hi,
I have a WS object defined and I am trying to call it twice (each time using a different base URL - QA and PROD). This url is defined as a global variable and referenced in the variables tab of the ws object. It all works fine until I try to change the url from a function I have created like this:
GlobalVariable.env_url = “http://dev.mysite.com”
def response1 = WS.sendRequestAndVerify(requestObject)
GlobalVariable.env_url = “http://prod.mysite.com”
def response1 = WS.sendRequestAndVerify(requestObject)
this has no affect on the URL the object references when executing the below code…any ideas? Thanks
class Compare {
/**
* Send request and compare responses b/t two server instances
* @param request object - must be an instance of RequestObject
*/
@Keyword
def compareWsResponses(requestObject) {
//send requests
GlobalVariable.env_url = "http://apidev.mysite.com"
def response1 = WS.sendRequestAndVerify(requestObject)
KeywordUtil.logInfo("QA URL: " + requestObject.getRestUrl())
GlobalVariable.env_url = "http://api.mysite.com"
def response2 = WS.sendRequestAndVerify(requestObject)
KeywordUtil.logInfo("PROD URL: " + requestObject.getRestUrl())
//parse response
def parsedJson1 = new groovy.json.JsonSlurper().parseText(response1.getResponseBodyContent())
def parsedJson2 = new groovy.json.JsonSlurper().parseText(response2.getResponseBodyContent())
//JSONAssert.assertEquals(parsedJson1, parsedJson2, JSONCompareMode.STRICT)
//compare responses
if (parsedJson1 == parsedJson2) {
println('PASS')
KeywordUtil.markPassed('Responses Matched!')
} else {
println('FAIL')
KeywordUtil.markFailed('Responses did not match!')
}
KeywordUtil.logInfo("QA Response: " + parsedJson1.toString())
KeywordUtil.logInfo("PROD Response: " + parsedJson2.toString())
}
}