Get API response and execute UI test cases

I have a generic Katalon project, first it runs a API test. Based on API response(HTTP 200), test suppose to execute UI test cases.

First I tried to use globalvariable to store API response but it didn’t work.

Is there any good approach to handle this scenario? Feed back is really appreciate.

Thanks,
Thushar

Please show your code and error log to us.

You could use a Test Listener. I would create a TestCaseListener which would look like this:

class TestCaseListener {
	/**
	 * Executes before every test case starts.
	 * @param testCaseContext related information of the executed test case.
	 */
	@BeforeTestCase
	def loginBeforeTestCase(TestCaseContext testCaseContext) {
		def testCaseId = testCaseContext.getTestCaseId()
		
		def idsToSendAPIRequestBeforehand = [
			"Test Cases/UsersTests/CreateUser",
			"Test Cases/Utility/TestConnection"
		]

		if(idsToSendAPIRequestBeforehand.contains(testCaseId)) {
			def response = WS.sendRequest(findTestObject('AuthenticationService/POST_Sign-in'))
			def statusCode = WS.getResponseStatusCode(response)
			if (statusCode != 200) {
				testCaseContext.skipThisTestCase()
			}
		}
	}
}

So, before every UI Test Case, if the ID of the wanted UI Test Case is in the list, then you will send an API call to, let’s say, login. If the login is not successful, skip the UI Test Case, otherwise, go on with the UI Test Case.

@Oli , thanks for your reply. I will try this solution and let you know how it went. Thanks again.

1 Like