How to optimize your tests using the Page Object Model.

Image for post
Image for post
Photo by John Barkiple on Unsplash

What is PageObject?

Page Object Model is an object design pattern, in which for every web page in the application, there should be a relevant page class, various elements on the page are defined as variables on the class. To interact with different elements of web page methods are implemented in the class.

public class HomePage {

//Variables
@FindBy(xpath = "xpath")
private WebElement signInButton;
@FindBy(xpath = "xpath")
private WebElement userAvatar;
//Methods
public void clickSignInButton() {
signInButton.click();
}

Why should we use the Page Object Model?

So now with every change on a webpage, we have to change the code of our tests only in one place. …


Use AssertJ for fluent and more readable assertions.

Image for post
Image for post
Photo by timJ on Unsplash

What’s the difference between JUnit and AssertJ

Hi, there!

First of all, JUnit is an automated test framework that is built in Java, whereas AssertJ is an opensource library used for writing fluent and rich assertions in Java tests.

It’s true that you can write assertions just using JUnit, but if you ever have an extra half an hour for studying AssertJ, be sure to go for it. It will make your working process more effective and your code more readable.

Why should I use AssertJ?

  • easy to learn: Ready to dive in AssertJ? You can find all about AssertJ here.

Took me less than half an hour to get AssertJ.

  • easy to use: you just need to add a dependency and static import in your test class to start using AssertJ. …

About

Ania Duldiier

QA and free artist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store