Skip to content

Commit

Permalink
Added browser version as a new CLI argument for local browsers (cherr…
Browse files Browse the repository at this point in the history
…y picked commit and fixed conflicts)
  • Loading branch information
akkuldn authored and rohandudam committed Oct 21, 2024
1 parent f3a0a74 commit 07022e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
10 changes: 8 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,17 @@ def pytest_generate_tests(metafunc):
if metafunc.config.getoption("--browser") == ["all"]:
metafunc.config.option.browser = browser_os_name_conf.local_browsers
metafunc.parametrize("browser", metafunc.config.option.browser)
elif metafunc.config.getoption("--browser") == []:
elif metafunc.config.getoption("--browser") == [] and metafunc.config.getoption("--ver") == []:
metafunc.parametrize("browser",browser_os_name_conf.default_browser)
else:
elif metafunc.config.getoption("--browser") != [] and metafunc.config.getoption("--ver") == []:
config_list_local = [(metafunc.config.getoption("--browser")[0])]
metafunc.parametrize("browser", config_list_local)
elif metafunc.config.getoption("--browser") == [] and metafunc.config.getoption("--ver") != []:
config_list_local = [(browser_os_name_conf.default_browser[0], metafunc.config.getoption("--ver")[0])]
metafunc.parametrize("browser, browser_version", config_list_local)
else:
config_list_local = [(metafunc.config.getoption("--browser")[0], metafunc.config.getoption("--ver")[0])]
metafunc.parametrize("browser, browser_version", config_list_local)

except Exception as e: # pylint: disable=broad-exception-caught
print(f"Exception when trying to run test:{__file__}")
Expand Down
18 changes: 10 additions & 8 deletions core_helpers/drivers/driverfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_web_driver(self, remote_flag, os_name, os_version, browser,
remote_build_name, testname)

elif remote_flag.lower() == 'n':
web_driver = self.get_local_driver(browser)
web_driver = self.get_local_driver(browser, browser_version)

return web_driver,session_url

Expand Down Expand Up @@ -60,21 +60,23 @@ def select_remote_platform(self, remote_flag, os_name, os_version, browser,

return web_driver,session_url

def get_local_driver(self, browser):
def get_local_driver(self, browser, browser_version):
"""Run the test on local system."""
local_driver = None
if browser_version == []:
browser_version = None
if browser.lower() == "ff" or browser.lower() == 'firefox':
local_driver = self.firefox_local()
local_driver = self.firefox_local(browser_version)
elif browser.lower() == "ie":
local_driver = self.explorer_local()
local_driver = self.explorer_local(browser_version)
elif browser.lower() == "chrome":
local_driver = self.chrome_local()
local_driver = self.chrome_local(browser_version)
elif browser.lower() == "opera":
local_driver = self.opera_local()
elif browser.lower() == "safari":
local_driver = self.safari_local()
elif browser.lower() == "headless-chrome":
local_driver = self.headless_chrome()
else:
raise AttributeError(f"Unsupported Browser - {browser!r}")
local_driver = self.headless_chrome(browser_version)

return local_driver

Expand Down
19 changes: 13 additions & 6 deletions core_helpers/drivers/local_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ class LocalOptions():
"""Class contains methods for getting webfrivers for various browsers."""

@staticmethod
def firefox_local():
def firefox_local(browser_version):
"""Get webdriver for firefox."""
local_driver = webdriver.Firefox()
options = webdriver.FirefoxOptions()
options.browser_version = browser_version
local_driver = webdriver.Firefox(options=options)

return local_driver

@staticmethod
def explorer_local():
def explorer_local(browser_version):
"""Get webdriver for internet explorer."""
options = webdriver.IeOptions()
options.browser_version = browser_version
local_driver = webdriver.Ie()

return local_driver

@staticmethod
def chrome_local():
def chrome_local(browser_version):
"""Get webdriver for chrome."""
local_driver = webdriver.Chrome()
options = webdriver.ChromeOptions()
options.browser_version = browser_version
local_driver = webdriver.Chrome(options=options)

return local_driver

Expand All @@ -37,10 +43,11 @@ def safari_local():
return local_driver

@staticmethod
def headless_chrome():
def headless_chrome(browser_version):
"""Set up headless chrome driver options and get webdriver for headless chrome."""
options = Options()
options.headless = True
options.browser_version = browser_version
options.add_argument("--window-size=1920,1080")
options.add_argument("--disable-extensions")
options.add_argument("--proxy-server='direct://'")
Expand Down

0 comments on commit 07022e5

Please sign in to comment.