Forum Discussion
- hrn83auOccasional Contributor
hi,
We wrote the following groovy script using the TestRunListener.afterrun event, but this script works rest abi whether the test automation is successful or not. What can I do to make it work only when it fails.
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URLdef restApiUrl = "URL"
def url = new URL(restApiUrl)
def connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "GET"if (connection.responseCode == HttpURLConnection.HTTP_OK) {
def response = new StringBuffer()
def reader = new BufferedReader(new InputStreamReader(connection.inputStream))
String line
while ((line = reader.readLine()) != null) {
response.append(line)
}
reader.close()
println("REST API Yanıtı: " + response.toString())
} else {
println("REST API çağrısı başarısız: " + connection.responseCode + ", " + connection.responseMessage)
}connection.disconnect() - nmraoChampion Level 3
Simple. Make the following change in the above groovy script.
- Read the previous test step response, use context.response
- Add the condition to determine if the test fails.
- If fails, then call the above code i.e., call your above code conditionally.
Related Content
- 7 years ago
- 7 years ago
Recent Discussions
- 3 days ago