Transcripted Summary

Here, we will understand how page objects are being used in the framework.

We will write our first test case together, run it, and look at the results.

I've got some good coffee for us. Let's get going.

Let's understand what the PageObjects are in our framework - a quick refresher on PageObjects to clear up the basics.

We are on the Accounts list page over here.

Now, while there are many web elements to interact with - from the top nav bar menu items and the list items themselves - in the framework we have modeled the Accounts list page as group of WebElements and methods for this area on the screen.



While this is not the best way, we can go more granular so that the PageObjects or components are further reusable.

Now, let's look at the same thing from our codebase.

Now we have our editor opened over here, Eclipse, we're looking at the code equivalent of what we just saw on the Salesforce UI with the Accounts list page.



Basically, we have the AccountListPage java class opened over here and, as part of the framework itself, we have modeled some of the elements on the UI, like the "New" button or the "SaveEdit" button.

That's pretty much about it.

Key things to note over here are that the PageObject itself extends SFPageBase from the framework.

Also, if you look closely, it follows the template provided by the PageObject design pattern with @FindBy notations and an initElements method with the PageFactory.

That being said, what do you do if you have to create a new PageObject?

You have two options.

Option one - create a new class in the pageobjects package over here or, the easier option, which I would prefer, is use an existing PageObject, copy it and paste it back.



Change it to the name that you require.

Let's say AccountListPage_new_example, and then take it from there.

Once you have the new Java class for the new PageObject that you're trying to model, you need to perform some more actions to ensure that it is instantiated correctly at runtime.

Check the class name and you need to ensure that this is set up in BaseTest because that is where all the PageObjects are instantiated.

What I will do is I will add a new variable for this. Let's say, acne.



It is an ugly name, metaphorically and literally, but we are just giving examples here.

In addition to declaring the variable for the PageObject, what we also need to do is ensure that it is instantiated correctly at runtime.

We are using the concept of reflections to do so, and around these lines, this is actually being instantiated.



What I'm going to do is copy an example from the previous line and then use it as a reference.

We try to get the class name at runtime and then get a PageObject using the PageFactory design pattern.

What you might need to do is actually import this into your BaseTest.

Once you're imported, our ID knows a reference point for this object.

After instantiating it, you can actually use it in one of our test cases, as you will see in the next section.

© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR