0:00 - Introduction and session overview.
0:33 - Explanation of what the Page Object Model (POM) is.
1:43 - Benefits of using the Page Object Model, separating locators and actions.
3:25 - Creating folders for pages and tests in the project.
4:46 - Creating a Python file for the LoginTest.
5:32 - Creating a Python file for the LoginPage class.
9:10 - Creating a constructor in the LoginPage class to accept the driver instance.
12:08 - Defining locators for username, password, and login button.
14:20 - Defining methods for actions like opening the page, entering username and password, and clicking the login button.
24:38 - Importing the LoginPage class in the test script.
25:10 - Creating an instance of the LoginPage class and performing actions using the defined methods
Page Object Model
What is POM - Page Object Model
How to implement POM in Selenium Python Project
Demo and Hands-On
Step 1 - In the project folder create 2 folders pages and tests
Step 2 - In the tests folder create a python file login_test.py and create a simple login test
Step 3 - In the pages folder create a python file login_page.py and create a class LoginPage
Step 4 - In the class LoginPage create a constructor function that takes driver parameter
Step 5 - In the constructor function add locators for all elements of login page as needed for the test
Step 6 - Create functions for login actions
Step 7 - In the login_test.py import the class LoginPage
Step 8 - Create an object for LoginPage class to access the functions of the class
Step 9 - Replace the test scripts with LoginPage function calls
Step 10 - Run and test
Ref: Python for Beginners - • Python for Complete Beginners
login_test.py
import pytest
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from POMDemo.tests.pages.login_page import LoginPage
@pytest.fixture()
def driver():
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
driver.implicitly_wait(10)
yield driver
driver.close()
driver.quit()
def test_login(driver):
login_page = LoginPage(driver)
login_page.open_page("https://trytestingthis.netlify.app/")
time.sleep(1)
login_page.enter_username("test")
time.sleep(1)
login_page.enter_password("test")
time.sleep(1)
login_page.click_login()
time.sleep(1)
login_page.py
from selenium.webdriver.common.by import By
class LoginPage:
def __init__(self, driver):
self.driver = driver
self.username_textbox = (By.ID, "uname")
self.password_textbox = (By.ID, "pwd")
self.login_button = (By.XPATH, "//input[@value='Login']")
def open_page(self, url):
self.driver.get(url)
def enter_username(self, username):
self.driver.find_element(*self.username_textbox).send_keys(username)
def enter_password(self, password):
self.driver.find_element(*self.password_textbox).send_keys(password)
def click_login(self):
self.driver.find_element(* self.login_button).click()
▬▬▬▬▬▬▬
Every Like & Subscription gives me great motivation to keep working for you
You can support my mission for education by sharing this knowledge and helping as many people as you can
If my work has helped you, consider helping any animal near you, in any way you can
Never Stop Learning
Raghav Pal
▬▬▬▬ USEFUL LINKS ▬▬▬▬
All Free Tutorials - https://AutomationStepByStep.com/
Ask Raghav - https://bit.ly/2CoJGWf
Shorts Eng - https://bit.ly/3H9bifV
Shorts Hindi - https://bit.ly/3XY7XqN
GitHub Repositories - https://github.com/Raghav-Pal
Udemy - https://automationstepbystep.com/udem...
Stories - https://automationstepbystep.com/stor...
---
In questa pagina del sito puoi guardare il video online 6 | Page Object Model | Selenium Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Automation Step by Step 01 August 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 13,818 volte e gli è piaciuto 237 spettatori. Buona visione!