Writing tasks to customize your page objects

The Automation project contains a set of page objects. Page objects are an abstraction of the web pages, and include relevant tasks, identifiers of elements that are used in the tasks, and page validation identifiers. Each task is a Java method that interacts with a specific element on the storefront. Multiple tasks are combined to form your store test cases.

Procedure

  1. In the development environment, browse to the directory in your test bucket project that contains the task library.
    For example, the src/com/ibm/commerce/ga/aurora/page directory contains all the page objects for the Aurora starter store.
  2. Open a page object class. The task libraries are named regarding the storefront page or the common page fragment that they test.
    For example, the HeaderSection.java file contains tasks that test the links in the header, such as the Advanced Search link and the Sign-In link.
    The top of the page objects contains all the Identifiers that are used in the tasks. One or more of these Identifiers are annotated with @PageValidator a. The framework uses this annotation to test for the existence of these elements before it declares the page to be fully loaded. Most of the store pages are composed of subsections such as header and footer. These subsections are imported in the constructor, allowing for calls such as the following:
    frontPage.getHeader().signIn();
  3. Type the new code into the task library.
    For example, the following is a task that clicks the sign-in link in the header:
       /**
       * Go to sign in page by clicking on the sign in link.
       * 
       * @return new sign in page object
       */
       public SignInPage signIn(){
         getFactory().createQuery(signInLink).withinAjaxTimeout().findExactlyOne().clickWithRetry();
          return getFactory().createPage().build(SignInPage.class);
       }
    Each task returns another page object, which is validated and instantiated by the framework. To build and return a page, the PageFactory framework is called, with the createdPage().build(<Page Class>) method to build and confirm that the page is fully loaded before giving back control to the test.
    Note: The values for signInLink and all other constants are defined at the top of the Page Object class.
  4. Save the file.