Beispiel #1
0
 def __init__(self, headless=True, options=[], path='myengine\geckodriver'):
     browser_options = FirefoxOptions()
     for _ in options:
         browser_options.add_argument(_)
     browser_options.headless = headless
     Firefox.__init__(self, options=browser_options, executable_path=path)
     Browser.__init__(self)
Beispiel #2
0
  def __init__(self, url, headless=False):

    if headless:
      self.makeHeadLess()

    ffx.__init__(self)
    self.url = url
    self.minimum_timeout = 60
    self.headless = headless
    self.timed_out = False

    self.load_time = -99
    self.login_time = -99
    self.logout_time = -99

    # Logging
    logfmt = '%(levelname)s [%(asctime)s]:\t  %(message)s'
    datefmt= '%m/%d/%Y %I:%M:%S %p'

    formatter = logging.Formatter(fmt=logfmt,datefmt=datefmt)
    self.logger = logging.getLogger('__main__')

    logging.root.setLevel(logging.DEBUG)
    rfh = RotatingFileHandler(filename="/diska/home/jonny/sw/python/stress/stress/gp_timings.log",maxBytes=1048576,backupCount=3,mode='a')
    rfh.setFormatter(formatter)
    ch = logging.StreamHandler()
    ch.setFormatter(formatter)
    self.logger.handlers = []
    self.logger.addHandler(ch)
    self.logger.addHandler(rfh)
Beispiel #3
0
 def __init__(self, headless=False, disable_images=True, open_links_same_tab=False, disable_flash=True, detect_driver_path=True, timeout=15, driver_version='default', options=None, *args, **kwargs):
     ''' Returns a Firefox webdriver with customised configuration. '''
     if options is None:
         options = Options()
     if disable_flash:
         options.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false')
     if open_links_same_tab:
         options.set_preference('browser.link.open_newwindow.restriction', 0)
         options.set_preference('browser.link.open_newwindow', 1)
     if headless:
         options.headless = True
     if disable_images:
         options.set_preference('permissions.default.image', 2)
     if driver_version == 'default':
         driver_version = Firefox.VERSION_DRIVER
     if detect_driver_path:
         exec_path, log_path = self.find_driver_path(driver_version)
         if exec_path is None:
             raise RuntimeError('Platform %s not recognised. Please install geckodriver manually, add it to the PATH, and set the detect_driver_path to False.' % sys.platform)
         try:
             SeleniumFirefox.__init__(self, options=options, executable_path=exec_path, service_log_path=log_path, *args, **kwargs)
         except SessionNotCreatedException as e:
             raise RuntimeError('Please, install a Firefox compatible with Geckodriver %s from this compatibility table: https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html.' % Firefox.VERSION_DRIVER) from e
     else:
         SeleniumFirefox.__init__(self, options=options, *args, **kwargs)
     self.set_page_load_timeout(timeout)
     register(self.quit)
Beispiel #4
0
    def __init__(self,
                 browser_type="chrome",
                 driver_path=None,
                 *args,
                 **kwargs):
        """
        根据浏览器类型初始化浏览器
        :param browser_type: 浏览器类型,只可传入chrome或firefox
        :param driver_path:指定驱动存放的路径
        """
        # 检查browser_type值是否合法
        if browser_type not in ["chrome", "firefox"]:
            # 不合法报错
            logging.error("browser_type 输入值不为chrome,firefox")
            raise ValueError("browser_type 输入值不为chrome,firefox")

        self.__browser_type = browser_type

        # 根据browser_type值选择对应的驱动
        if self.__browser_type == "chrome":
            if driver_path:
                Chrome.__init__(self,
                                executable_path=driver_path,
                                *args,
                                **kwargs)
            else:
                Chrome.__init__(self, *args, **kwargs)
        elif self.__browser_type == "firefox":
            if driver_path:
                Firefox.__init__(self,
                                 executable_path=driver_path,
                                 *args,
                                 **kwargs)
            else:
                Firefox.__init__(self, *args, **kwargs)
Beispiel #5
0
 def __init__(self, headless=True, executable_path="geckodriver", timeout=10):
     """
     Parameters
     ----------
     headless : bool
         If false, browser window will be opened
     executable_path : str
         Path to geckodriver
     timeout : int
         Timeout for loading browser when calling wait_for_element
     """
     opt = Options()
     opt.headless = headless
     Firefox.__init__(self, options=opt, executable_path=executable_path)
     self.timeout = timeout
Beispiel #6
0
    def __init__(self, url, config={}):

        # Logging
        # -------------------------
        logfmt = '%(levelname)s [%(asctime)s]:\t  %(message)s'
        datefmt = '%m/%d/%Y %I:%M:%S %p'
        formatter = logging.Formatter(fmt=logfmt, datefmt=datefmt)
        self.logger = logging.getLogger('__main__')
        logging.root.setLevel(logging.DEBUG)
        rfh = RotatingFileHandler(
            filename="{0}/logs/WebDriver.log".format(STRESS_PATH),
            maxBytes=1048576,
            backupCount=3,
            mode='a')
        rfh.setFormatter(formatter)
        ch = logging.StreamHandler()
        ch.setFormatter(formatter)
        self.logger.handlers = []
        self.logger.addHandler(ch)
        self.logger.addHandler(rfh)
        # -------------------------

        # Centralise config
        self.config = self.check_config(config)

        # Headless Xvfb
        self.headless = self.makeHeadLess(self.config)

        # Pre-defined attributes
        self.url = url
        self.minimum_timeout = 60  #300 # 5 minutes
        self.timed_out = False
        self.load_time = -99
        self.login_time = -99
        self.logout_time = -99

        # Firefox profiles
        self.profile = self.makeProfile(self.config)

        Firefox.__init__(self, firefox_profile=self.profile)
  def __init__(self, url, config={}):
    
    # Logging
    # -------------------------
    logfmt = '%(levelname)s [%(asctime)s]:\t  %(message)s'
    datefmt= '%m/%d/%Y %I:%M:%S %p'
    formatter = logging.Formatter(fmt=logfmt,datefmt=datefmt)
    self.logger = logging.getLogger('__main__')
    logging.root.setLevel(logging.DEBUG)
    rfh = RotatingFileHandler(filename="{0}/logs/WebDriver.log".format(STRESS_PATH),maxBytes=1048576,backupCount=3,mode='a')
    rfh.setFormatter(formatter)
    ch = logging.StreamHandler()
    ch.setFormatter(formatter)
    self.logger.handlers = []
    self.logger.addHandler(ch)
    self.logger.addHandler(rfh)
    # -------------------------

    # Centralise config
    self.config = self.check_config(config)

    # Headless Xvfb
    self.headless = self.makeHeadLess(self.config)

    # Pre-defined attributes
    self.url = url
    self.minimum_timeout = 60 #300 # 5 minutes
    self.timed_out = False
    self.load_time = -99
    self.login_time = -99
    self.logout_time = -99

    # Firefox profiles
    self.profile = self.makeProfile(self.config)

    Firefox.__init__(self, firefox_profile=self.profile)
Beispiel #8
0
 def __init__(self):
     self.opt = 'none'
     opt = firefox.options.Options()
     #opt.set_headless()                                                             # remove "#" to head window of browser
     Firefox.__init__(self)  # start firefox_driver