5 | Selenium Pytest Examples | Selenium Python

preview_player
Показать описание
0:00 - Intro
0:43 - Creating a new Python file for the Google search test
1:27 - Importing necessary packages for the test
2:11 - Creating a basic Google search test function
3:47 - Running the test using PyCharm's interface
4:45 - Running the test using the command line
5:45 - Introduction to Pytest fixtures and setup/teardown
6:08 - Creating a Pytest fixture named "driver" for setup and teardown
10:30 - Demonstrating how the fixture works in the test function
11:23 - Using the fixture for setup and teardown of WebDriver
13:10 - Introduction to parameterization with Pytest
13:35 - Creating a parameterized test for a login scenario
15:17 - Running the parameterized test with different sets of data
17:10 - Conclusion & explore more Pytest features

Create a Google Search test with Pytest
Use Pytest fixture for set up and tear down
Use Parameterization with Pytest
Demo & Examples

Step 1 - Create a new python file in project
Step 2 - Import pytest and selenium packages
Step 3 - Create a function and write code for Google Search Test

import pytest
import time
from selenium import webdriver

def test_google_search():
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
print(" Test Completed ")

Step 4 - Run the test from IDE - Rt click > Run pytest… OR from cmd pytest “filename”
Using Pytest Fixtures:
are reusable functions that can be used to set up and tear down test cases
Step 5 - Create a pytest fixture function to setup and teardown driver
Step 6 - Use the fixture in test case

import pytest
import time
from selenium import webdriver

def driver():
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
# Yield the WebDriver instance
yield driver
# Close the WebDriver instance

def test_google_search(driver):
print(" Test Completed ")

Step 7 - Run and check result
Step 8 - Try using parameterization with Pytest
Parametrization is a technique that can be used to run the same test with different values

def driver():
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
# Yield the WebDriver instance
yield driver
# Close the WebDriver instance

("test", "test"),
("user2", "pass2"),
("user3", "pass3"),
])

def test_login(driver, username, password):

Introduction to Selenium Pytest Examples
Test Automation with Selenium and Pytest
Writing Test Cases with Selenium and Pytest
▬▬▬▬▬▬▬

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


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

I really enjoy watching your tutorials. Each video explains everything from scratch. Just as you said. All the best for you for your work.

paweoleksiak-svmm
Автор

A great fan of your work Sir. Keep sharing and teaching.

MrXOXO-vjol
Автор

Raghav Bro, Thank you very much for these amazing classes. I've been following the Python 2023 series from the very first video, and I can't express how much I've learned already! Your content is incredibly well-explained and easy to understand, making it a joy to learn Python with your guidance.

I'm truly grateful for the effort you put into creating these educational videos. Looking forward to more fantastic content from you. Keep up the fantastic work! 🙌🐍

venkateshkrishnasamy
Автор

This was an informative session. Thank you for sharing your knowledge and experience.

flirtuall
Автор

What does "yield driver" do? And 'def driver()' is a start up for test_login? If so, it starts the driver then closes and quits the driver. If the driver closes in startup, then how can it be used in the test_login?

VAudioVideo
Автор

Happy to get the video, thanks a lot Sir

MdNajmulIslamNajim
Автор

Never stop learning. looking for listening to you tomorrow

ndemazizou
Автор

find element showing waring and auto suggestion not working. Am I missing something ?

harshitharry
Автор

I got error using brave browser how to use it, pls help

vijayrajkumar-ojlc