def launch_browser(self, browser_name, url): global driver try: if browser_name == "chrome": chromeoptions = ChromeOptions() chromeoptions.add_argument("start-maximized") chromeoptions.add_argument("disable-notifications") chromeoptions.add_argument("--ignore-certificate-errors") chromeoptions.add_argument("--disable-infobars") chromeoptions.add_argument("--disable-extensions") driver = webdriver.Chrome( executable_path="./drivers/chromedriver.exe", options=chromeoptions) log.info("chrome browser launch successfully") elif browser_name == "firefox": firefoxoptions = FirefoxOptions() firefoxoptions.add_argument("start-maximize") driver = webdriver.Firefox( executable_path="./drivers/geckodriver.exe", options=firefoxoptions) log.info("firefox browser launch successfully") elif browser_name == "ie": ieoptions = IeOptions() ieoptions.add_argument("start-maximize") driver = webdriver.Ie( executable_path="./drivers/IEDriverServer.exe", options=ieoptions) log.info("ie browser launch successfully") else: log.error("invalid browser name") except WebDriverException as e: log.error("exception ", e) driver.implicitly_wait(10) driver.get(url)
def driver(request): browser = request.config.getoption("--browser") if browser == 'firefox': capabilities = webdriver.DesiredCapabilities.FIREFOX.copy() capabilities['timeouts'] = {'implicit': 3000, 'pageLoad': 3000, 'script': 3000} capabilities['loggingPrefs'] = {'browser': 'ALL', 'client': 'ALL', 'driver': 'ALL', 'performance': 'ALL', 'server': 'ALL'} profile = webdriver.FirefoxProfile() profile.set_preference('app.update.auto', False) profile.set_preference('app.update.enabled', False) profile.accept_untrusted_certs = True wd = webdriver.Firefox(firefox_profile=profile, capabilities=capabilities) wd.maximize_window() elif browser == 'chrome': capabilities = webdriver.DesiredCapabilities.CHROME.copy() capabilities['acceptSslCerts'] = True capabilities['acceptInsecureCerts'] = True wd = webdriver.Chrome(desired_capabilities=capabilities) wd.fullscreen_window() elif browser == 'ie': options = IeOptions() options.add_argument("--start-fullscreen") options.add_argument('--headless') wd = webdriver.Ie(options=options) else: print('Unsupported browser!') sys.exit(1) yield wd wd.quit()
def create_options(self): options = IeOptions() options.add_argument("--disable-popup-blocking") options.add_argument("--start-fullscreen") if super()._use_proxy: pass return options
def driver(request): browser = request.config.getoption("--browser") try: timeout_str = request.config.getoption("--timeouts") timeout = int(timeout_str) except ValueError: print("Bad --timeouts value: ".join(timeout_str)) timeout = 10000 if browser == 'firefox': capabilities = webdriver.DesiredCapabilities.FIREFOX.copy() capabilities['timeouts'] = { 'implicit': timeout, 'pageLoad': timeout, 'script': timeout } capabilities['loggingPrefs'] = { 'browser': 'ALL', 'client': 'ALL', 'driver': 'ALL', 'performance': 'ALL', 'server': 'ALL' } profile = webdriver.FirefoxProfile() profile.set_preference('app.update.auto', False) profile.set_preference('app.update.enabled', False) profile.accept_untrusted_certs = True wd = webdriver.Firefox(firefox_profile=profile, capabilities=capabilities) wd.maximize_window() elif browser == 'chrome': capabilities = webdriver.DesiredCapabilities.CHROME.copy() capabilities['timeouts'] = { 'implicit': timeout, 'pageLoad': timeout, 'script': timeout } capabilities['acceptSslCerts'] = True capabilities['acceptInsecureCerts'] = True wd = webdriver.Chrome(desired_capabilities=capabilities) wd.maximize_window() elif browser == 'ie': options = IeOptions() options.add_argument("--start-fullscreen") options.add_argument('--headless') wd = webdriver.Ie(options=options) else: print('Unsupported browser!') sys.exit(1) log_folder = request.config.getoption("--logfolder") logger = get_logger(log_folder, "webDriverLog") logged_driver = EventFiringWebDriver(wd, WdEventListener(logger)) yield logged_driver if browser == 'chrome': browser_logger = get_logger(log_folder, "chromeLog", "%(message)s") for l in logged_driver.get_log("browser"): browser_logger.info(l) logged_driver.quit()