def start_browser(request, browser, timeout): """ Setup and run browser :param request: pytest request :param browser: name of browser that will start :param timeout: page load timeout :return wd: web driver :return proxy: browsermob proxy """ chromedriver_path = '/home/zhukov/PycharmProjects/Otus/drivers/chromedriver' firefoxdriver_path = '/home/zhukov/PycharmProjects/Otus/drivers/geckodriver' url = urlparse(proxy.proxy).path if browser == "chrome": des_cap = DesiredCapabilities.CHROME des_cap['loggingPrefs'] = {'performance': 'ALL'} chrome_options().add_argument(argument='--proxy-server={}'.format(url)) options = chrome_options() options.headless = True wd = EventFiringWebDriver( webdriver.Chrome(options=options, executable_path=chromedriver_path, desired_capabilities=des_cap), OpencartListener()) # command_executor = 'http://*****:*****@hub.browserstack.com:80/wd/hub' # wd = EventFiringWebDriver(webdriver.Remote(command_executor, # desired_capabilities={"browserName": "chrome", # 'os': 'Linux', 'os_version': '16.04'}), # OpencartListener()) wd.implicitly_wait(int(timeout)) else: des_cap = DesiredCapabilities.FIREFOX des_cap['loggingPrefs'] = {'performance': 'ALL'} firefox_options().add_argument( argument='--proxy-server={}'.format(url)) options = firefox_options() options.headless = True wd = EventFiringWebDriver( webdriver.Firefox(options=options, executable_path=firefoxdriver_path, desired_capabilities=des_cap), OpencartListener()) # command_executor = 'http://*****:*****@hub.browserstack.com:80/wd/hub' # wd = EventFiringWebDriver(webdriver.Remote(command_executor, # desired_capabilities={"browserName": "firefox", # 'os': 'Windows', 'os_version': '10'}), # OpencartListener()) wd.implicitly_wait(int(timeout)) wd.maximize_window() request.addfinalizer(wd.quit) return wd, proxy
def start_browser(): if config.browser == 'firefox': options = firefox_options() options.headless = config.headless if config.system == "linux": browser = webdriver.Firefox( options=options, executable_path=r"./include/geckodriver") elif config.system == "windows": browser = webdriver.Firefox( options=options, executable_path=r".\include\geckodriver.exe") elif config.browser == 'chrome': options = chrome_options() if config.headless: options.add_argument('--headless') if config.system == "linux": browser = webdriver.Chrome( options=options, executable_path=r"./include/chromedriver") elif config.system == "windows": browser = webdriver.Chrome( options=options, executable_path=r".\include\chromedriver.exe") else: print("Error : wrong browser configured") exit(1) atexit.register(quit_browser, browser) return browser
def browser(self): config_browser = self.config_browser() config_wait_time = self.config_wait_time() config_headless = self.headless_browser() if config_browser == 'chrome': if config_headless == 'yes': driver_options = chrome_options() driver_options.headless = True driver = Chrome(options=driver_options) else: driver = Chrome() elif config_browser == 'firefox': if config_headless == 'yes': driver_options = ff_options() driver_options.headless = True driver = Firefox(options=driver_options) else: driver = Firefox() elif config_browser == 'opera': if config_headless == 'yes': driver_options = opera_options() driver_options.headless = True driver = Opera(options=driver_options) else: driver = Opera() else: raise Exception(f'"{config_browser}" is not a supported browser') driver.implicitly_wait(config_wait_time) return driver
def check_for_url(self): if self.url != "": if self.browser_type.get() == 0: ch_options = chrome_options() if self.headless.get() == 1: ch_options.add_argument("--headless") try: self.driver = webdriver.Chrome("chrome1/chromedriver.exe", options=ch_options) except: try: self.driver = webdriver.Chrome("chrome2/chromedriver.exe", options=ch_options) except: try: self.driver = webdriver.Chrome("chrome3/chromedriver.exe", options=ch_options) except: print("NO WORKING CHROME DRIVER") exit() else: ff_options = firefox_options() if self.headless.get() == 1: ff_options.add_argument("--headless") try: self.driver = webdriver.Firefox("firefox1/geckodriver.exe", options=ff_options) except: try: self.driver = webdriver.Firefox("firefox2/geckodriver.exe", options=ff_options) except: try: self.driver = webdriver.Firefox("firefox3/geckodriver.exe", options=ff_options) except: print("NO WORKING FIREFOX DRIVER") exit() self.driver.get(self.url) self.main_loop()
def browser(request): browser_name = request.config.getoption("browser_name") browser = None language_property = request.config.getoption("language") # выбрасываем исключение, если языка нет в списке if language_property not in language_list: raise pytest.UsageError( "--language should some language that supported by page for e.g. en-gb" ) # установку языка осуществляем после того, как определили браузер if browser_name == "chrome": print("\nstart chrome browser for test..") options = chrome_options() options.add_experimental_option( 'prefs', {'intl.accept_languages': language_property}) browser = webdriver.Chrome(options=options) elif browser_name == "firefox": print("\nstart firefox browser for test..") options = webdriver.FirefoxProfile() options.set_preference("intl.accept_languages", language_property) browser = webdriver.Firefox(firefox_profile=options) else: raise pytest.UsageError("--browser_name should be chrome or firefox") yield browser print("\nquit browser..") browser.quit()
def choose_webdriver(browser): """Choosing availabe webdriver in the webdriver_manager module. Args: browser (str): browser's name. One of ['chrome', 'chromium', 'firefox', 'ie']. """ if browser == 'chrome': options = chrome_options() # silent mode options.add_argument('--headless') # no printing log in the terminal options.add_argument("--log-level=3") driver = webdriver.Chrome( executable_path=ChromeDriverManager().install(), chrome_options=options) elif browser == 'firefox': options = firefox_options() # silent mode options.headless = True driver = webdriver.Firefox( executable_path=GeckoDriverManager().install(), service_log_path=os.devnull, options=options) else: raise Exception('Your browser is not supported.') return (driver)
def get_chrome_options(): options = chrome_options() options.add_argument( 'chrome') # Use headless if you do not need a browser UI options.add_argument('--start-maximized') # максимизировали окно options.add_argument( '--window-size=800,600') # дал определенный размер окна return options
def setup_browser(self): options = chrome_options() options.binary_location = self.chrome_path options.add_argument("--proxy-server=socks5://127.0.0.1:9050") options.add_argument("--headless") options.add_argument("--no-sandbox") browser = webdriver.Chrome(chrome_options=options, executable_path=self.chromedriver_path) return browser
def start_selenium(driver_type='firefox', seleniumwire_driver=False, timeout=60, is_headless=False, proxy=None, **kwargs): if platform.system() == 'Linux': display = Display(visible=0, size=(1280, 1024)) display.start() if seleniumwire_driver: driver_module = xhr_webdriver else: driver_module = webdriver if driver_type == 'firefox': driver_class = driver_module.Firefox driver_path = Path(__file__).parent / '_webdrivers' / 'gecko.exe' webdriver_manager = GeckoDriverManager() options = firefox_options() caps = webdriver.DesiredCapabilities.FIREFOX elif driver_type == 'chrome': driver_class = driver_module.Chrome driver_path = Path(__file__).parent / '_webdrivers' / 'chrome.exe' webdriver_manager = ChromeDriverManager() options = chrome_options() caps = webdriver.DesiredCapabilities.CHROME else: raise NotImplementedError( f"Запуск драйвера {driver_type} не реализован") if proxy: caps['proxy'] = { "proxyType": "MANUAL", "httpProxy": proxy, "sslProxy": proxy } driver_path = driver_path.resolve() if not driver_path.exists(): driver_path.parent.mkdir(exist_ok=True) cache_path = webdriver_manager.install() shutil.copy(cache_path, str(driver_path)) options.headless = is_headless driver = driver_class(options=options, executable_path=str(driver_path), capabilities=caps) if not is_headless: driver.maximize_window() driver.set_page_load_timeout(timeout) return driver
def grab_soup(url_, browser="firefox"): """ This function enables a driver (using Firefox or Chrome), goes to the URL, and retrieves the data after the JS is loaded. :param url_: url to go to to retrieve data :param browser: browser to use, defaults to firefox (requires geckodriver.exe on path) :return: soup - the data of the page driver - the browser (process) instance """ if browser == 'chrome': chromeOptions = chrome_options() chromeOptions.add_experimental_option( "prefs", { "download.default_directory": r"C:\Users\J_Ragbeer\Downloads", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True }) chromeOptions.add_argument("--disable-gpu") chromeOptions.add_argument("--headless") chromeOptions.add_argument('--no-sandbox') chromeOptions.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome( "C:/Users/Julien/PycharmProjects/practice/chromedriver95", options=chromeOptions) else: firefoxOptions = firefox_options() firefoxOptions.set_preference("browser.download.folderList", 2) firefoxOptions.set_preference( "browser.download.manager.showWhenStarting", False) firefoxOptions.set_preference( "browser.download.dir", path.replace('/', '\\') + 'data\\downloads\\') firefoxOptions.set_preference( "browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) driver = webdriver.Firefox(options=firefoxOptions) driver.get(url_) # go to the URL html = driver.page_source time.sleep( 1) # sleep for 1 second to ensure all JS scripts are loaded html = driver.execute_script( "return document.body.outerHTML;") # execute javascript code soup_ = bs.BeautifulSoup( html, 'lxml') # read the data as html (using lxml driver) return soup_, driver
def start(self): if self.browser == 'Chrome': browser_options = chrome_options() browser_options.add_argument("--headless") browser_options.add_argument('--no-sandbox') self.__driver = webdriver.Chrome(options=browser_options) elif self.browser == 'Firefox': browser_options = firefox_options() browser_options.add_argument("--headless") browser_options.add_argument('--no-sandbox') self.__driver = webdriver.Firefox(options=browser_options) else: raise Exception('Please set browser to browser=Firefox or Chrome.') logger.info(f'Using {self.browser}') time.sleep(1) logger.debug('Webdriver Started')
def make_driver(): driver = None if config.use_proxy and config.browser != 'chrome': raise Exception(f'proxy only supported in chrome') if config.browser == 'chrome': _chrome_options = chrome_options() _chrome_options.add_argument("--disable-extensions") _chrome_options.add_argument("--disable-gpu") _chrome_options.add_argument("--disable-notifications") _chrome_options.add_argument("--disable-logging") _chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) _chrome_options.add_experimental_option('prefs', { 'prefs': {'intl.accept_languages': 'en,en-US'}, 'profile.default_content_setting_values.notifications' : 2, 'profile.managed_default_content_settings.images': 2}) #_chrome_options.add_argument(f"user-data-dir={config.chrome_profile_path}") if config.use_proxy: host, port, protocol = config.proxy_list[0] _chrome_options.add_argument(f"--proxy-server={protocol}://{host}:{port}") helper.thread_safe_print(f'using proxy: {protocol}://{host}:{port}') if config.headless: _chrome_options.add_argument("--start-maximized") _chrome_options.add_argument("--headless") driver = webdriver.Chrome(executable_path=config.chrome_driver, options=_chrome_options) elif config.browser == 'firefox': _firefox_profile = FirefoxProfile(config.firefox_profile_path) _firefox_options = firefox_options() _firefox_options.headless = config.headless driver = webdriver.Firefox(_firefox_profile, options=_firefox_options) else: raise Exception(f'unknown brower "{config.browser}"') if not config.skip_login: login(driver) return driver
def before_scenario(context, scenario): # We set our Guerrilla email. this is the temporary email service. context.email_session = GuerrillaMailSession() context.temp_email = context.email_session.get_session_state()['email_address'] # Start browser options = chrome_options() # options = firefox_options() options.add_argument("--start-maximized") options.add_argument("--incognito") options.add_argument("--private") # options.add_argument("--headless") # context.browser = webdriver.Edge() context.browser = Browser(browser='chrome', options=options) context.browser.window().maximize() # We create a dict to store the data of the fake user context.fake_user = dict() # Print which scenario we are about to test print(f'Starting test for {scenario.tags[0]}: {context.scenario.name}\n')
def init(): open("./file/DEBUG.txt", "w", encoding="utf-8").close() try: option = chrome_options() option.add_argument("--headless") v_driver = webdriver.Chrome(options=option) except: print_debug("[v_driver] don't detect Chrome", "yellow") try: option = firefox_options() option.add_argument("--headless") v_driver = webdriver.Opera(options=option) except: print_debug("[v_driver] don't detect Opera", "yellow") try: option = opera_options() option.add_argument("--headless") v_driver = webdriver.Firefox(options=option) except: print_debug("[v_driver] CANT FIND COMPATIBLE DRIVER -> EXIT", "red") e = pop_up( "/msg{-txt:aucun moteur\n de recherche detecté \n(chrome, opera ou firefox) -title:VoltaireTaMere -link:https://www.google.com/intl/fr_fr/chrome/ -lock:0 -size:180x90}" ) e.start_root() e.root.mainloop() exit() return v_driver.get("https://sites.google.com/view/voltairetamere/init") v_driver.implicitly_wait(1) init_command = v_driver.find_element_by_class_name("yaqOZd").text print("init_command:", init_command) v_driver.close() if init_command[init_command.index("version:") + 8:] != found_data( "./file/version.txt", "version", "str"): init_command = "/msg{-txt:VoltaireTaMere doit être\n mis à jour -title:VoltaireTaMere -link:https://sites.google.com/view/voltairetamere/accueil -lock:1 -size:180x70}" if init_command != "version:" + found_data("./file/version.txt", "version", "str"): w = pop_up(init_command) w.start_root() w.root.mainloop() if w.option.lock: exit()
def get_chrome_driver(): caps = DesiredCapabilities().CHROME caps["pageLoadStrategy"] = "none" options = chrome_options() user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36' options.add_argument('--headless') options.add_argument('--no-sandbox') if os.environ.get("DEV"): options.add_argument("--proxy-server=socks5://127.0.0.1:8050") options.add_argument('start-maximized') options.add_argument(f'user-agent={user_agent}') path = os.path.dirname(__file__) if platform.system() == "Linux": path = os.path.join(path, r"driver/chromedriver") else: path = os.path.join(path, r"driver/chromedriver_mac") driver = webdriver.Chrome(executable_path=path, desired_capabilities=caps, chrome_options=options) driver.set_window_size(1920, 1080) hide_webdriver(driver) return driver
def start_browser(request, browser): """ Setup and run browser :param request: pytest request :param browser: name of browser that will start """ chromedriver_path = '/home/support/Py_projects/Otus/drivers/chromedriver' firefoxdriver_path = '/home/support/Py_projects/Otus/drivers/geckodriver' if browser == "chrome": options = chrome_options() options.headless = True wd = webdriver.Chrome(options=options, executable_path=chromedriver_path) else: options = firefox_options() options.headless = True wd = webdriver.Firefox(options=options, executable_path=firefoxdriver_path) wd.maximize_window() request.addfinalizer(wd.quit) return wd
# WPpilot credentials with open("wp_credentials.pickle", "rb") as file: wp_login, wp_password = pickle.load(file) wp_url = ['https://pilot.wp.pl/tv/#tvp-1-hd', 'https://pilot.wp.pl/tv/#tvn'] wp_cookies = ["cookies/wp_tvp1.pickle", "cookies/wp_tvn.pickle"] # WPpilot sources video_sources = [ WPpilot(*i) for i in zip(wp_login, wp_password, wp_cookies, wp_url) ] # webdriver setup options = chrome_options() options.headless = True chromedriver = os.path.abspath("chromedriver") # opening browsers for source in video_sources: source.browser = webdriver.Chrome( executable_path = chromedriver, options = options ) # wp_pilot_login for source in video_sources: wp_pilot_login( source.browser, source.wp_login[0],
def __init__(self, url, username, password, twilio_account_sid="", twilio_auth_token="", gmail_username="", gmail_password="", arg=None): self.url = url self.username = username self.password = password self.twilio_account_sid = twilio_account_sid self.twilio_auth_token = twilio_auth_token self.gmail_username = gmail_username self.gmail_password = gmail_password """ Empty failed_hostnames list to be later used to store hostnames that were not updated because of some issues """ self.failed_hostnames = [] # Checking if firefox or chrome has been chosen in the settings and running selected web driver if settings.get("pref_webdriver").lower() == "firefox": try: # Checking if headless mode has been selected before initialising firefox web driver if arg: print("[*] Launching Firefox with headless mode") # Setting web driver to run in headless mode using firefox Options() and passing it as an argument when initialising firefox web driver firefox_opts = firefox_options() firefox_opts.add_argument("--headless") self.driver = webdriver.Firefox(options=firefox_opts) else: print("[*] Launching Firefox") self.driver = webdriver.Firefox() except: print( """[X] Something went wrong with initialising the firefox web driver, make sure the executable web driver for firefox has been added to PATH in your system and that the current firefox web driver supports the current version of firefox in your system e.g. download an older version of firefox web driver """) sys.exit() elif settings.get("pref_webdriver").lower() == "chrome": try: # Checking if headless mode has been selected before initialising chrome web driver if arg: print("[*] Launching Chrome with headless mode") # Setting web driver to run in headless mode using chrome Options() and passing it as an argument when initialising chrome web driver chrome_opts = chrome_options() chrome_opts.add_argument("--headless") self.driver = webdriver.Chrome(options=chrome_opts) else: print("[*] Launching Chrome") self.driver = webdriver.Chrome() except: print( """[X] Something went wrong with initialising the chrome web driver, make sure the executable web driver for chrome has been added to PATH in your system and that the current chrome web driver supports the current version of chrome in your system e.g. download an older version of chrome web driver """) sys.exit() else: print( "[X] Given web browser name in settings is not recognised must be either firefox or chrome" ) sys.exit()
def grab_soup(url_, browser="firefox", indicator=''): """ This function enables a driver (using Firefox or Chrome), goes to the URL, and retrieves the data after the JS is loaded. :param url_: url to go to to retrieve data :param browser: browser to use, defaults to firefox (requires geckodriver.exe on path) :param indicator: specific page that is being looked at, waits for certain elements to load depending on this value. :return: soup - the data of the page driver - the browser (process) instance """ if browser == 'chrome': chromeOptions = chrome_options() chromeOptions.add_experimental_option( "prefs", { "download.default_directory": r"C:\Users\Julien\Downloads", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True }) chromeOptions.add_argument("--disable-gpu") chromeOptions.add_argument("--headless") chromeOptions.add_argument('--no-sandbox') chromeOptions.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome( 'C:/Users/Julien/PycharmProjects/practice/chromedriver86', options=chromeOptions) else: firefoxOptions = firefox_options() firefoxOptions.set_preference("browser.download.folderList", 2) firefoxOptions.set_preference( "browser.download.manager.showWhenStarting", False) firefoxOptions.set_preference( "browser.download.dir", path.replace('/', '\\') + 'data\\downloads\\') firefoxOptions.set_preference( "browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ) driver = webdriver.Firefox(options=firefoxOptions) driver.get(url_) # go to the URL # wait up to 7 seconds for element to load if indicator == 'game_info': try: my_elem = WebDriverWait(driver, 7).until( EC.presence_of_element_located((By.CLASS_NAME, 'attendance'))) except TimeoutException: print("Loading took too much time!") elif indicator == 'matchup': try: my_elem = WebDriverWait(driver, 7).until( EC.presence_of_element_located((By.ID, 'gamepackage-matchup'))) except TimeoutException: print("Loading took too much time!") elif indicator == 'playbyplay': try: my_elem = WebDriverWait(driver, 7).until( EC.presence_of_element_located( (By.ID, "gamepackage-play-by-play"))) except TimeoutException: print("Loading took too much time!") time.sleep(0.5) try: html = driver.page_source except: pass # sleep for 1 second to ensure all JS scripts are loaded try: html = driver.execute_script( "return document.body.outerHTML;") # execute javascript code except: pass soup_ = bs.BeautifulSoup( html, 'lxml') # read the data as html (using lxml driver) # pprint(soup_) return soup_, driver
def getWebDriverInstance(self): """ Get WebDriver Instance based on the browser configuration For Bamboo integration need to use the webdriver manager to install the webdrivers on runtime instead of using the path on local machine: https://github.com/SergeyPirogov/webdriver_manager Returns: 'WebDriver Instance' """ """" # Location where I save the drivers on my local machine chromeDriverLocation = "C:\\Users\\nhussein\\PycharmProjects\\chromedriver.exe" ffDriverLocation = "C:\\Users\\nhussein\\PycharmProjects\\geckodriver.exe" ieDriverLocation = "C:\\Users\\nhussein\\PycharmProjects\\IEDriverServer.exe" """ if self.browser == "ie": # Set ie driver #os.environ["webdriver.ie.driver"] = ieDriverLocation #driver = webdriver.Ie(ieDriverLocation) #install IE driver to default path C:\Users\nhussein\.wdm\IEDriverServer\3.141.5\Win32 driver = webdriver.Ie(IEDriverManager(os_type="win32").install()) elif self.browser == "edge": #default installation folder C:\Users\nhussein\.wdm\MicrosoftWebDriver\latest\win driver = webdriver.Edge(EdgeDriverManager().install()) elif self.browser == "ff": #driver = webdriver.Firefox() # default installation path C:\Users\nhussein\.wdm\geckodriver\v0.23.0\win64 driver = webdriver.Firefox( executable_path=GeckoDriverManager().install()) elif self.browser == "ffdocker": #driver = webdriver.Firefox() capabilities = DesiredCapabilities.FIREFOX.copy() driver = webdriver.Remote("http://127.0.0.1:4446/wd/hub", capabilities) elif self.browser == "ffheadless": ffDriverLocation = "C:\TEMP\geckodriver.exe" webdriver.Firefox(executable_path=GeckoDriverManager().install( path="C:\TEMP")) options = ff_options() options.headless = True driver = webdriver.Firefox(options=options, executable_path=ffDriverLocation) elif self.browser == "chrome": # Set chrome driver #os.environ["webdriver.chrome.driver"] = chromeDriverLocation #driver = webdriver.Chrome(chromeDriverLocation) driver = webdriver.Chrome(ChromeDriverManager().install()) driver.set_window_size(1920, 1080) elif self.browser == "chromedocker": # Set chrome driver #driverLocation = "C:\\Users\\nhussein\\PycharmProjects\\selenium_workspace\\chromedriver.exe" #os.environ["webdriver.chrome.driver"] = chromeDriverLocation ####### THIS WILL USE DOCKER CONTAINER AND LAUNCH THE SCRIPT ON VNC ##########################3########## capabilities = DesiredCapabilities.CHROME.copy() #capabilities['platform'] = "WINDOWS" #capabilities['version'] = "10" capabilities['takesScreenshot'] = True driver = webdriver.Remote("http://127.0.0.1:4446/wd/hub", capabilities) driver.set_window_size(1920, 1080) elif self.browser == "chromeheadless": chromeDriverLocation = "C:\TEMP\chromedriver.exe" webdriver.Chrome(ChromeDriverManager().install(path="C:\TEMP")) # To use the default driver installation path comment out the above 2 lines and uncomment the below 2 lines #webdriver.Chrome(ChromeDriverManager().install()) #chromeDriverLocation = str(self.getHomeDirectory())+"\.wdm\chromedriver\\2.45\win32\chromedriver.exe" options = chrome_options() options.headless = True driver = webdriver.Chrome(chromeDriverLocation, chrome_options=options) elif self.browser == "mobile": # Select which device you want to emulate by uncommenting it # More information at: https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation mobile_emulation = { "deviceName": "iPhone 6/7/8" # "deviceName": "iPhone 6/7/8 Plus" # "deviceName": "iPhone X" # "deviceName": "iPad" # "deviceName": "iPad Mini" # "deviceName": "iPad Pro" # "deviceName": "Nexus 10" # "deviceName": "Galaxy S III" # "deviceName": "Galaxy Note 3" # Or specify a specific build using the following two arguments # "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, # "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" } # Define a variable to hold all the configurations we want options = chrome_options() # Add the mobile emulation to the chrome options variable options.add_experimental_option("mobileEmulation", mobile_emulation) # Create driver, pass it the path to the chromedriver file and the special configurations you want to run chromeDriverLocation = "C:\TEMP\chromedriver.exe" webdriver.Chrome(ChromeDriverManager().install(path="C:\TEMP")) driver = webdriver.Chrome(chromeDriverLocation, chrome_options=options) else: #driver = webdriver.Firefox() driver = webdriver.Firefox( executable_path=GeckoDriverManager().install()) # Setting Driver Implicit Time out for An Element driver.implicitly_wait(3) # Maximize the window driver.maximize_window() #selecting the URL based on the environment param #env = self.environment.lower() if self.environment == 'qa': baseURL = "https://portal.qa.aws.wfscorp.com/" elif self.environment == 'test': baseURL = "https://portal.test.aws.wfscorp.com/" elif self.environment == 'dev': baseURL = "https://portal.dev.aws.wfscorp.com/" else: baseURL = "https://portal.qa.aws.wfscorp.com/" # Loading browser with App URL driver.get(baseURL) return driver
def get_chrome_options(): options = chrome_options() options.add_argument('chrome') options.add_argument('--start-maximized') options.add_argument('--window-size = 800, 600') return options