Page Object Model testing

In the ongoing process of doing my code work on my Github, I came across an idea that I’d actually encountered before. But it was one for which I’d never previously had an identifying term, and I was excited to learn about this.

Namely, Page Object Model testing. (Not to be confused with Project Object Model, which is what the POM in a pom.xml file stands for when you’re working with Maven.)

What this is: a way of writing a test framework that separates “code that represents the thing you’re testing” from “code that actually does the testing”. Turns out I’d learned about how to do this at Big Fish, when I picked up the idea and how to implement in Python.

Back in those days, it helped to do this because it let me have test cases that basically said “okay go get me the page I need to test, and stick all the data representing it into this object, which I will then do tests against”. It meant that in setup for tests, all I had to do was go grab an instance of the object that represented the page to be tested. And that meant in turn that the tests themselves were more tightly focused.

I found that it required a bit more organizational work to set up, but that once I had the idea in place, it meant writing future tests became easier. For example, if I had test script A that tested the homepage of the site, and then later needed to write test script B against the same page, I wouldn’t have to rewrite the code that loaded the homepage for testing. Likewise, if something about the structure of the homepage changed, I would only have to change the class that dictated that structure, with possibly only minor changes to any test scripts that needed to deal with it.

I liked this way of organizing code well enough that I have been implementing it on my Github repos. In the Python Selenium demo, specifically.

But, now that I’m done with the initial wave of Selenium tests and am looking at ways to expand the suite in both Java and Python, I started thinking of how to rearrange the organizational structure of both suites and seeing whether I could do a similar structure in Java. That led me to discovering that this whole concept had a name.

And it also led me to being able to implement Page Object Model testing in the Java Selenium repo, too.

What this means in practical terms is that I can think of pages on my test WordPress site in terms of “here is an object that represents an entire page, including child objects”. These child objects would be things that are shared across all pages, like a sidebar, or a footer, or a menu. Their various objects are things I have to implement only once in a Page Object Model system, and then use as necessary in tests that actually look at them on different pages.

So all in all this has been a satisfying area of research.

Some links I’ve used to read up about this:

Page Object Model (POM) | Design Pattern on Medium.com

Getting Started with Page Object Pattern for Your Selenium Tests on Pluralsight.com

Coding projects update

I now have three active repositories up on my Github account. These are:

misc-configs: This one is for miscellaneous config files that are useful for the tests in the other repositories. What’s in here will mostly make sense to you if you are familiar with a) how to import data into a WordPress site, b) how to import Collections or Environment files into Postman, and/or c) how to use a YAML file to run Docker Compose to launch one or more containers.

wp-test-demo-java: This one is for my demo of testing the REST API endpoints made available by WordPress for any given site. Phase 1 of the work on this demo is complete, in which I test against the endpoints that handle publicly accessible data. I.e., the kinds of things you could find out about a WordPress site if you’re just a visitor to the site.

wp-test-demo-java-selenium: This demo is also using my test WordPress site, but here, I am doing front end testing rather than service testing. I’m using the Selenide Java library to run tests against the site via Selenium, a widely used automation framework for testing web pages. Selenide is a layer on top of Selenium that does the heavy lifting of Selenium setup for me, and frees me up to focus on the test cases I want to run.

This is a work in progress, but as of this post it has 27 test cases in it. There are more to come.

Other projects that’ll be showing up on my Github account include:

  • Phase 2 of the REST API project, which would involve hitting service endpoints that specifically require authentication.
  • Porting the Selenium tests over into Python, and structuring them in such a way as to be similar to the Python test framework we used on my former team at Big Fish. The intent here would be to demonstrate my ability to use Selenium in Python, and to write up a framework for it. (Which will require more work than the equivalent testing in Java!)
  • The teeny WordPress plugin I want to do that’ll make nice Dreamwidth-style user and community name tags in a post or page for me. (This is the one I’ve mentioned before that would be an expansion on the very old plugin that does this for LJ user and community tags.) This would be written in PHP, and the intent HERE would be to show my comfort level with PHP. I haven’t used this language as much in a professional context, but I HAVE used it a lot over the years dealing with my websites, and I can demonstrate that here.

Stretch goals:

  • Do something in JavaScript. What, I don’t know yet, but the obvious possibility would be to port some or all of the previously mentioned Selenium tests.
  • Since I do have a locally running plugin on annathepiper.org that fuels my Roleplay Logs page, time permitting, I’d like to do a more solid version of that. Right now the plugin I’m running is a hack of the previous non-Wordpress-based code, and it talks to a database outside the WordPress structure. A cleaner version of this would actually be properly integrated with WordPress. If I get really fancy, I could do an entry form in the Admin UI for WordPress to allow the addition of new logs, and possibly even reading them in via the Media section of the site. This would, of course, also be written in PHP. More on this as events warrant!