i'm new to both python and selenium testing and i've encountered a problem that probably has a standard solution but i'm unable to find it.
Let's say that the project that i'm working on is supporting Google Chrome and Firefox. Writing separate tests for every supported browser seems redundant, so i've been trying to write generic test methods that will be executed separately using different webdrivers.
My current approach goes as follows
from selenium import webdriver
def construct_chrome_webdriver () :
driver = webdriver.Chrome()
driver.implicitly_wait(10)
return driver
def construct_firefox_webdriver () :
driver = webdriver.Firefox()
driver.implicitly_wait(10)
return driver
def actual_test_method_implementation (construct_webdriver) :
webdriver = construct_webdriver()
webdriver.get('http://localhost:3333')
# do some testing
def test_method_that_is_executed_by_pytest () :
actual_test_method_implementation(construct_chrome_webdriver)
actual_test_method_implementation(construct_firefox_webdriver)
And the tests are executed using command pytest filename.py
This approach requires a lot of boilerplate - two methods for each test. Is there a better way of achieving this?