How to re-run a request and not re-run the whole test

Hi,

Is there a way to just run the failed request only and not previous requests that have already passed in the same test?

TestCase1 has
Create request
Update request
Delete request

Create passed
Update Failed (I only want to re-run this request before moving to Delete)
Delete

Moving each request to different tests is not an option for us. Some of these tests have to be together.

Thanks in advance

1 Like

You should modularize your existing test case scripts. You can use the callTestCase keyword.

1 Like

We have more than 200 test cases, we are hoping for something like “Retry Failed Requests immediately”?
Any code ideas, that we can put in a listener. For example, if the test case fails, look at the failed requests and re-run those only?

thanks

I don’t know such thing.

Perhaps, it is the time for you to refactor your 200 test cases to make them easier to maintain long term in future.

Hi,
Please advise how will callTestCase work here. Forget about the 200 testcases, lets say I’ve 10 testcases with 3-5 request in each test case. If a request 3 fails in Test1, how will callTestCase rerun that request only?

Thanks

I have made a minimalistic example of modularized Test Case script using callTestCase keyword.

Test Cases/TC

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')
WebUI.setViewPortSize(800,600)
String title = ""

title = WebUI.callTestCase(findTestCase("sub/demoaut.katalon.com"), ["greeting": "Hello!"])
WebUI.comment("${title}")

//title = WebUI.callTestCase(findTestCase("sub/www.google.com"), ["greeting": "How are you?"])
//WebUI.comment("${title}")

title = WebUI.callTestCase(findTestCase("sub/duckduckgo.com"), ["greeting": "Goodbye!"])
WebUI.comment("${title}")

WebUI.closeBrowser()

Teset Case/sub/demoaut.katalon.com

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.comment("${greeting}")
WebUI.navigateToUrl("http://demoaut.katalon.com")
WebUI.waitForPageLoad(10)
// do anything you want
WebUI.takeFullPageScreenshot("./out/demoaut.katalon.com.png")
return WebUI.getWindowTitle()

Test Cases/sub/www.google.com

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.comment("${greeting}")
WebUI.navigateToUrl("https://www.google.com")
WebUI.waitForPageLoad(10)
// do anything you want
WebUI.takeFullPageScreenshot("./out/www.google.com.png")
return WebUI.getWindowTitle()

Test Cases/sub/duckduckgo.com

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.comment("${greeting}")
WebUI.navigateToUrl("https://duckduckgo.com/?q=duckduckgo&atb=v314-1&ia=web")
WebUI.waitForPageLoad(10)
// do anything you want
WebUI.takeFullPageScreenshot("./out/duckduckgo.com.png")
return WebUI.getWindowTitle()

Log when “Test Case/TC” ran

The sub test cases can do anything

Test cases/sub/demoaut.katalon.com and other test cases can do anything you want. It can do hundreds of lines of data manipulation. To demonstrate the potential, the demo script just takes a screenshot of the page, as this:

How to re-run partially

Please find in the “Test Cases/TC”, a call to “Test Cases/sub/www.google.com” was commented out

...
//title = WebUI.callTestCase(findTestCase("sub/www.google.com"), ["greeting": "How are you?"])
//WebUI.comment("${title}")
...

You can easily edit the code so that the TC processes the Google next time. Also you can easily edit the code so that the TC comment out other URL (duckduckgo.com) next time.

Test Cases/TC_www.google.com

You can create one more test case

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI


WebUI.openBrowser('')
WebUI.setViewPortSize(800,600)
String title = ""

title = WebUI.callTestCase(findTestCase("sub/www.google.com"), ["greeting": "How are you?"])
WebUI.comment("${title}")

WebUI.closeBrowser()

This test case is self-contained. You can run it independently of others.


@mqamar

Are you a “Manual view” user? Can you use “Script view”? The idea of mine above requires you to work with Script mode. It requires seasoned programming skill. If you can only use the Manual mode, then my idea above would not be practical for you. Just forget it.

I wasn’t satisfied with the above implementation.

Both the Test Cases/TC and TestCase_www.google.com have repetitive lines, as this:

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')
WebUI.setViewPortSize(800,600)
... // statements 
WebUI.closeBrowser()

I wanted to get rid of code duplication as much as possible. So I changed my code set as follows


Include/scripts/groovy/com.kazurayam.ks.WthBrowser

I made a Groovy class com.kazurayam.ks.WithBrowser.

The source is as follows:

package com.kazurayam.ks

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

public class WithBrowser {

	public static void callClosure(Closure cls) {
		WebUI.openBrowser('')
		WebUI.setViewPortSize(800,600)

		cls.call();

		WebUI.closeBrowser()
	}
}

Test Cases/WB

I made a new Test Case.

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kazurayam.ks.WithBrowser
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WithBrowser.callClosure({
	String title = ""
	
	title = WebUI.callTestCase(findTestCase("sub/demoaut.katalon.com"), ["greeting": "Hello!"])
	WebUI.comment("${title}")
	
	//title = WebUI.callTestCase(findTestCase("sub/www.google.com"), ["greeting": "How are you?"])
	//WebUI.comment("${title}")
	
	title = WebUI.callTestCase(findTestCase("sub/duckduckgo.com"), ["greeting": "Goodbye!"])
	WebUI.comment("${title}")	
})

This worked just the same as Test Cases/TC

Test Cases/WB_www.google.com

I made one more Test Case

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kazurayam.ks.WithBrowser
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WithBrowser.callClosure({
	String title = WebUI.callTestCase(findTestCase("sub/www.google.com"), ["greeting": "How are you?"])
	WebUI.comment("${title}")
})

This worked just the same as Test Cases/TC_www.google.com.

The WB series are shorter than the TC series. You can hide the details of opening/closing the browsers inside the WithBrowser.callTestClosure() method. The WB series succesfully avoided code duplications. It’s good, isn’t it?

Hi Kazaurayam,
Thank you for the response. I’m sorry, I still don’t understand how this will help me with API requests failures.

My TestCase1 has the following requests: ( Please don’t mind the syntax, I just created few requests here as a test)

data1 = GetExcelSheetdata

WS.sendRequest(findTestObject(‘MyFolder/CreateUser’, [(‘User1’) : data1.get(‘User1’)]))
WS.sendRequest(findTestObject(‘MyFolder/GetUsers’, [(‘UserId’) : data1.get(‘UserId’)]))
WS.sendRequest(findTestObject(‘MyFolder/GetLocations’, [(‘Location’) : data1.get(‘Location’)]))
WS.sendRequest(findTestObject(‘MyFolder/GetReferences’, [(‘Ref1’) : data1.get(‘Ref1’)]))

Test Suite:
TestCase1
TestCase2
TestCase3

If request called “GetUser” fails, how do we re-run that request before moving on to ‘GetLocations’. We can’t re-run the testcase because of dependencies.

Thanks

Do you expect the 2nd or 3rd call to “GetUser” immediately after the 1st call to succeed ?

Really? It looks like a gambling with dice to me. Personally I have never worked on such target. Possibly I do not understand your idea.


If that is the case, why not you do:

try {
    WS.sendRequest(findTestObject(‘MyFolder/GetUsers’, [(‘UserId’) : data1.get(‘UserId’)]))
} catch (Exception e) {
    // retry the same after 1second
    Thread.sleep(1000)
    WS.sendRequest(findTestObject(‘MyFolder/GetUsers’, [(‘UserId’) : data1.get(‘UserId’)]))
}

If you want to repeat retry more times with an interval of few seconds, you would want to write a function:

def boolean retry(Closure cls, int times) {
    boolean result = false
    for (int i = 0; i < times; i++) {
        try {
            cls.call()
            result = true
        } catch (Exception e) {
            // retry the same after 1second
            Thread.sleep(1000)
        }
        if (result) {
            break
        }
    }
    return result
} 

// getting UserId while retrying maxim 10 times 
boolean result = retry({
    WS.sendRequest(findTestObject(‘MyFolder/GetUsers’, [(‘UserId’) : data1.get(‘UserId’)]))
}, 10)

In the Katalon Docs, I found the following page:

The “Debug” feature seems to be what @mqamar wants.

But I have never used the debug feature of Katalon Studio. I have no idea about it.

I seem to remember that there are a few previous posts in this forum that said “run-from-here does not work for me”. Search it if you want to read them.

I happened to find a previous post by @mqamar .

It seems that @mqamar has been struggling with a single problem for the last 2 years.