Ask about POM (Page Objects Model)

I write test in Katalon follow the desig pattern POM but recently found some problem of my structure. So I wanna ask some advice or personal experiment to enhance my work.

1. Where should store the page object. In folder keywords or Include?
I placed it in folder keywords. But every function need to have static to allow them can be recognize in test case. And when call that function it need to has prefix call that class even it’s name is unique. I haven’t try place in Include, does it can write script shorter than place in keywords.

2. Can I write a single function call element has declared to do action? Does it can take more effort to maintain test case?
example:

def static ifHasElement(element) {
		Mobile.waitForElementPresent(findTestObject(element), GlobalVariable.time10, FailureHandling.CONTINUE_ON_FAILURE)
	}

Because most screen of app I need to test has a lot of element. On average, each page has about 10 elements that need to be declared. If I create function for single action of every element then the page object will be very long.

3. Should I create only function for single action (step around 10 lines or less). Like wait element present, wait element not present, verify element exist, verify element not exist, tap element, get attribute, tap and click, tap and send key… Or beside single action, create the complex action in page object.

4. Create a common page object for elements can be appear in different screen or recreate multi time when it has in screen to avoid forgetting.

In other words, what’s the difference between the Keywords folder and the Include folder?

I made a small project for experiment. I used Katalon Studio v9.0.0.

Keywords/my/bogus/KeywordClazz.groovy

package my.bogus

import com.kms.katalon.core.annotation.Keyword

public class KeywordClazz {

	@Keyword
	def hello(String name) {
		println "Hello, ${name}"
	}

	def konnichiwa(String name) {
		println "こんにちは ${name}"
	}
}

Include/scripts/groovy/my/greatest/IncludeClazz.groovy

package my.greatest

import com.kms.katalon.core.annotation.Keyword

public class IncludeClazz {
	
	@Keyword
	def bonjour(String name) {
		println "Bonjour! ${name}"
	}
	
	def salut(String name) {
		println "Salut! ${name}"
	}
}

Test Cases/TC1

in Script view

import my.bogus.KeywordClazz
import my.greatest.IncludeClazz

CustomKeywords.'my.bogus.KeywordClazz.hello'('qaat.hanh')

new my.bogus.KeywordClazz().hello('qaat.hanh')

new KeywordClazz().konnichiwa('quaat.hanh')

CustomKeywords.'my.greatest.IncludeClazz.bonjour'('POM')

new IncludeClazz().salut("POM")

in Manual view

When executed, I saw

2024-11-27 22:32:15.321 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-11-27 22:32:15.325 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TC1
2024-11-27 22:32:15.892 DEBUG testcase.TC1                             - 1: my.bogus.KeywordClazz.hello("qaat.hanh")
Hello, qaat.hanh
2024-11-27 22:32:15.991 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - my.bogus.KeywordClazz.hello is PASSED
2024-11-27 22:32:16.013 DEBUG testcase.TC1                             - 2: KeywordClazz().hello("qaat.hanh")
Hello, qaat.hanh
2024-11-27 22:32:16.040 DEBUG testcase.TC1                             - 3: KeywordClazz().konnichiwa("quaat.hanh")
こんにちは quaat.hanh
2024-11-27 22:32:16.063 DEBUG testcase.TC1                             - 4: my.greatest.IncludeClazz.bonjour("POM")
Bonjour! POM
2024-11-27 22:32:16.084 INFO  k.k.c.m.CustomKeywordDelegatingMetaClass - my.greatest.IncludeClazz.bonjour is PASSED
2024-11-27 22:32:16.090 DEBUG testcase.TC1                             - 5: IncludeClazz().salut("POM")
Salut! POM
2024-11-27 22:32:16.146 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TC1

Conclusion

There seems to be no significant difference between the Keywords folder and the Include/scripts/groovy folder.

Still confused?

The only difference between the Keywords folder and the Include folder is the way how each folders are described in the Katalon documentation. The doc says:

  • Keywords folder is the place where you should locate your Custom Keywords
  • Include/scripts/groovy folder is the place where you should locate your Step Definitions for BDD/Cucumber tests.

And Katalon documentation does not mention where a user should locate an arbitrary Groovy class source file which is neither a custom keyword nor a step definition. I guess, the original Katalon creator didn’t envisage users want to create their own general-purpose Groovy classes.

I suppose that the document confused @qaat.hanh.

1 Like

@qaat.hanh

You are wondering about something that is deducted from a misunderstanding: you think that the Keywords folder and the Include folder are somehow different. But my experiment revealed that there is no difference.

I would recommend you to read my Test Case TC1 above. There you would find something you weren’t aware of.

As for POM, it is difficult for me to understand @qaat.hanh’s discussion unless his Katalon project is disclosed so that we can read his code (test cases, keywords, inludes) in its entirety.

Any disussion about POM in the forum format will be stressful. Without sharing a code base, we can not understand each other about their idea what POM is and how POM should be. I am afraid that we can not discuss about POM productively in this user forum which provides very little support for code sharing.

If @qaat.hanh publishes his katalon project open at GitHub, then people would be able to carry out code reviews, which could be productive.