Activity: Implementing the POM on a Multi-Page Application

Before You Begin

  1. Open Chrome. Go to https://trainingbypackt.github.io/Beginning-Selenium/lesson_6/activity_6_B-1.html and open the DevTools console.
  2. Use IntelliJ IDEA to create a Selenium script.

Scenario

The Gigantic Store provides the layout for a wholesale store. It includes a menu, which contains different options. Clicking on any of the options will redirect the user to a different web page.

In this activity, we will create a Page Object for the home page, and for any other page of the application. Finally, we will create an automation script that makes use of the Page Objects.

Aim

To implement an automation script with the Page Object Model on a multi-page web application.

Steps for Completion

  1. Create a Page Object for the https://trainingbypackt.github.io/Beginning-Selenium/lesson_6/activity_6_B-1.html file (which is considered the home page of the Gigantic Store application):
    1. Create a new Java file by using your IDE of choice.
    2. Define a package for our Object Repository and include it at the top of every Page Object file that you create.
    3. Include all of the libraries required, such as WebDriver, ChromeDriver, and WebElement.
    4. Since we are creating a Page Object for the Home page, it would be a good practice to name our classHomePage.
    5. Set variables and methods to handle the driver. Use the open and close functions.
    6. Write a constructor to the HomePage class.
    7. Write an operation to click on any of the options of the menu.
    1. Create an operation that uses the clickOption from any other page of the application. For this activity, we will choose the https://trainingbypackt.github.io/Beginning-Selenium/lesson_6/activity_6_B-1/deals.html page.
  1. Create a Page Object for the page that was chosen in step 1, as follows:
    1. Create a new Java file by using your IDE of choice.
    2. Include this Page Object in the same Object Repository that includes the HomePage class.
    3. Include all of the required libraries, such as WebDriver, ChromeDriver, and WebElement.
    4.  Since we are creating a Page Object for the Deals page, it would be good practice to name our class DealsPage.
    5. Set variables and methods to handle the driver.
    6. Set the variables of the required web elements. The Deals page includes an element with the ID quote, with specific text.
    7. Write a constructor to the DealsPage class that verifies that the Deals page has been loaded and initializes the quote element.
    8. Write an operation to read the value of the quote element.
  2. Create an automation script for the HomePage class. The test should include clicking on the Deals option in the menu and verifying that the Deals page loads:
    1. Define a package for the test.
    2.  Import the Object Repository of the Page Objects, and all other required libraries, such as DealsPage, HomePage, WebDriver, and ChromeDriver.
    3. Since we are creating a script for the Age Calculator application, it would be good practice to name our class HomeScript.
    4. Create a method where the script's code can be placed. Name it checkHomeAndDealsPage.
    5. To use the Page Object, we must create an instance of the HomePage class, and then start the driver.
    6. Start the test by invoking the clickDeals method of the HomePage class. This method returns a DealsPage class object.
    7. Verify the test.
    8. Stop the test.
  3. Compile and run the test.

To refer to the detailed steps, go to the Solutions section at the end of this book on Page no. 172.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.190.101