Pages

Page class files

In this package we will create multiple classes based on screens or webpages. Each .py class consists of WebElement locator values of each screen.In this way it's very easy to modify whenever they update or change the locatore value.

Here we have extended BaseClass which is present in BasePage to the pages classes. As all the customized methods are present in this class.


Initialization method

Initialization method will be executed at the beginning of the class.So that we have called this method to initialize the driver object. This initialization method ( __init__ ) is used to get the driver object which is passed from the Test file.

We have called super().__init__ inside the initialization method of ContctFormPage and EnterTextPage page files because as __init__ method is present in BaseClass as well and we have extended the BaseClass to the page class.




Variable declaration for Locators

We need to create private variables by adding double underscores( __ ) before the variable name.

Private Variable _contactFromPage = "Form"

Now we need to create a method for this variable as this is a private variable it will not access outside the class.


def clickContactForm(self):
   self.clickOnElement(self._contactFromPage, "link")
   cl.allureLogs("Clicked on Contact Form")


For the above method we have passed the locator value to the method ( clickOnElement) which is present in the BaseClass of BasePage file and we have called the allure report method as well to store the logs in allure reports.


We have written all the locator values which belong to the contact form here.

Contact US Form

ContctFormPage.py

from SeleniumFrameWork.base.BasePage import BaseClass
import SeleniumFrameWork.utilities.CustomLogger as cl

class ContactForm(BaseClass):

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    # Locators  values in Contact form page

    _contactFromPage = "Form"  # link
    _formPage = "reused_form"  # id
    _enterName = "name"  # id
    _enterEmail = "email"  # id
    _enterMessage = "message"  # id
    _getCaptcha = "captcha_image"  # id
    _enterCaptha = "captcha"  # id
    _postButton = "btnContactUs"  # id

    def clickContactForm(self):
        self.clickOnElement(self._contactFromPage, "link")
        cl.allureLogs("Clicked on Contact Form")

    def verifyFormPage(self):
        element = self.isElementDisplayed(self._formPage, "id")
        assert element == True
        cl.allureLogs("Verified Contact Form")

    def enterName(self):
        self.sendText("Code2Lead", self._enterName, "id")
        cl.allureLogs("Entered Name")

    def enterEmail(self):
        self.sendText("abc@gmail.com", self._enterEmail, "id")
        cl.allureLogs("Entered Email")

    def enterMessage(self):
        self.sendText("This is a Code2Lead", self._enterMessage, "id")
        cl.allureLogs("Entered Message")

    def getCaptha(self):
        cap = self.getText(self._getCaptcha, "id")
        cl.allureLogs("Got the captcha data")
        return cap

    def enterCaptha(self):
        self.sendText(self.getCaptha(), self._enterCaptha, "id")
        cl.allureLogs("Entered captcha")

    def clickOnPostButton(self):
        self.scrollTo(self._postButton, "id")
        self.clickOnElement(self._postButton, "id")
        cl.allureLogs("Clicked on the post button")




We have written all the locator values which belong to the enter text edit box here.

Enter text

EnterTextPage.py

from SeleniumFrameWork.base.BasePage import BaseClass
import SeleniumFrameWork.utilities.CustomLogger as cl


class EnterText(BaseClass):

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    # Locators values in Contact form
    _locatorsPage="Locators" # link
    _enterTextEditBox = "user_input"  # id
    _submitButton = "submitbutton"  # id

    def clickOnLocatorsPage(self):
        self.clickOnElement(self._locatorsPage,"link")

    def enterText(self):
        self.sendText("Code2Lead",self._enterTextEditBox,"id")
        cl.allureLogs("Entered Text in Edit Box")

    def clickOnSubmitButton(self):
        self.clickOnElement(self._submitButton,"id")