This chapter will focus on where we will put our page objects, and how we'll keep them organized as our application grows.
Here's what our project looks like right now:
$:> tree test/pages/
test/pages/
├── base.js
├── login.js
├── polls
│ ├── table
│ │ ├── columns.js
│ │ └── rows.js
│ └── table.js
└── profile
├── basic.js
├── politics.js
└── social.js
3 directories, 8 files
PROTIP: You can install
tree
viabrew install tree
for mac, orsudo apt-get install tree
in Linux.
However, all of these files are empty. They are just placeholders to allow some observations about their structure.
Namely,
- Our more complex web pages are actually page directories.
- We need to be able to keep things that belong on the same page together, but not in the same file.
- Our files describe parts of our entire page.
- Our "polls" page directory could just be one file. But we keep it separate to allow rows and columns to support more and more functionality without sacrificing readability of our code base.
- This also holds true for components on pages, too. See
test/pages/polls/table
, and the corresponding file,test/pages/polls/table.js
, which acts as a top-level container for the more complex modules found in thetable/
directory beside it.
- Our pages get namespaced this way.
- That way, if our profile gets a table later, it doesn't need to be called
profileTable.js
. It's justprofile/table.js
, which compartmentalizes our thinking when working on one tiny section of a larger application.
- We can nest this as deep as we need to.
- Don't like that
profile/politics.js
isn'tprofile/politics/form.js
instead? Well, then change it! This also holds true over time. If our profile page(s) get larger, smaller, or anything in between, shifting things around inside of it's own domain is relatively unobtrusive.
Next, we'll take a look at writing our first page object, which navigates us past the front page to the login page. There we'll introduce Astrolabe, a tool designed to make page objects much easier to read and write.
Run
$> git checkout -b chapter-2 origin/chapter-2
to skip ahead, or just visit this branch in your browser.