Use of Object Repository

I then call the needed method in my test - cases to create a test-object to interact with.

Just so I’m clear, your page objects just have methods for creating test objects, yes? Then you are calling these keywords from your script to get test objects, which you then use to perform work (i.e. click(), sendKeys(), etc.)?

Is this considered an implementation of POM?

This is totally fine, and essentially replaces the OR with your own custom containers.

and Is there any other effective way of doing this?

Yes, there are plenty of ways to approach it. With any automation, these are the “big 3” items that you must handle to make scripts run smoothly and consistently:

1.) Location of elements
2.) Manipulation of those elements (clicking, sending keys, etc.)
3.) Waiting for the page to respond

Personally, I prefer that my page objects wrap all 3 of these, not just the location of elements as you are doing.

For an easy example, take a login page for some application. This page object might have 3 (or more) methods:

public class LoginPage {
    
    public void setUsername(String value) {
        // locate username field
        // set the value
        // wait for page response (if any)
    }

    public void setPassword(String value) {
        // locate password field
        // set the value
        // wait for page response (if any)
    }

    public void clickLoginButton() {
        // locate login button
        // click
        // wait for page response
    }
}

Then your script-writing becomes super easy. Want to set the username/password field, then click the login button? Call the appropriate methods, and the page object does all of the work for you; no extra thought required.

This opens up a lot of customization too. What if the usual click() method works for some buttons in your application, but not others? What if you need JavaScript to do some work in some part of the app? What if your wait condition works in some places, but not others? You don’t want to have to remember these kinds of caveats in each script you write, so having your page objects responsible for these things will save you a lot of headache.

3 Likes