Skip to content

Commit

Permalink
Merge pull request #482 from qxf2/add-browser-version-option-for-loca…
Browse files Browse the repository at this point in the history
…l-execution-and-add-edge-support

Added browser version option for local execution and Edge browser support
  • Loading branch information
rohandudam authored Oct 23, 2024
2 parents 36f89f4 + 2ac1fef commit 2193371
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ c) If your are using firefox 47 and above, you need to set up Geckodriver. Refer

d) On Ubuntu, you may run into an issue installing the cryptography module. You need to `sudo apt-get install libssl-dev` and then run `sudo pip install -r requirements.txt`

e) The Edge in Windows can not be downloaded automatically to the local cache (~/.cache/selenium) by Selenium Manager as it requires administrative access. When Edge is attempted to installed with Selenium Manager it will through ``edge can only be installed in Windows with administrator permissions.``

-----------
Continuous Integration and Support
-----------
Expand Down
14 changes: 11 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def test_obj(base_url, browser, browser_version, os_version, os_name, remote_fla
elif os.getenv('REMOTE_BROWSER_PLATFORM') == 'BS' and remote_flag.lower() == 'y':
test_obj.execute_javascript("""browserstack_executor: {"action": "setSessionStatus",
"arguments": {"status":"failed", "reason": "Exception occured"}}""")
if browser == "edge":
print(f"Selenium Manager requires administrator permissions to install Microsoft {browser} in Windows automatically ")

@pytest.fixture
def test_mobile_obj(mobile_os_name, mobile_os_version, device_name, app_package, app_activity, # pylint: disable=redefined-outer-name too-many-arguments too-many-locals
Expand Down Expand Up @@ -661,11 +663,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 All @@ -678,7 +686,7 @@ def pytest_addoption(parser):
dest="browser",
action="append",
default=[],
help="Browser. Valid options are firefox, ie and chrome")
help="Browser. Valid options are firefox, Edge and chrome")
parser.addoption("--app_url",
dest="url",
default=base_url_conf.ui_base_url,
Expand Down
20 changes: 11 additions & 9 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()
elif browser.lower() == "ie":
local_driver = self.explorer_local()
local_driver = self.firefox_local(browser_version)
elif browser.lower() == "edge":
local_driver = self.edge_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
23 changes: 15 additions & 8 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():
"""Get webdriver for internet explorer."""
local_driver = webdriver.Ie()
def edge_local(browser_version):
"""Get webdriver for Edge."""
options = webdriver.EdgeOptions()
options.browser_version = browser_version
local_driver = webdriver.Edge(options=options)

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
11 changes: 5 additions & 6 deletions core_helpers/web_app_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Page class that all page models can inherit from
There are useful wrappers for common Selenium operations
"""

import inspect
from selenium.webdriver.common.by import By
import os,inspect
from core_helpers.drivers.driverfactory import DriverFactory
from .selenium_action_objects import Selenium_Action_Objects
from .remote_objects import Remote_Objects
Expand Down Expand Up @@ -248,7 +247,7 @@ def switch_frame(self,name=None,index=None,wait_time=2):
def get_element_attribute_value(self,element,attribute_name):
"Return the elements attribute value if present"
attribute_value = None
if (hasattr(element,attribute_name)):
if hasattr(element,attribute_name):
attribute_value = element.get_attribute(attribute_name)

return attribute_value
Expand Down Expand Up @@ -278,14 +277,14 @@ def accessibility_inject_axe(self):
try:
return self.axe_util.inject()
except Exception as e:
self.write(str(e),'critical')
self.write(str(e),'critical')

def accessibility_run_axe(self):
"Run Axe into the Page"
try:
return self.axe_util.run()
except Exception as e:
self.write(str(e),'critical')
self.write(str(e),'critical')

def snapshot_assert_match(self, value, snapshot_name):
"Asserts the current value of the snapshot with the given snapshot_name"
Expand All @@ -294,7 +293,7 @@ def snapshot_assert_match(self, value, snapshot_name):
self.snapshot_util.assert_match(value, snapshot_name)
result_flag = True
except Exception as e:
self.write(str(e),'critical')
self.write(str(e),'critical')

return result_flag

Expand Down
12 changes: 6 additions & 6 deletions integrations/cross_browsers/remote_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Set the desired option for running the test on a remote platform.
"""
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.ie.options import Options as IeOptions
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.safari.options import Options as SafariOptions
from appium.options.android import UiAutomator2Options
Expand All @@ -20,9 +20,9 @@ def firefox(browser_version):
return options

@staticmethod
def explorer(browser_version):
"""Set web browser as Explorer."""
options = IeOptions()
def edge(browser_version):
"""Set web browser as Edge."""
options = EdgeOptions()
options.browser_version = browser_version

return options
Expand All @@ -47,8 +47,8 @@ def get_browser(self, browser, browser_version):
"""Select the browser."""
if browser.lower() == 'ff' or browser.lower() == 'firefox':
desired_capabilities = self.firefox(browser_version)
elif browser.lower() == 'ie':
desired_capabilities = self.explorer(browser_version)
elif browser.lower() == 'edge':
desired_capabilities = self.edge(browser_version)
elif browser.lower() == 'chrome':
desired_capabilities = self.chrome(browser_version)
elif browser.lower() == 'safari':
Expand Down

0 comments on commit 2193371

Please sign in to comment.