SDET Unicorns

Page Object Model – Selenide Tutorial Series

Table of Content

In this tutorial, we will cover how to implement Page Object Model in Selenide. Page Object Model is a popular design pattern to improve code readability and maintainability as well as to reduce duplicacy in your code. Selenide makes it really to get Page objects setup, let’s take a look at how we can do that –

Setup Page Class

We first need to setup a page class where we can store all our page locators and page methods.

public class HomePage {
// add locators and methods here
}

Setup Page Locators

Once base page class is setup, we can start adding the Page locators to the class –

public class HomePage {

    public SelenideElement getStartedBtn() {
        return $(By.id("get-started"));
    }

    public SelenideElement headingTitle() {
        return $("h1");
    }

    public SelenideElement logoLink() {
        return $(By.xpath("//a[@class=\"custom-logo-link\"]"));
    }

    public ElementsCollection linksList() {
        return $$("#primary-menu li[id*=menu-item]");
    }
}

Note: Make sure to import all the necessary packages from Selenide if auto-import doesn’t work.


Setup Page Methods

Now that we have the page locators setup, we can start adding in necessary page methods to reduce code duplicacy –

    public HomePage open() {
        Selenide.open("https://practice.automationbro.com/");
        return this;
    }

    public void assertUrl(String expectedUrl) {
        String url = WebDriverRunner.url();
        assertEquals(url, expectedUrl);
    }

Update Tests to use POM

In your test file, you need to initialize the HomePage class and then start replacing your locators and adding in page locators as well as page methods. Here’s an example –

    @Test
    public void testInteractingWithElements() {
        // Open page url
        home
            .open()
            .assertUrl("https://practice.automationbro.com/");

        // By ID
        home.getStartedBtn().click();

        // verify heading by CssSelector
        home.headingTitle()
            .shouldHave(text("Think different. Make different."));

        // verify by XPath
        home.logoLink()
            .should(be(visible));
    }

As seen above, in just few steps you can implement Page object model concepts in Selenide. To learn more, check out this video below –

Thanks for reading!

My Resources

Thrive Suite: The all-in-one WordPress theme I used to create my blog.
Jasper AI: My favorite AI writing tool.
Surfer SEO:  A tool to help you rank your content on the first page of Google.

Write Content Faster

5/5

Write blog posts that rank for affiliate terms!

Join our mailing list

Unlock the Secrets to Becoming a SDET Pro in the Industry!

Stay ahead of the curve! Join our mailing list for exclusive insights, tips, and the latest industry updates delivered straight to your inbox

Table of Content

Related Post

equivalence and boundary value

Understanding Equivalence Partitioning and Boundary Value Analysis in Software Testing

Software testing techniques help ensure software quality and reliability, by helping us select test cases intelligently from the collection of test cases, such that all test scenarios are covered.

Boundary Value Analysis and Equivalence Partitioning are two testing techniques that help testers select a subset of test cases that covers all important test scenarios, even under time and budget constraints. By testing all the equivalence classes and boundary values, testers can reduce the risk of releasing software with defects.

Read More »