I am currently learning about Selenium with Python binding. I am currently trying to design a test where I could do run a test with different browsers by passing the browser name as a parameter through the terminal.
The command that I use to run is:
(venv) cp@cp fetchwebsite % pytest -s -v -q TestCases/test_login.py --browser="chrome"
it keeps returning this error for me
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --browser=chrome
inifile: None
rootdir: /Users/cp/PycharmProjects/fetchwebsite
Below is my conftest.py
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
@pytest.fixture()
def setup(browser):
options = Options()
options.add_experimental_option('detach', True)
if browser == "chrome":
driver = webdriver.Chrome(options=options)
elif browser == "firefox":
driver = webdriver.Firefox(options=options)
return driver
def pytest_addoption(parser):
parser.addoption("--browser", default="chrome", action="store")
@pytest.fixture()
def browser(request):
return request.config.getoption("--browser")
this is my test_login.py
import pytest
from PageObjects.login_page import LoginPage
from PageObjects.myStuff_page import MyStuffPage
from PageObjects.pin_page import PINPage
from selenium import webdriver
from Utilities.property_reader import ReadConfig
from Utilities.log_generator import LogGenerator
from Configurations.conftest import setup
class Test_LoginByActivationCode:
# getting all the configs needed for this test
loginURL = ReadConfig.getURL()
validPIN = ReadConfig.getValidPIN()
validCode = ReadConfig.getValidCode()
log = LogGenerator.logGenerator()
def test_pageTitle(self, setup):
self.driver = setup
self.driver.get(self.loginURL)
self.driver.implicitly_wait(5)
self.log.info("LOGIN TEST 1: Login By Valid Activation Code and PIN")
self.log.info(":: Verifying Page Title")
page_title = self.driver.title
if page_title == "Fetch Account":
self.log.info(":: > Page Title is verified")
assert True
self.driver.close()
else:
self.log.error(":: > Page Title is NOT verified")
assert False
self.driver.close()
def test_loginCorrectActivationCodeCorrectPIN(self, setup):
self.driver = setup
self.driver.get(self.loginURL)
self.driver.implicitly_wait(5)
lp = LoginPage(self.driver)
pp = PINPage(self.driver)
msp = MyStuffPage(self.driver)
lp.closeCookieBanner()
self.log.info(":: Finding Cookie Banner and Closing it")
lp.setValidActivationCode(self.validCode)
self.log.info(":: Entering a valid activation code: " + self.validCode)
lp.clickSignInButton()
self.log.info(":: Clicking on Sign In Button")
self.driver.implicitly_wait(5)
pp.setValidPIN(self.validPIN)
self.log.info(":: Entering a valid PIN: " + self.validPIN)
self.driver.implicitly_wait(5)
# locate My Stuff heading and print it
self.log.info(":: Finding and Verifying My Stuff Page Heading")
heading = msp.findMyStuffPageHeading()
if heading == "My Stuff":
self.log.info(":: > My Stuff Heading is verified")
self.log.info(":: > Login is Successful")
assert True
self.driver.close()
else:
self.log.error(":: > My Stuff Heading is NOT verified: " + heading)
self.log.error(":: > Login is NOT Successful")
assert False
self.driver.close()
Directories structure inside my Project Project directories
I tried to search for answers for two weeks now but I am stucked. If anyone could help it would be great.
My goal is when I pass 'chrome' it would launch the chrome browser and when I pass 'firefox' it would launch the firefox browser.
Thank you