6 | Page Object Model | Selenium Python

preview_player
Показать описание
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 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 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

import pytest
import time
from selenium import webdriver

def driver():
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
yield driver

def test_login(driver):
login_page = LoginPage(driver)

class LoginPage:

def __init__(self, driver):

def open_page(self, url):

def enter_username(self, username):

def enter_password(self, password):

def click_login(self):

▬▬▬▬▬▬▬

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 ▬▬▬▬

---
Рекомендации по теме
Комментарии
Автор

Done and dusted. Have gone through all 6 videos with hands on Raghav. I am very grateful to you for sharing these videos. I am new to Python. Watched your python videos first and then started with this. Completed successfully. 🙏

shwethabolar
Автор

Thank you so much, Raghav. I’m so thankful for these free videos you shared with us. I have tried to watch other tutorials, but your videos by far is the easiest to follow and understand. You’re assuring words helped too. I finished these 6 videos and I felt really great. I would be happy to learn more about automation with other tools from your guidance through YouTube and your site. Thank you again! I hope you’re having the best time of your life for being very generous with us with your knowledge! Please keep sharing! Thank you, Raghav!

darkmode
Автор

Thank you Raghav ji for the wonderful set for python automation.

MySmallbigworld
Автор

Hi Raghav, that is great . Another wrapper method could be created where you can call the 3 existing independent methods eg:
Login (user, pass):
enter_username(user)
enter_password(pass)
click_login() . So, from your tests you can call a single: login wrapper method instead of calling 3 independent methods .

elmariscal
Автор

I separated the driver logic into a separate class - I wasn't convinced of the merits of the driver logic being included as part of the test logic. Otherwise, really great video!

MeatyWhack
Автор

Being a complete beginner this course was really useful.Thanks @raghavpal

khirankumar
Автор

Very good video! I understood everything, tysm

yuzara
Автор

Hi Raghav bro, ur videos are very nice and easy to learn quickly. But my one suggestion you are posted selenium with python 2023 course only six videos, Please make sure you post the further videos also and we get more information.
Thank you ❤

Teja_Rao
Автор

Hii Raghav, is this course good for begineers in automation. I have knowledge of python but no knowledge of testing/automation. Will this course be good to start with?

Namelessaccount-xx
Автор

@raghavpal Hi there I understand the POM model here but one question can we use this when working on behave with python like I want to keep locator separate but not in step definition. Can you help me ple

ashishajwani
Автор

Hi Raghav, great videos. They are really easy to follow and implement. Do you have any courses or material on Pytest-BDD? I'm trying to understand it and how to implement it with Page Object Model. Any help would be great thank you.

emmanuelalder
Автор

Hi Raghav,
I'm getting error for,
self.password_textbox = (By.ID, "password")


but if I change into below it works fine.
self.password_textbox = "password"
self.driver.find_element(By.ID,

can you please help me understand why. Thanks

saumyaari
Автор

Hi Raghav.. Your videos have helped me a lot to learn how to automate, thank you very much for sharing them.
I have a question. Please, could you help me?.. What method can I use so that in the Login window, the username and password are not inserted until the page is completely loaded?

yazz-m
Автор

Hi Raghav, playwright or webdriverio which tool is suitable for angular and react frameworks? Please clarify

parthipanp-idwo
Автор

Hi Raghav, First of thanks so much you are my silent mentor in automation.

I am 7 years of exp in Manual and API Automation. Web automation i did very less.

i did it 2 years back in last company for 6 months(Selenium), I forgot a lot now my new company wants to do it in Selenium So the company demand it to me to complete one project -(Atelaset minimum I have to Write maximum 50 test cases till the September first week)..

I dnt know how can i start a new project ?
For me its completely new how your videos can give me some help and how can I start Project automation? It's so urgent ..there are many channels on Youtube but i was always comforted with your teaching skills.

So can you guide me how can start my project automation step by step (Selenium+Java)with the learning in parallel i did half course in udemy but it was so complex and explained so lengthy so could not complete as there are lots of things..
Till now i did installation etc now i am stuck how a project can be started?

Hope you will leave me with some satisfaction and some guidelines as well .Thanks in Advance.

KavitaRawatWorld
Автор

Hi Raghav, in this video while you were importing from pages you got an error so you moved the pages in test. but can you please tell me the actual solution so that the purpose POM can be successfully delivered.

TanzeelRabbani-sk
Автор

Hi @Raghav, Thanks for these videos. I just have a question on assertions. Is it best to use the try and except? Also is it best practice to stop the test as soon as we hit an error, or should we let the test continue running to the end? Thanks

emmanuelalder
Автор

Hi Raghav…I know java selenium using cucumber …which is better in market today??…selenium with java or the python???
Is it so necessary to learn python again or java is sufficient?

rahulraj-jebo
Автор

Hi Raghav, I ran into the same problem as you when I tried to run the code. I had to use the splat operator. I've never had to do this before, can you explain what this is and why we have to use it? Thanks

emmanuelalder
Автор

Hey Raghav, Thank you for the great session on Selenium Python.
One issue that I'm facing here is whenever I'm adding locators for elements under constructor function, it is giving me error: InvalidArgumentException: Message: invalid argument: 'using' must be a string.
However, if I'm defining the locators within the action functions, it is running fine. Still figuring out the reason, but if you could help me with the reason for this, it will be helpful. Also, is this a good practice to define the locators in the action function itself?

TravelltheGlobe