Under the pages package we need to create class files for respective app screens and define variables and assign locator values of each MobileElement to that variables.
Now we need to create methods to perform actions on the respective MobileElements.
In this ContactUsFormPage class we have defined all the locator values of contact form and created all the methods which perform actions such as clicking on the button , entering the text and verifying whether text is displayed or not.
ContactUsFormPage.py
from AppiumFrameWork.base.BasePage import BasePage import AppiumFrameWork.utilities.CustomLogger as cl class ContactForm(BasePage): def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators values in Contact us form _contactFromButton = "com.skill2lead.appiumdemo:id/ContactUs" # id _pagetitle = "Contact Us form" # text _enterName = "Enter Name" # text _enterEmail = "Enter Email" # text _enterAddress = "Enter Address" # text _enterMobileNumber = "4" # index number _submitButton = "SUBMIT" # text def clickContactFormButton(self): self.clickElement(self._contactFromButton, "id") cl.allureLogs("Clicked on Contact us From Button") def verifyContactPage(self): element = self.isDisplayed(self._pagetitle, "text") assert element == True cl.allureLogs("Contact Us Form page opened") def enterName(self): self.sendText("Code2Lead", self._enterName, "text") cl.allureLogs("Entered Name") def enterEmail(self): self.sendText("abc@gmail.com", self._enterEmail, "text") cl.allureLogs("Entered Email") def enterAddress(self): self.sendText("India", self._enterAddress, "text") cl.allureLogs("Entered Address") def enterMNumber(self): self.sendText("987654210", self._enterMobileNumber, "index") cl.allureLogs("Entered Mobile Number") def clickSubmitButton(self): self.clickElement(self._submitButton, "text") cl.allureLogs("Clicked on Submit button")
In this LoginPage class we have defined all the locator values of LoginPage and created all the methods which perform actions such as clicking on the button , entering the text and verifying whether text is displayed or not.
LoginPage.py
from AppiumFrameWork.base.BasePage import BasePage import AppiumFrameWork.utilities.CustomLogger as cl class LoginPageTest(BasePage): def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators values in Contact us form _loginbutton = "com.skill2lead.appiumdemo:id/Login" # id _enterEmail = "3" # index _enterPassword = "Enter Password" # text _clickloginButton = "com.skill2lead.appiumdemo:id/Btn3" # id _wrongCredentials = "Wrong Credentials" # text _pageTitle = "Enter Admin" # text _enterText = "com.skill2lead.appiumdemo:id/Edt_admin" # id _submitButton = "SUBMIT" # text def clickLoginBotton(self): self.clickElement(self._loginbutton, "id") cl.allureLogs("Click on Login Button") def enterEmail(self): self.sendText("admin@gmail.com", self._enterEmail, "index") cl.allureLogs("Entered email id") def enterPassword(self): self.sendText("admin123", self._enterPassword, "text") cl.allureLogs("Entered Password") def enterPassword2(self): self.sendText("admin12344", self._enterPassword, "text") cl.allureLogs("Entered Password") def clickOnLoginB(self): self.clickElement(self._clickloginButton, "id") cl.allureLogs("Clicked on Login Button in Login Screen") def verifyAdminScreen(self): adminScreen = self.isDisplayed(self._pageTitle, "text") assert adminScreen == True cl.allureLogs("Opened Admin Screen") def enterText(self): self.sendText("Code2Lead", self._enterText, "id") cl.allureLogs("Entered Text") def clickOnSubmit(self): self.clickElement(self._submitButton, "text") cl.allureLogs("Clicked on Submit Button")