abhilasha singh
abhilasha singh

Reputation: 7

How to call a method from one test case by using Katalon Studio?

How to call a method from one test case by using Katalon Studio?

For example, I have a test case Purchase order and I have two test methods(test method1 and test method2 in it, Now what I want to do is, I want to create a new test case and call only test method2 in it.

Please suggest

Upvotes: 1

Views: 2277

Answers (2)

Mike Warren
Mike Warren

Reputation: 3886

If that method2 consist purely of actions on one page, you could implement page object model:

package com.yourEntityName.pages;

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject;

import com.kms.katalon.core.exception.StepFailedException;
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI;

public class YourPage { 

    public void method2() throws StepFailedException { 
       // ...implementation goes here...
    }

}

and just call it from the two test cases:

new YourPage().method2();

NOTE: a couple things about this:

  • this is called a Custom Keyword. More on that here.
  • there is no logging of any of the steps of this method, so you might want to KeywordUtil.logInfo() the important steps
  • as corollary to second bullet point, git gud at debugging/troubleshooting, and
  • make damn sure that whatever code you write here works seamlessly

Upvotes: 0

plaidshirt
plaidshirt

Reputation: 5681

You can simply call an existing test case from a test case with this code:

WebUI.callTestCase(findTestCase({Test Case ID}), [key1:value1, key2:value2, … , keyN:valueN], FailureHandling.option)

A quick example:

WebUI.callTestCase(findTestCase('TestCaseToCall'), [:], FailureHandling.STOP_ON_FAILURE)

Upvotes: 2

Related Questions