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.

1 Like

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.

3 Likes

@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.

Sorry for late reply. Im so busy in my new project. I have invite collab you to my github project. I cannot set it to public.

I always prefer being involved in the open discussions. I do not like to be involved in your private project. So, I would decline to accept your invitation to your private GitHub repository, sorry.

@qaat.hanh

I regard the “Page Object Model” is something as described in the Guru99 article: “Page Object Model(POM)”

I think that “Page Object Model” is a design pattern in the class-based Object Oriented Programming domain. I think that Katalon Studio is a domain-specific tool for Browser automation. It does not fit for the real Object Oriented Programming.

I think that “Page Object Model” deserves unit-testing frameworks: JUnit or TestNG. Katalon Studio doesn’t help users to perform unit-testing for their custom classes in the “Keywords” folder using JUnit or TestNG. Therefore I have no idea how to implement the “Page Object Model” without unit-testing framework. I don’t think that I can implement what I regard a real “Page Object Model” in Katalon Studio. If I want to apply POM to my project, I would not do it in Katalon Studio. I would do it in a Gradle Java project with WebDriver + TestNG plus ExtentReport.

I suppose that you, @qaat.hanh, might be able to invent something unique in Katalon Studio. But it would be different from what I regard POM.

I think that design pattern is still, even with Katalon Studio’s weird antics, good to use in something like Katalon Studio.

Yes, it is harder for KS to log, but it separates the redundant actions code from the actual Test Cases.

I would even take it further and create classes for each section of each page in the testing code base.

@qaat.hanh to answer your question, the methods should be written for the GENERAL ACTIONS on the page (e.g. filling out a whole section of the page).

Don’t let your programming skills falter tho (as I’ve seen a lot of other test developers do). Keep your methods short and simple (no more than, say, 50 lines of code).

If you find yourself having to write a lot of conditional logic in those methods just to handle certain cases, to fill out parts of the section, consider making classes for each of those sections and move your implementation there.

I wouldn’t put methods for just one action step though…

Hi @qaat.hanh,

Have you solved this issue or satisfied with this? If yes, please help provide and mark solution so that others can take it as reference. If no, please help follow up with the discussion or close it.

Thank you

Thanks everyone for helping. During the work and some sample from kazurayam I has found the best practice for us. It is pretty long so I will share it later.

1 Like