<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Angie Jones on Medium]]></title>
        <description><![CDATA[Stories by Angie Jones on Medium]]></description>
        <link>https://medium.com/@jones.angie?source=rss-6ddbd027381e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xlwiZto-Vp_o79Oc.</url>
            <title>Stories by Angie Jones on Medium</title>
            <link>https://medium.com/@jones.angie?source=rss-6ddbd027381e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:14:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jones.angie/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Object-Oriented Principles in Test Code]]></title>
            <link>https://medium.com/test-automation-university/using-object-oriented-principles-in-test-code-67f67d5b9d0?source=rss-6ddbd027381e------2</link>
            <guid isPermaLink="false">https://medium.com/p/67f67d5b9d0</guid>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Angie Jones]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 19:37:11 GMT</pubDate>
            <atom:updated>2020-06-09T22:31:41.063Z</atom:updated>
            <content:encoded><![CDATA[<p>When writing test code, it’s important to exercise the same care that you’d use when developing production code. Here are common ways to use OO principles when implementing test code.</p><p><strong>Encapsulation</strong><br>The Page Object Model design pattern is commonly used in test automation. This pattern prescribes creating a class to interact with each page of the application under test. Within this class are the locator objects for the elements of the web page, and the methods to interact with those elements.</p><p>To keep things clean and safe, it’s best to properly encapsulate by restricting access to the locators themselves and only exposing their corresponding methods.</p><pre> public class SearchPage {<br> <br>    private By searchButton = By.id(“searchButton”);<br>    private By queryField = By.id(“query”);<br> <br>    public void search(String query) {<br>       driver.findElement(queryField).sendKeys(query);<br>       driver.findElement(searchButton).click();<br>    }<br> }</pre><p><em>Example of Page Object Model design pattern. Note: </em><em>driver declaration omitted for brevity.</em></p><p><strong>Inheritance</strong><br>While inheritance should not be abused, it can certainly be useful in test code. For example, given there’s a header and footer component that exists on every page, it’s redundant to create fields and methods for interacting with the elements of these components within every Page Object class. Instead, create a base Page class containing the common fields and methods that exist on every page, and have your Page Object classes inherit from this class. By using this approach, your test code will have access to anything in the header and footer no matter what Page Object they are currently interacting with.</p><p>Another good use case for inheritance within test code is when a given page has various implementations. For example, your app may contain a User Profile page which has different functionality based on roles (e.g. Administrator, Member). While there are differences, there could also be functionality that is the same. Creating two classes and duplicating code in both is not ideal. Instead, create a ProfilePage class which contains the common elements/interactions, and create subclasses (e.g. AdministratorProfilePage, MemberProfilePage) that implement the unique interactions and inherit the common ones.</p><p><strong>Polymorphism</strong><br>Assume we have a convenience method that goes to the User Profile page. This method doesn’t know what type of profile page it is — an Administrator or a Member.</p><p>You’re faced with a design decision here. Do you make two methods — one for each of the profile types? This seems like overkill since they both would do the exact same thing but just have a different return type.</p><p>Instead, return the super class (ProfilePage) since both AdministratorProfilePage and MemberProfilePage are both subclasses of ProfilePage. The test method which is calling this convenience method has more context and can cast accordingly.</p><pre> <a href="http://twitter.com/Test">@Test</a><br> public void badge_exists_on_admin_profile(){<br>    var adminProfile = <br>       (AdministratorProfilePage)page.goToProfile(&quot;<a href="http://twitter.com/admin">@admin</a>&quot;);<br>    //…<br> }</pre><p><strong>Abstraction</strong><br>Abstraction is used sparingly in test code, but there are valid use cases. Consider a type of widget that has been customized for different usages throughout the app. Creating an abstract class that specifies the behaviors expected is helpful when developing classes that interact with specific implementations of that widget.</p><pre>public abstract class ListWidget {</pre><pre>   protected abstract List&lt;WebElement&gt; getItems();</pre><pre>   int getNumberOfItems() {<br>       return getItems().size();<br>   }<br>}</pre><pre>public class ProductList extends ListWidget {</pre><pre>   private By productLocator = By.cssSelector(&quot;.product-item&quot;);</pre><pre>   @Override<br>   protected List&lt;WebElement&gt; getItems() {<br>      return driver.findElements(productLocator);<br>   }<br>}</pre><p>Angie Jones is the Director of <a href="https://info.applitools.com/uwi7">Test Automation University</a>. Check out her courses <a href="https://info.applitools.com/uwi8">here</a>.</p><p><em>Test Automation University is sponsored by </em><a href="https://info.applitools.com/uw9e"><em>Applitools</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67f67d5b9d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/test-automation-university/using-object-oriented-principles-in-test-code-67f67d5b9d0">Using Object-Oriented Principles in Test Code</a> was originally published in <a href="https://medium.com/test-automation-university">Test Automation University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tips for Healthy Page Object Model Classes]]></title>
            <link>https://medium.com/test-automation-university/tips-for-healthy-page-object-model-classes-e5071fccaf7f?source=rss-6ddbd027381e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5071fccaf7f</guid>
            <category><![CDATA[page-object-model]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[page-object-pattern]]></category>
            <category><![CDATA[page-object]]></category>
            <dc:creator><![CDATA[Angie Jones]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 19:36:49 GMT</pubDate>
            <atom:updated>2020-06-09T22:31:17.824Z</atom:updated>
            <content:encoded><![CDATA[<p>The most popular design pattern used in web UI test codebases is the Page Object Model (POM) design pattern. This pattern suggests modeling a class to represent a single page of your system under test. Using this model, the class would contain properties that represent the elements of the UI page and methods that interact with these elements.</p><p>Given this is the Login Page of our application, let’s discuss tips for building a class using POM.</p><figure><img alt="login form with username field, password field, and sign in button" src="https://cdn-images-1.medium.com/max/557/1*x5ojnlgAspPNu7ZZlfK26Q.png" /></figure><h3>The Class</h3><p>We make a single class in our automation framework to represent this page. It’s recommended to ensure the name of the class is representative of the page in the application so that other developers can quickly find the class associated with a given UI page.</p><p>So, in this example, we’d make a class called LoginPage.</p><pre>public class LoginPage {</pre><pre>   private WebDriver driver;</pre><pre>   public LoginPage(WebDriver driver){<br>      this.driver = driver;<br>   }<br>}</pre><h3>Properties</h3><p><em>LoginPage</em> should contain properties for each of the elements on the page that will be used within your tests. The value of these properties are locators to the elements on the actual page. By defining these locators in one place, you won’t need to hardcode them in every place that you use them — thus, eliminating duplication.</p><pre>private By usernameField      = By.id(&quot;username&quot;);<br>private By passwordField      = By.id(&quot;password&quot;);<br>private By signInButton       = By.id(&quot;log-in&quot;);<br>private By rememberMeCheckbox = By.id(&quot;rememberMe&quot;);<br>private By twitterIcon        = By.id(&quot;twitterIcon&quot;);<br>private By facebookIcon       = By.id(&quot;fbIcon&quot;);<br>private By linkedInIcon       = By.id(&quot;linkedInIcon&quot;);<br>private By errorMessage       = By.id(&quot;alert&quot;);</pre><h3>Methods</h3><p>In addition to the properties, the class should also contain methods that enable a test to interact with the application, such as setting input fields and clicking buttons. Here are some tips on designing these methods to be optimally used by your tests.</p><p><strong>Add Getters and Setters</strong></p><p>The purpose of POM classes are to set and get the state of your application. So, you’ll need methods to do this.</p><p>For example, we definitely need to set the username and password fields, so set methods should be added.</p><pre>public void setUsername(String username) {<br>    driver.findElement(usernameField).sendKeys(username);<br>}</pre><pre>public void setPassword(String password) {<br>    driver.findElement(passwordField).sendKeys(password);<br>}</pre><p>We also need to know the content of the error message, so this will need a getter method.</p><pre>public String getErrorMessage() {<br>    return driver.findElement(errorMessage).getText();<br>}</pre><p><strong>Only Add What’s Currently Needed</strong></p><p>Notice, we didn’t add getter and setter methods for every field, because we don’t have a need for them in our tests. Only add what’s currently needed. You can always add more if a new test requires such. This will prevent you from needing to maintain unused code.</p><p><strong>Transitions Should Return New Objects</strong></p><p>You’ll also need methods for clicking links and buttons. However, when your click results in a page change, your method should return a handle to the class representing the UI page you’ve transitioned to.</p><p>For example, if clicking the sign-in button will lead to the home page of your application, then your method should return a handle to the class representing that home page.</p><pre>public HomePage clickSignInButton() {<br>    driver.findElement(signInButton).click();<br>    return new HomePage();<br>}</pre><p>By providing this, all calling tests know that a transition will occur by calling this method, and the test has a handle to the necessary object to continue interacting with the application.</p><p><strong>Don’t Be Afraid to Make Convenience Methods</strong></p><p>Right now, logging into the application would take at least three method calls (setUsername, setPassword, and clickSignInButton). As these three are commonly used together, it makes sense for your class to also provide a convenience method so that your tests only need to call one method.</p><pre>public HomePage login(String username, String password) {<br>    setUsername(username);<br>    setPassword(password);<br>    return clickSignInButton();<br>}</pre><p>Notice we did not implement the logic within this method, but instead called the individual methods. It’s important to have those separate methods available, so that negative tests (e.g. set username but not password) can utilize them.</p><p><strong>Be Mindful of State</strong></p><p>For checkbox elements (or other toggles), simply clicking them may not satisfy the desired intent of the test. For example, what if your test wants the box to be checked, but it’s already checked? Calling a click method would give you the opposite of what you want. Instead, make your method more sophisticated by implementing logic that will only check the box if it’s needed to give the user their desired result. To do this, instead of blindly clicking, accept an argument that specifies intent (i.e. do they want it selected or deselected) and act accordingly.</p><pre>public boolean isRememberUsernameChecked() {<br>    return driver.findElement(rememberMeCheckbox).isSelected();<br>}</pre><pre>public void setRememberUsername(boolean checkIt) {<br>    boolean alreadySelected = isRememberUsernameChecked();</pre><pre>    //only click if the intent does not match the current state<br>    if( (checkIt &amp;&amp; !alreadySelected) || <br>        (!checkIt &amp;&amp; alreadySelected)) {</pre><pre>        driver.findElement(rememberMeCheckbox).click();<br>    }<br>}</pre><h3>Keep POM Classes Neutral</h3><p>Your POM class should be a neutral entity that interacts with and gathers information about your application. Be careful to keep your methods neutral and ensure they are generic enough to be used by any test that wishes to interact with the page. This basically means do not include assertions within these methods.</p><p>By keeping the methods neutral, they can be used in both positive and negative tests. The test can use the information returned from the class for its own purposes in determining whether that information warrants a pass or fail.</p><p>For example, what if our method that gets the error message also fails the test if the message is visible?</p><pre>//This is bad. don&#39;t copy this<br>public String getErrorMessage() {<br>    String message = driver.findElement(errorMessage).getText();<br>    if(message.isDisplayed()){<br>        assert.fail(message);<br>    }<br>    return message;<br>}</pre><p>I cannot reuse this method for tests where I want to make sure an error message is shown when the username or password is incorrect or not provided. This is because the POM class has taken it upon itself to determine that the display of an error message is a failure; when in these cases, that’s not so. Instead, just return the state and allow the test to determine what that means.</p><pre>public String getErrorMessage() {<br>    return driver.findElement(errorMessage).getText();<br>}</pre><h3>Healthy Code Makes Healthy Tests</h3><p>These tips should help you design healthy classes that implement the Page Object Model design pattern. The use of this pattern promotes separation of concerns (e.g. tests vs managing state), reduces code duplication, and provides reusable methods. Happy testing!</p><p>Angie Jones is the Director of <a href="https://info.applitools.com/uwi7">Test Automation University</a>. Check out her courses <a href="https://info.applitools.com/uwi8">here</a>.</p><p><em>Test Automation University is sponsored by </em><a href="https://info.applitools.com/uw9e"><em>Applitools</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5071fccaf7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/test-automation-university/tips-for-healthy-page-object-model-classes-e5071fccaf7f">Tips for Healthy Page Object Model Classes</a> was originally published in <a href="https://medium.com/test-automation-university">Test Automation University</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>