In the login POM we can observe the following improvements that can be made:
- Move all selectors to constants
- Use the short-hand notation for initializing the class variables
- Move all texts to constants
- Avoid nth methods
Since we are already familiar with the first two action items, let's implement
them now.
Now let's deal with the 3rd action item. Let's move all the hard-coded texts to
constants. For this let's create a directory called texts
within the
constants
directory. Since all the texts we're dealing with are on the
dashboard page, we will create a new file called dashboard.ts
where we will
extract all the texts related to the dashboard page. Just like for the
selectors, we will create an index.ts
file which will export all the
constants for easier imports across modules.
Additionally there are some texts which are common across multiple pages like
the username Oliver Smith
. We will move such texts to a file called
common.ts
within the texts
directory.
Now that we have created all the files and directories, let's extract the
texts and refactor the code.
Great! Now we have to deal with the final action item for the POM. This
involves removing all the nth methods. But our use-case here is to ensure
that the starred task is moved to the top of the list. That means we need to
ensure that the first row of the table is the starred task. This is a
genuine use case for the nth methods and it cannot be avoided. So instead of
removing it, let's add a comment in the code stating our intentions for
breaking a best practice.