def setUp(self): WebDriverFactory().setup_edgedriver() from msedge.selenium_tools import Edge, EdgeOptions options = EdgeOptions() options.use_chromium = True options.set_capability('platform', 'MAC' if OS_NAME == 'MAC' else 'WINDOWS') self.driver1 = Edge(options=options) self.driver2 = Edge(options=options) self.driver1.maximize_window() self.wait1 = WebDriverWait(self.driver1, 5) self.wait2 = WebDriverWait(self.driver2, 5)
def __edge_driver(browser_options): edge_options = EdgeOptions() edge_options.use_chromium = True if browser_options.headless: edge_options.add_argument('headless') if browser_options.browser_binary_location: edge_options.binary_location = browser_options.browser_binary_location if browser_options.operating_system: edge_options.set_capability('platform', 'LINUX') if browser_options.webdriver_location: return Edge(options=edge_options, executable_path=browser_options.webdriver_location) return EdgeDriver.WebDriver(options=edge_options)
def launch(self, desired_capabilities=None, options=None): from selenium.webdriver import DesiredCapabilities self._set_config() if self._automation_browser == CHROME and self._automation_local: self.setup_chromedriver() chrome_capabilities = DesiredCapabilities.CHROME.copy() if options is not None: chrome_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: chrome_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: chrome_capabilities.update(desired_capabilities) return webdriver.Chrome(desired_capabilities=chrome_capabilities) if self._automation_browser == GECKO and self._automation_local: self.setup_geckodriver() firefox_capabilities = DesiredCapabilities.FIREFOX.copy() if options is not None: firefox_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: firefox_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: firefox_capabilities.update(desired_capabilities) return webdriver.Firefox(desired_capabilities=firefox_capabilities, service_log_path=os.path.join(ROOT_DIR, LOG_DIR, f'{GECKODRIVER}{LOG}')) if self._automation_browser == EDGE: self.setup_edgedriver() from msedge.selenium_tools import Edge, EdgeOptions edge_capabilities = DesiredCapabilities.EDGE.copy() if options is not None: edge_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: edge_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: edge_capabilities.update(desired_capabilities) from msedge.selenium_tools import Edge, EdgeOptions edge_options = EdgeOptions() edge_options.use_chromium = True edge_options.set_capability('platform', 'MAC' if OS_NAME == 'MAC' else 'WINDOWS') edge_capabilities.update(edge_options.to_capabilities()) return Edge(desired_capabilities=edge_options.to_capabilities()) if self._automation_browser == IE: if OS_NAME == 'MAC': raise NotImplementedError('Cannot launch IE browser on Mac.') self.setup_iedriver() ie_capabilities = DesiredCapabilities.INTERNETEXPLORER.copy() if options is not None: ie_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: ie_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: ie_capabilities.update(desired_capabilities) from selenium.webdriver import IeOptions ie_options = IeOptions() ie_options.ignore_protected_mode_settings = True ie_options.ensure_clean_session = True ie_options.require_window_focus = True ie_options.ignore_zoom_level = True ie_capabilities.update(ie_options.to_capabilities()) return webdriver.Ie(desired_capabilities=ie_capabilities) if self._automation_browser == SAFARI: if OS_NAME == 'WIN': raise NotImplementedError('Cannot launch safari browser on Windows.') return webdriver.Safari(desired_capabilities=desired_capabilities) remote_capabilities = DesiredCapabilities.CHROME.copy() if self._automation_browser == CHROME \ else DesiredCapabilities.FIREFOX.copy() if options is not None: remote_capabilities.update(options.to_capabilities()) if desired_capabilities is not None: remote_capabilities.update(desired_capabilities) else: if desired_capabilities is not None: remote_capabilities.update(desired_capabilities) return webdriver.Remote(command_executor=self._automation_url, desired_capabilities=remote_capabilities)
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as ec from msedge.selenium_tools import Edge, EdgeOptions import time import datetime #options = Options() #cap = options.to_capabilities() #capabilities = options.to_capabilities() #driver = webdriver.Edge(capabilities=capabilities) options = EdgeOptions() options.set_capability("dom.webnotifications.enabled", 1) options.set_capability("permissions.default.microphone", 1) options.set_capability("permissions.default.camera", 1) options.use_chromium = True driver = Edge("C:\\msedgedriver.exe", options = options) #driver = webdriver.Edge("C:/MicrosoftWebDriver.exe") class Meet: def __init__(self, meet, ID, password): self.meet = meet self.ID = ID self.password = password self.email = self.ID + "@hyderabad.bits-pilani.ac.in" self.googleLogin() self.launchMeet()
def create_driver(browser_name): if browser_name not in GlobalUtils.BROWSER_NAMES: raise Exception("Unsupported browser string: '%s' Use: %s" % (browser_name, GlobalUtils.BROWSER_NAMES)) spinner_locator_file = os.path.join(os.getcwd(), GlobalUtils.PROJECT_SPINNER_LOCATORS_FILE) if not os.path.isfile(spinner_locator_file): shutil.copyfile(GlobalUtils.FRAMEWORK_SPINNER_LOCATORS_FILE, spinner_locator_file) if __REMOTE_SERVER_ADDRESS: if _REMOTE_SERVER_CAPTIONS: desired_capabilities = _REMOTE_SERVER_CAPTIONS else: desired_capabilities = __get_desired_capabilities(browser_name) print(__REMOTE_SERVER_ADDRESS) print(desired_capabilities) _driver = webdriver.Remote(__REMOTE_SERVER_ADDRESS, desired_capabilities) return _driver if browser_name == GlobalUtils.BROWSER_NAMES[Browsers.IE]: # Read browser language from config import winreg try: my_lang = get_config_value("browser_language") country_key = get_country_key(my_lang) try: key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\International", 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx(key, "AcceptLanguage", 0, winreg.REG_SZ, str(country_key + ";q=0.5")) winreg.CloseKey(key) except Exception as e: try: winreg.CloseKey(key) throw_error("\nCould not set language value: " + str(e)) except Exception as msg: print(str(msg)) except: pass # Turn protected mode on for all zones try: for i in range(1, 5): key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\" + str(i), 0, winreg.KEY_ALL_ACCESS) try: _protected_values[i - 1] = winreg.QueryValueEx(key, "2500")[0] except WindowsError as e: pass winreg.SetValueEx(key, "2500", 0, winreg.REG_DWORD, 0) winreg.CloseKey(key) except Exception as e: try: winreg.CloseKey(key) reset_protected_mode() throw_error("\nCould not change Internet Explorer zone settings: " + str(e)) except Exception as msg: print(str(msg)) pass capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.IE]], "capabilities") ie_capabilities = DesiredCapabilities.INTERNETEXPLORER for arg in capabilities: ie_capabilities[arg["option"]] = eval(arg["text"]) # Adding driver to path if not GlobalUtils.is_linux(): print("Using IEDriverServer") if not os.path.join(GlobalUtils.RESOURCES_IE_PATH) in os.environ["PATH"]: print("Adding IEDriverServer to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_IE_PATH) else: raise Exception("Linux can't use IEDriverServer") _driver = webdriver.Ie(capabilities=ie_capabilities) return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.CHROME]: options = webdriver.ChromeOptions() # enable chrome switches try: opt_values = get_config_value("browser_options") for opt_value in opt_values: options.add_argument("--" + opt_value) except: pass extension_if_cases = [] argument_if_cases = [] # enable cache cleaner for resource timings if get_config_value("enable_live_monitoring").lower() == 'true': extension_if_cases.append("enable_live_monitoring") # enable precise memory info if get_config_value("enable_precise_memory").lower() == 'true': argument_if_cases.append("enable_precise_memory") # Get add_argument options from xml add_arguments = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.CHROME]], "add_argument", argument_if_cases) # Get add_extensions options from xml add_extensions = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.CHROME]], "add_extension", extension_if_cases) # Get add_experimental_options options from xml add_experimental_options = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.CHROME]], "add_experimental_option") # add_argument using dict parsed from xml for arg in add_arguments: options.add_argument(eval(arg["text"])) # add_extension using dict parsed from xml for arg in add_extensions: options.add_extension(eval(arg["text"])) # add_experimental_option using dict parsed from xml for arg in add_experimental_options: try: # Selenium 2.26 options.add_experimental_option(arg["option"], eval(arg["text"])) except: pass # Adding driver to path if not GlobalUtils.is_linux(): print("Using 32bit win chromedriver") if not os.path.join(GlobalUtils.RESOURCES_CHROME32_PATH) in os.environ["PATH"]: print("Adding 32bit win chromedriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_CHROME32_PATH) else: print("Using 64bit linux chromedriver") if not os.path.join(GlobalUtils.RESOURCES_LINUX_CHROME64_PATH) in os.environ["PATH"]: print("Adding 64bit linux chromedriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_LINUX_CHROME64_PATH) _driver = webdriver.Chrome(chrome_options=options) try: selenium_library = BuiltIn().get_library_instance("SeleniumLibrary") selenium_library.register_driver(_driver, "default_gc") except: pass return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.FIREFOX]: profile = webdriver.FirefoxProfile() preference_if_cases = [] set_preferences = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.FIREFOX]], "set_preference", preference_if_cases) for arg in set_preferences: profile.set_preference(arg["option"], eval(arg["text"])) set_capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.FIREFOX]], "set_capabilities") firefox_capabilities = DesiredCapabilities.FIREFOX for arg in set_capabilities: firefox_capabilities[arg["option"]] = eval(arg["text"]) # Adding driver to path if not GlobalUtils.is_linux(): print("Using 32bit win geckodriver") # first we try to use 32bit wersion if not os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH) in os.environ["PATH"]: print("Adding 32bit win geckodriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH) else: print("Using 64bit linux geckodriver") if not os.path.join(GlobalUtils.RESOURCES_LINUX_GECKO64_PATH) in os.environ["PATH"]: print("Adding 64bit linux geckodriver to path") os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_LINUX_GECKO64_PATH) try: _driver = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities, log_path=_geckodriver_log_path) except WebDriverException as e: # try with 64bit version if we are using windows if not GlobalUtils.is_linux(): if os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH) in os.environ["PATH"]: os.environ["PATH"] = os.environ["PATH"].replace(os.pathsep + os.path.join(GlobalUtils.RESOURCES_GECKO32_PATH), "") if not os.path.join(GlobalUtils.RESOURCES_GECKO64_PATH) in os.environ["PATH"]: os.environ["PATH"] += os.pathsep + os.path.join(GlobalUtils.RESOURCES_GECKO64_PATH) _driver = webdriver.Firefox(firefox_profile=profile, capabilities=firefox_capabilities) try: selenium_library = BuiltIn().get_library_instance("SeleniumLibrary") selenium_library.register_driver(_driver, "default_ff") except: pass else: raise e return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.EDGE]: capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.EDGE]], "capabilities") options = EdgeOptions() for arg in capabilities: options.set_capability(arg["option"], eval(arg["text"])) options.use_chromium = True # Adding driver to path print("Using EdgeWebDriver") if not GlobalUtils.is_linux(): options.set_capability("platform", "WINDOWS") else: options.set_capability("platform", "LINUX") _driver = Edge(options=options) return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.SAFARI]: desired_capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.SAFARI]], "desired_capabilities") safari_capabilities = DesiredCapabilities.SAFARI for arg in desired_capabilities: safari_capabilities[arg["option"]] = eval(arg["text"]) _driver = webdriver.Safari(desired_capabilities=safari_capabilities) return _driver elif browser_name == GlobalUtils.BROWSER_NAMES[Browsers.OPERA]: desired_capabilities = _get_browser_options_from_project_xml("default", GlobalUtils.BROWSER_FULL_NAMES[GlobalUtils.BROWSER_NAMES[Browsers.OPERA]], "desired_capabilities") opera_capabilities = DesiredCapabilities.OPERA for arg in desired_capabilities: opera_capabilities[arg["option"]] = eval(arg["text"]) _driver = webdriver.Opera(desired_capabilities=opera_capabilities) return _driver else: return None