Skip to end of metadata
Go to start of metadata

A method consists of instructions to perform a specific task. Defined methods can be called for reused later. Refer to Method Call Statements for more details regarding how to call a defined method.

Define a method in Manual view

  1. Open a test case in Manual view, then select to add Method from command toolbar.


  2. The Method builder dialog is displayed. 

    Specify the required information for your method as following:

    FieldDescription
    NameThe name of the method.
    Return type

    The object type that this method will return after its execution.

    Setup, Teardown options

    Select any checkbox to indicate whether it should be a setup() or teardown() method. Refer to SetUp() and TearDown() in Manual view for more details.

    Parameter list

    Any parameter needed to pass into the method.

    By clicking on the Insert button, a row will be appended into the grid. You can then change the type and name of the parameter by double clicking and editing the appropriate cell.

    Click OK after configuring the method details.

     

  3. A test step representing the recently defined method is added to the test case. You can switch to Script view to define content for the method.


  4. Save the test case when you're done.

    Once a test step is defined as Method, it will not be allowed to change into another keyword.

SetUp() and TearDown() in Manual view

Automation testers usually want to specify prerequisite and clean-up configuration for their test cases.

With the prerequisite configuration, certain actions must be taken before starting test execution. For clean-up configuration, some actions must be carried out after the test execution finishes.

This can be achieved using the setup() and teardown() methods. 

MethodDescriptionCommon Usage

Set Up

This method is always called first prior to executing main test steps.

Prepare testing environment such as:

  • Starting new browser with clean cookies
  • Creating temporary & proxy databases, directories
  • Starting a server process
  • ...

Tear Down If Failed

This method will be called after executing all steps of the test case and one of those steps has Failed status.

Clean-up testing environment such as:

  • Closing browsers
  • Disclosing opened connections to database or server
  • ...

 

Tear Down If Passed

This method will be called after executing all steps of the test case and all of those steps have Pass status.

Tear Down If Error

This method will be called after executing all steps of the test case and one of those steps has Error status.

Tear Down

This method will be called finally.

The SetUp()/TearDown() methods will have Error status if there is any issue occurred during their execution. The only exception to this is when AssertionError Class is used or the methods are skipped.

 

Define a method in Scripting view

The Script view of a test case allows you to programmatically define and handle methods easily using either Groovy or Java language. Refer to http://groovy-lang.org/structure.html#_methods for details about methods in Groovy.

For example:

SetUp() and TearDown() in Scripting view

You can declare a method as setup() or teardown() method using the appropriated annotation above it:

@com.kms.katalon.core.annotation.SetUp
@com.kms.katalon.core.annotation.TearDown
@com.kms.katalon.core.annotation.TearDownIfFailed
@com.kms.katalon.core.annotation.TearDownIfPassed
@com.kms.katalon.core.annotation.TearDownIfError

For example:

 

  • No labels

1 Comment

  1. Anonymous

    You actually make it seem really easy together with your presentation but I in finding this matter to be really something that I feel I would by no means understand. It sort of feels too complex and extremely broad for me. I'm looking forward for your next publish, Ill try to get the cling of it! dkgefeckbdgaekad