Core Functions
of A Test Framework
Test
Framework
Create & Execute Generate Test Generate Read & Write
Test Scripts Reports Logs Test Data
Rex Jones II
Pytest
Presentation
Rex Jones II
Rex Jones II
Pytest
Tutorial Playlist
1. Intro To Pytest Framework 7. Pytest Fixture With Selenium
2. How To Install Pytest 8. Parameterize Test In Pytest
3. Run 1st Test In Pytest 9. Skip Test / Stop Test In Pytest
4. Assertions In Pytest 10. Page Object Model In Pytest
5. Multiple Tests & Subset Of A Test 11. Generate Reports In Pytest
6. Group Tests Using Markers 12. Cross Browser Test On LambdaTest
Rex Jones II
Pytest
Agenda
• What Is Pytest
• How To Install Python
• How To Install PyCharm
• How To Install Pytest
Rex Jones II
Installations
1) Python for Programming
2) PyCharm IDE
3) Pytest Framework
Rex Jones II
How To
Install Python
Rex Jones II
Install
Python
Rex Jones II
Install
Python
Rex Jones II
Install
Python
Rex Jones II
How To Install
PyCharm
Rex Jones II
Install
PyCharm
Rex Jones II
Install
PyCharm
Rex Jones II
Install
PyCharm
Rex Jones II
How To
Install Pytest
Rex Jones II
1st Test Using
Pytest With Selenium
Rex Jones II
How To
Install Selenium
Rex Jones II
Naming
Conventions
1) Module Files
2) Functions
3) Pytest Framework
4) Selenium for Automation
Rex Jones II
Assertions In
Pytest
Rex Jones II
Pytest
Agenda
• Syntax of Assert Statement
• AssertionError Exception
• Difference Between Hard & Soft Asserts
Rex Jones II
Syntax of
Assert Statement
Rex Jones II
AssertionError
Exception
Rex Jones II
Hard Assert
vs
Soft Assert
Rex Jones II
Difference Between
Hard Asserts & Soft Asserts
▪ Hard Assert – stops execution after a failure and moves to the
next annotation
▪ Soft Assert – continues execution after a failure and moves to
the next statement line
Rex Jones II
Multiple Tests
& Subset of All Tests
Rex Jones II
DemoPytest
Project: PytestTutorials
Package 1 Package 2
test_file_one.py test_file_abc.py
test_1
test_7
test_2
test_8
test_3
test_file_two.py test_file_xyz.py
test_4
test_5 test_9
test_6
Rex Jones II
Run All Test Scripts
From Project
Rex Jones II
Run All Test Scripts
From Package
Rex Jones II
Run Subset
of All Test Scripts
Rex Jones II
Group Tests
Using Markers
Rex Jones II
Group Tests
Using Markers
Rex Jones II
Pytest
Agenda
• How To Use Marks To Run A Subset
• How To Register Custom Markers
• How To Mark The Whole Class Or Module
Rex Jones II
Pytest Fixture
With Selenium
Rex Jones II
Pytest
Agenda
• @pytest.fixture() decorator
• Understand The Power of yield
• How To Use the @pytest.mark.usefixtures()
Rex Jones II
setup_teardown()
setup code
yield
teardown code
test1 test2
Test 1 Code Test 2 Code
setup
yield to test code
teardown
Rex Jones II
Parameterize Test
In Pytest
Rex Jones II
Pytest
Agenda
• Parameterize Test Function With 1 Decorator
• Parameterize Test Function With 2 Decorators
• Parameterize Pytest Fixture
• Run On Multiple Browsers
Rex Jones II
Parameterize Test
With 1 Decorator
Rex Jones II
Parameterize Test
With 2 Decorators
Rex Jones II
Parameterize
Pytest Fixture
Rex Jones II
Run Test On
Multiple Browsers
Rex Jones II
Skipping & Stopping
A Test
Rex Jones II
Pytest
Agenda
• Skip & Fail Test Using A Decorator
• Skip & Fail Test Without Using A Decorator
• Skip With & Without A Condition
• Fail With & Without A Condition
Rex Jones II
Skipping
A Test
Rex Jones II
Failing & Stopping
A Test
Rex Jones II
Page Object
Model
Rex Jones II
Page Object
Model
Rex Jones II
Web
Pages
Page Objects Test
(Elements &
Interactions) Scripts
Elements & Interactions are stored
separate from Test Scripts
Rex Jones II
Page Object
Model
Web Pages Login Page Home Page
Page Objects LoginPage HomePage
(Variables & Methods) (Variables & Methods)
Test Scripts Test Script 1 Test Script 2 Test Script 3
Rex Jones II
Pytest
Agenda
• How To Create & Call A Base Page
• How To Create & Call Test Data File
• How To Store Locators (2 Different Ways)
• How To Create & Call Page Objects
• How To Create A Base Test & Test Files
• How To Execute Page Object Model On 3 Browsers Rex Jones II
Why Is The POM
Important
Rex Jones II
WebDriver
API’s
Rex Jones II
Create
Base Page
Rex Jones II
Create
Test Data
Rex Jones II
Store
Locators
Rex Jones II
Create
Page Objects
Rex Jones II
Create
Base Test
Rex Jones II
Create
Test Files
Rex Jones II
Generate Reports
In Pytest
Rex Jones II
Pytest
Agenda
• HTML Report
• Allure Report
Rex Jones II
HTML
Report
Rex Jones II
Allure
Report
Rex Jones II
Cross Browser
Testing On LambdaTest
Rex Jones II
Pytest
Agenda
• Set Up Online Selenium Grid On LambdaTest
• View The Automation Capabilities Generator
• Execute Test Scripts Using Online Selenium Grid
Rex Jones II
Set Up
Online Selenium Grid
Rex Jones II
View Automation
Capabilities Generator
Rex Jones II
Execute Test Using
Online Selenium Grid
Rex Jones II
Pytest
Tutorial Playlist
1. Intro To Pytest Framework 7. Pytest Fixture With Selenium
2. How To Install Pytest 8. Parameterize Test In Pytest
3. Run 1st Test In Pytest 9. Skip Test / Stop Test In Pytest
4. Assertions In Pytest 10. Page Object Model In Pytest
5. Multiple Tests & Subset Of A Test 11. Generate Reports In Pytest
6. Group Tests Using Markers 12. Cross Browser Test On LambdaTest
Rex Jones II
Yearning to learn more?
Follow us at
https://www.lambdatest.com/blog
https://community.lambdatest.com
Rex Jones II
Earn resume-worthy LambdaTest
Selenium certifications
https://www.lambdatest.com/certifications
Get Educated
Get Recognized
Rex Jones II