test_fixtures_params.py

 from selenium import webdriver

from webdriver_manager.chrome import ChromeDriverManager
import pytest
from webdriver_manager.firefox import GeckoDriverManager


@pytest.fixture(params=["chrome","firefox"],scope='class')
def init_driver(request):
if request.param== "chrome":
web_driver=webdriver.Chrome(ChromeDriverManager().install())

if request.param== "firefox":
web_driver=webdriver.Firefox(executable_path=GeckoDriverManager().install())

request.cls.driver = web_driver

yield
print("----------------Tear Down--------------------")
web_driver.close()

@pytest.mark.usefixtures("init_driver")
class BaseTest:
pass

class Test_Google(BaseTest):
def test_google_title(self):
self.driver.get("http://www.google.com")
assert self.driver.title=="Google"

#pytest PyTestSession\test_fixtures_params.py -v -s --html=test_params.html

#For parallel execution
#pytest PyTestSession\test_fixtures_params.py -v -s -n 2 --html=_new_test_params.html

Comments

Popular posts from this blog

test_google_fixtures.py

PyTest Basics