Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Selenium !
You have completed Introduction to Selenium !
Preview
The structure of a page is called Page Objects, but the classes you create don’t need to be entire pages, they can be sub-pages as well. In this video we will show you how that works.
Learn More
No cheating
My subpage Object
class Invitee {
constructor(element) {
this.element = element;
this.locators = {
editButton: By.css('button:first-of-type'),
editNameField: By.css('input[type="text"]'),
removeButton: By.css('button:last-child'),
confirmedCheckbox: By.css('input[type="checkbox"]')
}
}
changeName(name) {
const button = this.element
.findElement(this.locators.editButton);
button.click();
const textField = this.element.findElement(this.locators.editNameField);
textField.clear();
textField.sendKeys(name);
button.click();
}
// ...
Usage
homePage
.findInviteeByName("Jennifer Nordell")
.changeName("Craig Dennis");
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
All of them have very similar
properties and functionality.
0:00
Now, we could write methods on our main
page object, but that would require us to
0:02
continually pass the name of
the invitee to each of our new methods.
0:07
There's probably a better
API that we could design.
0:10
It's important to remember that
just like how you take your time to
0:14
design a software, you should also do the
same with your automation and test code.
0:17
You should always follow best practices
and create clean, understandable APIs.
0:21
You want other people to be able
to not only read your code, but
0:26
also being encourage to reuse it.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up