Example #1
0
    def test_profile(self, tmpdir_factory):
        opts = Options()
        assert opts.profile is None

        other_profile = FirefoxProfile()
        assert other_profile != opts.profile
        opts.profile = other_profile
        assert other_profile == opts.profile

        opts.profile = str(tmpdir_factory.mktemp("profile"))
        assert isinstance(opts.profile, FirefoxProfile)
Example #2
0
 def get_fx_options(self):
     options = FirefoxOptions()
     options.binary_location = self.fx_path
     profile_dir = self.user_dir + '/.mozilla/firefox/'
     profile_fname = Popen('cat "$HOME/.mozilla/firefox/profiles.ini" | sed -n -e \'s/^.*Path=//p\' | head -n 1', shell=True, stdout=PIPE).communicate()[0].decode().strip()
     options.profile = profile_dir + profile_fname
     return options
Example #3
0
    def test_to_capabilities(self):
        opts = Options()
        assert opts.to_capabilities() == {}

        profile = FirefoxProfile()
        opts.profile = profile
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "profile" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["profile"], basestring)
        assert caps["moz:firefoxOptions"]["profile"] == profile.encoded

        opts.add_argument("--foo")
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "args" in caps["moz:firefoxOptions"]
        assert caps["moz:firefoxOptions"]["args"] == ["--foo"]

        binary = FirefoxBinary()
        opts.binary = binary
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "binary" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["binary"], basestring)
        assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd

        opts.set_preference("spam", "ham")
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "prefs" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["prefs"], dict)
        assert caps["moz:firefoxOptions"]["prefs"]["spam"] == "ham"
Example #4
0
    def create_browser_session(self, url):
        download_dir = os.path.join(path, "downloads", self.scrape_id)
        print("Downloads directory:", download_dir)

        mime_types = "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml"
        fp = webdriver.FirefoxProfile()
        fp.set_preference("browser.link.open_newwindow", 3)
        fp.set_preference("browser.link.open_newwindow.restriction", 2)
        fp.set_preference("browser.download.folderList", 2)
        fp.set_preference("browser.download.manager.showWhenStarting", False)
        fp.set_preference("browser.download.dir", download_dir)
        fp.set_preference("browser.helperApps.neverAsk.saveToDisk", mime_types)
        fp.set_preference("plugin.disable_full_page_plugin_for_types",
                          mime_types)
        fp.set_preference("pdfjs.disabled", True)
        firefox_capabilities = DesiredCapabilities.FIREFOX
        firefox_capabilities['marionette'] = True

        options = FirefoxOptions()
        options.profile = fp
        options.headless = True
        driver = webdriver.Firefox(options=options,
                                   capabilities=firefox_capabilities)
        # driver.maximize_window()
        driver.get(url)
        return driver
Example #5
0
    def __init__(self,
                 keyword: str,
                 file_name: str,
                 option: str,
                 geckoDriver: str,
                 headOption: bool,
                 maximum_question=None,
                 follow_user_data=False):
        '''
		:param option is 15 or 30 or 50 questions by page

		'''
        # Setup the browser
        self.keyword = keyword
        self.file_name = file_name
        self.option = option
        self.max_question = maximum_question
        self.follow_user_data = follow_user_data
        options = Options()
        firefox_profile = webdriver.FirefoxProfile()
        firefox_profile.DEFAULT_PREFERENCES['frozen'][
            "javascript.enabled"] = True
        options.profile = firefox_profile
        headless = False if headOption else True
        options.headless = headless
        self.driver = webdriver.Firefox(executable_path=geckoDriver,
                                        options=options)
Example #6
0
    def test_to_capabilities(self):
        opts = Options()
        firefox_caps = DesiredCapabilities.FIREFOX.copy()
        firefox_caps.update({"pageLoadStrategy": "normal"})
        assert opts.to_capabilities() == firefox_caps

        profile = FirefoxProfile()
        opts.profile = profile
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "profile" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["profile"], str)
        assert caps["moz:firefoxOptions"]["profile"] == profile.encoded

        opts.add_argument("--foo")
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "args" in caps["moz:firefoxOptions"]
        assert caps["moz:firefoxOptions"]["args"] == ["--foo"]

        binary = FirefoxBinary()
        opts.binary = binary
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "binary" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["binary"], str)
        assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd

        opts.set_preference("spam", "ham")
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "prefs" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["prefs"], dict)
        assert caps["moz:firefoxOptions"]["prefs"]["spam"] == "ham"
Example #7
0
def init_firefox(request):
    """
    initialise geckodriver
    """
    #windowHeight=1049
    #windowWidth=1790
    #innerHeight=975

    delta_height = 74  # MacOS
    #delta_height = 74 # Ubuntu
    #delta_width = 76
    firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
    firefox_options = FirefoxOptions()
    profile = FirefoxProfile()
    if not check_for_test_webcam():
        profile.set_preference('media.navigator.streams.fake', True)
    profile.set_preference('media.navigator.permission.disabled', True)
    firefox_options.profile = profile
    firefox_driver = webdriver.Firefox(options=firefox_options,
                                       capabilities=firefox_capabilities)
    firefox_driver.set_window_position(0, 0)
    firefox_driver.set_window_size(INNER_WIDTH, INNER_HEIGHT + delta_height)
    request.cls.driver = firefox_driver
    yield
    firefox_driver.close()
Example #8
0
def get_firefox():
    binary = FirefoxBinary('/usr/bin/firefox')
    fp = webdriver.FirefoxProfile()
    fp.DEFAULT_PREFERENCES['frozen']['javascript.options.shared_memory'] = True
    fp.DEFAULT_PREFERENCES['frozen'][
        'javascript.options.wasm_baselinejit'] = False
    fp.DEFAULT_PREFERENCES['frozen']['javascript.options.wasm'] = True
    fp.DEFAULT_PREFERENCES['frozen']['javascript.options.wasm_ionjit'] = True
    fp.DEFAULT_PREFERENCES['frozen']['browser.tabs.remote.autostart'] = False
    fp.DEFAULT_PREFERENCES['frozen']['devtools.console.stdout.content'] = True
    options = FFOptions()
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.dir", "/mnt/homes/abhinav/Downloads")
    fp.set_preference("browser.download.useDownloadDir", True)
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
                      "application/x-tar")
    fp.add_extension('webconsoletap-1.0-fx.xpi')
    options.profile = fp
    options.binary = '/usr/bin/firefox'
    options.add_argument('-contentproc=2')
    d = DesiredCapabilities.FIREFOX
    d['loggingPrefs'] = {'browser': 'ALL'}
    options.set_capability(name='loggingPrefs', value={'browser': 'ALL'})
    return webdriver.Firefox(executable_path='/usr/bin/geckodriver',
                             firefox_options=options,
                             capabilities=d)
Example #9
0
def create_browser(stock_exchange):
    dir_name, file_name = os.path.split(os.path.abspath(__file__))

    if stock_exchange == 'NASDAQ':
        download_dir = os.path.join(dir_name, 'downloads/NASDAQ_15')
    elif stock_exchange == 'NYSE':
        download_dir = os.path.join(dir_name, 'downloads/NYSE_15')

    print("Downloads directory:", download_dir)

    fp = webdriver.FirefoxProfile()
    fp.set_preference("browser.preferences.instantApply", True)
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.manager.showWhenStarting", False)
    fp.set_preference("browser.helperApps.alwaysAsk.force", False)
    fp.set_preference("browser.download.dir", download_dir)
    fp.set_preference(
        "browser.helperApps.neverAsk.saveToDisk",
        "text/plain, application/octet-stream, application/binary, text/csv, application/csv, text/comma-separated-values"
    )
    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['marionette'] = True
    options = FirefoxOptions()
    options.profile = fp
    options.headless = True
    browser = webdriver.Firefox(options=options,
                                capabilities=firefox_capabilities)
    return browser
Example #10
0
    def test_to_capabilities(self):
        opts = Options()
        assert opts.to_capabilities() == {}

        profile = FirefoxProfile()
        opts.profile = profile
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "profile" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["profile"], types.StringTypes)
        assert caps["moz:firefoxOptions"]["profile"] == profile.encoded

        opts.add_argument("--foo")
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "args" in caps["moz:firefoxOptions"]
        assert caps["moz:firefoxOptions"]["args"] == ["--foo"]

        binary = FirefoxBinary()
        opts.binary = binary
        caps = opts.to_capabilities()
        assert "moz:firefoxOptions" in caps
        assert "binary" in caps["moz:firefoxOptions"]
        assert isinstance(caps["moz:firefoxOptions"]["binary"], types.StringTypes)
        assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd
def navegador_abrir():
    print("Inicializando el navegador.")
    opts = Options()
    opts.headless = constantes.OCULTAR_NAVEGADOR
    if (constantes.FIREFOX_PERFIL != ''):
        opts.profile = constantes.FIREFOX_PERFIL
    navegador = Firefox(options=opts)
    return navegador
def initiateFFbrowser():
    options = Options()
    options.binary_location = r'C:\\Program Files\\Mozilla Firefox\\firefox.exe'
    options.add_argument('-headless')
    options.profile = 'C:\\Users\\yedaya\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ri0nggib.bot_profile'
    driver = webdriver.Firefox(
        executable_path="C:\\Users\\yedaya\\Gechodriver\\geckodriver.exe",
        firefox_options=options)
    return driver
    def get_driver(cls, selenium_hub, browser_type):
        driver = None
        browser_type = browser_type.lower()
        download_file_content_types = "application/octet-stream,application/vnd.ms-excel,text/csv,application/zip,application/binary"

        if browser_type == 'ie':
            opt = ie_webdriver.Options()
            opt.force_create_process_api = True
            opt.ensure_clean_session = True
            opt.add_argument('-private')
            ie_capabilities = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy(
            )
            ie_capabilities.update(opt.to_capabilities())
            driver = webdriver.Remote(selenium_hub,
                                      desired_capabilities=ie_capabilities)
        elif browser_type == 'firefox':
            firefox_profile = FirefoxProfile()
            # firefox_profile参数可以在火狐浏览器中访问about:config进行查看
            firefox_profile.set_preference('browser.download.folderList',
                                           2)  # 0是桌面;1是“我的下载”;2是自定义
            firefox_profile.set_preference(
                'browser.download.dir',
                Read_WEB_UI_Config().web_ui_config.download_dir)
            firefox_profile.set_preference(
                'browser.helperApps.neverAsk.saveToDisk',
                download_file_content_types)
            firefox_options = Firefox_Options()
            if Read_WEB_UI_Config().web_ui_config.is_firefox_headless.lower(
            ) == 'true':
                firefox_options.add_argument('--headless')
            firefox_options.profile = firefox_profile
            driver = webdriver.Remote(
                selenium_hub,
                webdriver.DesiredCapabilities.FIREFOX.copy(),
                options=firefox_options)
        elif browser_type == 'chrome':
            chrome_options = Chrome_Options()
            prefs = {
                'download.default_directory':
                Read_WEB_UI_Config().web_ui_config.download_dir,
                'profile.default_content_settings.popups': 0
            }
            chrome_options.add_experimental_option('prefs', prefs)
            if Read_WEB_UI_Config().web_ui_config.is_chrome_headless.lower(
            ) == 'true':
                chrome_options.add_argument('--headless')
            driver = webdriver.Remote(
                selenium_hub,
                webdriver.DesiredCapabilities.CHROME.copy(),
                options=chrome_options)
        else:
            return driver
        driver.maximize_window()
        driver.delete_all_cookies()
        return driver
Example #14
0
def launchFirefox(binary, fp, dpath):
    opts = Options()
    opts.profile = fp
    # opts.add_argument("--headless")
    opts.add_argument("download.default_directory=" + dpath)
    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['marionette'] = True
    driver = webdriver.Firefox(capabilities=firefox_capabilities,
                               firefox_binary=binary,
                               options=opts)
    return driver
Example #15
0
def driver_kwargs(request, driver_kwargs, profile):
    if request.param == 'capabilities':
        options = {'profile': profile}
        driver_kwargs[request.param].setdefault('moz:firefoxOptions', options)
    elif request.param == 'firefox_profile':
        driver_kwargs[request.param] = profile
    elif request.param == 'firefox_options':
        options = Options()
        options.profile = profile
        driver_kwargs[request.param] = options
    driver_kwargs['firefox_profile'] = profile
    return driver_kwargs
Example #16
0
    def setUp(self):
        self.download_dir = tempfile.mkdtemp()

        options = Options()
        profile = webdriver.FirefoxProfile()
        profile.set_preference("browser.download.dir", self.download_dir)
        profile.set_preference("browser.download.folderList", 2)
        profile.set_preference(
            "browser.helperApps.neverAsk.saveToDisk",
            "images/jpeg, application/pdf, application/octet-stream")
        profile.set_preference("pdfjs.disabled", True)
        options.profile = profile
        self.driver = webdriver.Firefox(options=options)
Example #17
0
def create_instances_of_webdriver(selenium, driver, browser_id_list, tmpdir,
                                  tmp_memory, driver_kwargs, driver_type,
                                  firefox_logging, firefox_path, xvfb,
                                  screen_width, screen_height, displays):

    for browser_id, display in zip(parse_seq(browser_id_list), cycle(xvfb)):
        if browser_id in selenium:
            raise AttributeError('{:s} already in use'.format(browser_id))
        else:
            tmp_memory[browser_id] = {
                'shares': {},
                'spaces': {},
                'groups': {},
                'mailbox': {},
                'oz': {},
                'window': {
                    'modal': None
                }
            }

            with redirect_display(display):
                temp_dir = str(tmpdir)
                download_dir = os.path.join(temp_dir, browser_id, 'download')

                if driver_type.lower() == 'chrome':
                    option_keys = driver_kwargs['desired_capabilities'].keys()
                    option_key = [
                        x for x in option_keys if x.endswith('chromeOptions')
                    ][-1]
                    options = driver_kwargs['desired_capabilities'][option_key]

                    prefs = {"download.default_directory": download_dir}
                    options['prefs'].update(prefs)

                elif driver_type.lower() == 'firefox':
                    options = Options()
                    profile = FirefoxProfile()
                    log_path = _set_firefox_profile(profile, browser_id,
                                                    temp_dir, firefox_logging)
                    options.profile = profile
                    if firefox_path is not None:
                        options.binary = FirefoxBinary(firefox_path)
                    driver_kwargs['firefox_options'] = options

                browser = driver(driver_kwargs)
                if driver_type.lower() == 'firefox' and firefox_logging:
                    browser.get_log = _firefox_logger(log_path)
                _config_driver(browser, screen_width, screen_height)

            displays[browser_id] = display
            selenium[browser_id] = browser
Example #18
0
def firefox_options(request, firefox_path, firefox_profile):
    options = Options()

    if firefox_profile is not None:
        options.profile = firefox_profile

    if firefox_path is not None:
        options.binary = FirefoxBinary(firefox_path)

    for arg in get_arguments_from_markers(request.node):
        options.add_argument(arg)

    for name, value in get_preferences_from_markers(request.node).items():
        options.set_preference(name, value)

    return options
 def launch_browser(cls):
     app.logger.warning(f'Launching {util.get_xena_browser().capitalize()}')
     if util.get_xena_browser() == 'firefox':
         p = FirefoxProfile()
         p.set_preference(key='devtools.jsonview.enabled', value=False)
         options = Foptions()
         options.profile = p
         return webdriver.Firefox(options=options)
     else:
         d = DesiredCapabilities.CHROME
         d['loggingPrefs'] = {'browser': 'ALL'}
         options = Coptions()
         prefs = {
             'profile.default_content_settings.popups': 0,
             'download.default_directory': util.default_download_dir(),
             'directory_upgrade': True,
         }
         options.add_experimental_option('prefs', prefs)
         return webdriver.Chrome(desired_capabilities=d, options=options)
Example #20
0
def create_instances_of_webdriver(selenium, driver, browser_id_list, tmpdir,
                                  tmp_memory, driver_kwargs, driver_type,
                                  firefox_logging, firefox_path, xvfb,
                                  screen_width, screen_height, displays):

    for browser_id, display in zip(parse_seq(browser_id_list), cycle(xvfb)):
        if browser_id in selenium:
            raise AttributeError('{:s} already in use'.format(browser_id))
        else:
            tmp_memory[browser_id] = {'shares': {},
                                      'spaces': {},
                                      'groups': {},
                                      'mailbox': {},
                                      'oz': {},
                                      'window': {'modal': None}}

            with redirect_display(display):
                temp_dir = str(tmpdir)
                download_dir = os.path.join(temp_dir, browser_id, 'download')

                if driver_type.lower() == 'chrome':
                    options = driver_kwargs['desired_capabilities']['chromeOptions']
                    prefs = {"download.default_directory": download_dir}
                    options['prefs'].update(prefs)

                elif driver_type.lower() == 'firefox':
                    options = Options()
                    profile = FirefoxProfile()
                    log_path = _set_firefox_profile(profile, browser_id,
                                                    temp_dir, firefox_logging)
                    options.profile = profile
                    if firefox_path is not None:
                        options.binary = FirefoxBinary(firefox_path)
                    driver_kwargs['firefox_options'] = options

                browser = driver(driver_kwargs)
                if driver_type.lower() == 'firefox' and firefox_logging:
                    browser.get_log = _firefox_logger(log_path)
                _config_driver(browser, screen_width, screen_height)

            displays[browser_id] = display
            selenium[browser_id] = browser
Example #21
0
def firefox_options(request, firefox_path, firefox_profile):
    options = Options()

    if firefox_profile is not None:
        options.profile = firefox_profile

    if firefox_path is not None:
        options.binary = FirefoxBinary(firefox_path)

    args = request.node.get_marker('firefox_arguments')
    if args is not None:
        for arg in args.args:
            options.add_argument(arg)

    prefs = request.node.get_marker('firefox_preferences')
    if prefs is not None:
        for name, value in prefs.args[0].items():
            options.set_preference(name, value)

    return options
Example #22
0
def job():
    try:
        service = Service(PATH)
        options = FirefoxOptions()
        options.headless = True
        profile = "./Profile"
        options.profile = profile
        driver = webdriver.Firefox(options=options, service=service)
        driver.get(f"https://zoom.us/j/{ID}")
        watch = time.strftime("%H:%M - %d/%m/%y")
        print(f"{c_white}[{watch}] {c_green}Joined Zoom Room {ID}{c_white}\n")
        file = open(r"./logger.txt", "a")
        file.write(f"[{watch}] Joined Zoom Room {ID}\n")
        time.sleep(2)
        driver.quit()
    except:
        watch = time.strftime("%H:%M - %d/%m/%y")
        print(f"{c_white}[{watch}] {c_red}Something went wrong!{c_white}\n")
        file = open(r"./logger.txt", "a")
        file.write(f"[{watch}] Something went wrong!\n")
Example #23
0
    def __init__(self):
        """
        [FacebookProfile(name = "person1", fbLink = "www.facebook.com/ person1", friends = (
            FacebookProfile(name = "personA", fbLink = "www.facebook.com/ personA", friends = (
                ), likes = ()
            ) 
            FacebookProfile(name = "personB", fbLink = "www.facebook.com/ personB", friends = (
                ), likes = ()
            )
        ),
        FacebookProfile(name = "person2", fbLink = "www.facebook.com/ person2", friends = (
            FacebookProfile(name = "personA", fbLink = "www.facebook.com/ personA", friends = (
                ), likes = ()
            ) 
            FacebookProfile(name = "personB", fbLink = "www.facebook.com/ personB", friends = (
                ), likes = ()
            )
        )
        ]
        """

        opts = Options()
        customProfile = FirefoxProfile()
        customProfile.set_preference("dom.webnotifications.enabled", False)
        customProfile.set_preference("dom.push.enabled", False)
        opts.profile = customProfile

        self.fbEmail = None
        self.fbPass = None
        self.geckodriverPath = None

        self.profilesFriends = []

        self.options = self._loadArgs()
        self.loadConfig()

        self.driver = webdriver.Firefox(firefox_options=opts)
        self.wait = WebDriverWait(self.driver, 10)
        self.login(self.fbEmail, self.fbPass)

        self._loadFbProfiles()
Example #24
0
 def __init__(self, javascript=True):
     profile = webdriver.FirefoxProfile()
     profile.set_preference('network.proxy.type', 0)
     profile.set_preference('general.useragent.vendor', 'Linux Mint')
     profile.DEFAULT_PREFERENCES['frozen'][
         'dom.webnotifications.serviceworker.enabled'] = False
     profile.DEFAULT_PREFERENCES['frozen'][
         'javascript.enabled'] = javascript
     opts = Options()
     opts.profile = profile
     # caps = DesiredCapabilities.FIREFOX
     # caps['marionette'] = True
     # caps['firefox_profile'] = profile.encoded
     # path_to_driver = 'static/geckodriver'
     bin = FirefoxBinary(path_to_driver)
     self.driver = webdriver.Firefox(
         executable_path=path_to_driver,
         options=opts,
     )
     # capabilities=caps,
     self.action = ActionChains(self.driver)
Example #25
0
    def __init__(
        self,
        loadstyles=False,
        profile=None,
        headless=False,
        extra_params=None,
        executable_path=None,
    ):
        extra_params = extra_params or {}

        self._profile_path = profile
        self._profile = webdriver.FirefoxProfile(self._profile_path)
        if not loadstyles:
            # Disable CSS
            self._profile.set_preference("permissions.default.stylesheet", 2)
            # Disable images
            self._profile.set_preference("permissions.default.image", 2)
            # Disable Flash
            self._profile.set_preference(
                "dom.ipc.plugins.enabled.libflashplayer.so", "false")

            options = Options()

            if headless:
                options.set_headless()

            options.profile = self._profile

            capabilities = DesiredCapabilities.FIREFOX.copy()
            capabilities["webStorageEnabled"] = True

            if executable_path is not None:
                executable_path = os.path.abspath(executable_path)
            extra_params['executable_path'] = executable_path

            self.driver = webdriver.Firefox(capabilities=capabilities,
                                            options=options,
                                            **extra_params)
            self.connect()
Example #26
0
def main():

    # disable cache
    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.cache.disk.enable", False)
    profile.set_preference("browser.cache.memory.enable", False)
    profile.set_preference("browser.cache.offline.enable", False)
    profile.set_preference("network.http.use-cache", False)

    # make the driver headless
    options = Options()
    options.headless = True
    options.profile = profile

    # initialise the driver
    browser = webdriver.Firefox(options=options,
                                service_log_path='/home/echologic/debug.log')

    # to be change with realistic credentials from db
    params['firstName'] = generate_random_string(4, 10)
    params['LastName'] = generate_random_string(4, 10)
    params['email'] = params['firstName'] + params['LastName'] + "@gmail.com"

    print("Authenticating with; ", params)

    # Retry clause
    authenticated = is_authenticated(browser)
    while not authenticated:
        authenticate(browser, params)
        authenticated = is_authenticated(browser)
        if authenticated:
            break
        time.sleep(1)
        print("Retryinng")

    print("Authenticated Successfully")

    # Close the browser gracefully
    browser.quit()
Example #27
0
 def _create_firefox_options(api_obj):
     options = FirefoxOptions()
     args = set()
     if api_obj.browser_options_args:
         args.update(api_obj.browser_options_args)
     for arg in args:
         if arg:
             options.add_argument(arg)
     options.headless = api_obj.headless
     if api_obj.firefox_binary_path:
         options.binary_location = api_obj.firefox_binary_path
     if api_obj.firefox_profile_path:
         options.profile = api_obj.firefox_profile_path
     if api_obj.http_proxy:
         raw = {'proxyType': "manual", 'httpProxy': str(api_obj.http_proxy)}
         proxy = WebdriverProxy(raw=raw)
         options.proxy = proxy
     options.set_capability("acceptInsecureCerts",
                            False)  # why isnt this the default
     if api_obj.browser_options_dict:
         for k, v in api_obj.browser_options_dict.items():
             options.set_capability(k, v)
     return options
    def __init__(self,
                 client="firefox",
                 username="******",
                 proxy=None,
                 command_executor=None,
                 loadstyles=False,
                 profile=None,
                 headless=False,
                 autoconnect=True,
                 logger=None,
                 extra_params=None,
                 chrome_options=None,
                 executable_path=None,
                 disable_browser_updates=False):
        """Initialises the webdriver"""

        self.logger = logger or self.logger
        extra_params = extra_params or {}

        if profile is not None:
            self._profile_path = profile
            self.logger.info("Checking for profile at %s" % self._profile_path)
            if not os.path.exists(self._profile_path):
                self.logger.critical("Could not find profile at %s" % profile)
                raise WhatsAPIException("Could not find profile at %s" %
                                        profile)
        else:
            self._profile_path = None

        self.client = client.lower()
        if self.client == "firefox":
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()

            if not loadstyles:
                # Disable CSS
                self._profile.set_preference('permissions.default.stylesheet',
                                             2)
                # Disable images
                self._profile.set_preference('permissions.default.image', 2)
                # Disable Flash
                self._profile.set_preference(
                    'dom.ipc.plugins.enabled.libflashplayer.so', 'false')

            if disable_browser_updates:
                self._profile.set_preference('app.update.enabled', False)

            if proxy is not None:
                self.set_proxy(proxy)

            options = Options()

            if headless:
                options.set_headless()

            options.profile = self._profile

            capabilities = DesiredCapabilities.FIREFOX.copy()
            capabilities['webStorageEnabled'] = True

            self.logger.info("Starting webdriver")
            if executable_path is not None:
                executable_path = os.path.abspath(executable_path)

                self.logger.info("Starting webdriver")
                self.driver = webdriver.Firefox(
                    capabilities=capabilities,
                    options=options,
                    executable_path=executable_path,
                    **extra_params)
            else:
                self.logger.info("Starting webdriver")
                self.driver = webdriver.Firefox(capabilities=capabilities,
                                                options=options,
                                                **extra_params)

        elif self.client == "chrome":
            self._profile = webdriver.ChromeOptions()
            if self._profile_path is not None:
                self._profile.add_argument("user-data-dir=%s" %
                                           self._profile_path)
            if proxy is not None:
                self._profile.add_argument('--proxy-server=%s' % proxy)
            if headless:
                self._profile.add_argument('headless')
            if chrome_options is not None:
                for option in chrome_options:
                    self._profile.add_argument(option)
            self.logger.info("Starting webdriver")
            self.driver = webdriver.Chrome(chrome_options=self._profile,
                                           **extra_params)

        elif client == 'remote':
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()
            capabilities = DesiredCapabilities.FIREFOX.copy()
            self.driver = webdriver.Remote(command_executor=command_executor,
                                           desired_capabilities=capabilities,
                                           **extra_params)

        else:
            self.logger.error("Invalid client: %s" % client)
        self.username = username
        self.wapi_functions = WapiJsWrapper(self.driver, self)

        self.driver.set_script_timeout(500)
        self.driver.implicitly_wait(10)

        if autoconnect:
            self.connect()
Example #29
0
    test_urls = url_file.readlines()

# start chromedriver using the previously defined options
if browser == "chrome":
    options = ChromeOptions()
    options.binary_location = "C:\\Users\\mozilla\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe"
    driver = webdriver.Chrome(chrome_options=options)
    csvFilename = "chrome_log.txt"

if browser == "firefox":
    binary = (r'C:\Program Files\Firefox Nightly\firefox.exe')
    fp = (
        r'C:\Users\mozilla\AppData\Roaming\Mozilla\Firefox\Profiles\19c2m00s.power_tests'
    )
    opts = Options()
    opts.profile = fp
    driver = webdriver.Firefox(firefox_options=opts, firefox_binary=binary)
    #binary_location = "C:\\Program Files\\Firefox Nightly\\firefox.exe"
    #driver = webdriver.Firefox(firefox_binary=binary_location)
    csvFilename = "firefox_log.txt"

if browser == "edge":
    driver = webdriver.Edge()
    csvFilename = "edge_log.txt"

# set page load time out to 60 seconds
driver.set_page_load_timeout(30)

driver.maximize_window()

pageCounter = 0
Example #30
0
    def init_browser_firefox(self):
        self.print(
            "Start virtual display", end=""
        )  #############################################################
        if self.__debug:
            self.__display = Display(visible=1, size=(1280, 1024))
        else:
            self.__display = Display(visible=0, size=(1280, 1024))
        try:
            self.__display.start()
        except Exception as e:
            raise RuntimeError(
                str(e) +
                "if you launch the script through a ssh connection with '--debug' ensure X11 forwarding is activated"
            )
        else:
            self.print(st="OK")

        self.print(
            "Setup Firefox profile", end=""
        )  #############################################################
        try:
            # Enable Download
            opts = Options()
            fp = webdriver.FirefoxProfile()
            opts.profile = fp
            fp.set_preference('browser.download.dir',
                              self.configuration['download_folder'])
            fp.set_preference('browser.download.folderList', 2)
            fp.set_preference('browser.helperApps.neverAsk.saveToDisk',
                              'text/csv')
            fp.set_preference("browser.download.manager.showWhenStarting",
                              False)
            fp.set_preference("browser.helperApps.neverAsk.openFile",
                              "text/csv")
            fp.set_preference("browser.helperApps.alwaysAsk.force", False)

            # Set firefox binary to use
            binary = FirefoxBinary(self.configuration['firefox'])

            # Enable Mirionette drivers
            firefox_capabilities = DesiredCapabilities.FIREFOX
            firefox_capabilities['marionette'] = True

            # Enable the browser
            self.__browser = webdriver.Firefox(
                capabilities=firefox_capabilities,
                firefox_binary=binary,
                options=opts,
                service_log_path=self.configuration['logs_folder'] +
                "/geckodriver.log",
                executable_path=self.configuration['geckodriver'])
        except Exception:
            raise
        else:
            self.print(st="ok")

        self.print(
            "Start Firefox", end=""
        )  #############################################################
        try:
            self.__browser.maximize_window()
            self.__wait = WebDriverWait(self.__browser,
                                        int(self.configuration["timeout"]))
        except Exception:
            raise
        else:
            self.print(st="OK")
        pass
Example #31
0
    def __init__(self,
                 client="firefox",
                 username="******",
                 proxy=None,
                 command_executor=None,
                 loadstyles=False,
                 profile=None,
                 headless=False,
                 autoconnect=True,
                 logger=None,
                 extra_params=None,
                 chrome_options=None,
                 executable_path=None,
                 script_timeout=60,
                 element_timeout=30,
                 license_key=None,
                 wapi_version='master'):
        """Initialises the webdriver"""

        self.logger = logger or self.logger
        self.license_key = license_key
        extra_params = extra_params or {}

        if profile is not None:
            self._profile_path = profile
            self.logger.info("Checking for profile at %s" % self._profile_path)
            if not os.path.exists(self._profile_path):
                self.logger.critical("Could not find profile at %s" % profile)
                raise WhatsAPIException("Could not find profile at %s" %
                                        profile)
        else:
            self._profile_path = None

        self.client = client.lower()
        if self.client == "firefox":
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()
            if not loadstyles:
                # Disable CSS
                self._profile.set_preference('permissions.default.stylesheet',
                                             2)
                # Disable images
                self._profile.set_preference('permissions.default.image', 2)
                # Disable Flash
                self._profile.set_preference(
                    'dom.ipc.plugins.enabled.libflashplayer.so', 'false')
            # Defaults to no proxy
            self._profile.set_preference("network.proxy.type", 0)
            if proxy is not None:
                self.set_proxy(proxy)

            options = Options()

            if headless:
                options.headless = True

            options.profile = self._profile

            capabilities = DesiredCapabilities.FIREFOX.copy()
            capabilities['webStorageEnabled'] = True

            self.logger.info("Starting webdriver")
            if executable_path is not None:
                executable_path = os.path.abspath(executable_path)

                self.logger.info("Starting webdriver")
                self.driver = webdriver.Firefox(
                    capabilities=capabilities,
                    options=options,
                    executable_path=executable_path,
                    **extra_params)
            else:
                self.logger.info("Starting webdriver")
                self.driver = webdriver.Firefox(capabilities=capabilities,
                                                options=options,
                                                **extra_params)

        elif self.client == "chrome":
            self._profile = webdriver.ChromeOptions()
            if self._profile_path is not None:
                self._profile.add_argument("--user-data-dir=%s" %
                                           self._profile_path)
            if proxy is not None:
                self._profile.add_argument('--proxy-server=%s' % proxy)
            if headless:
                self._profile.add_argument('--headless')
                self._profile.add_argument('--disable-gpu')
                self._profile.add_argument('--remote-debugging-port=9222')
                self._profile.add_argument(
                    '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
                )
            if chrome_options is not None:
                for option in chrome_options:
                    self._profile.add_argument(option)

            if executable_path is not None:
                self.logger.info("Starting webdriver")
                self.driver = webdriver.Chrome(executable_path=executable_path,
                                               chrome_options=self._profile,
                                               **extra_params)
            else:
                self.logger.info("Starting webdriver")
                self.driver = webdriver.Chrome(chrome_options=self._profile,
                                               **extra_params)

        elif client == 'remote':
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()

            options = Options()

            if headless:
                options.headless = True

            capabilities = DesiredCapabilities.FIREFOX.copy()
            self.driver = webdriver.Remote(command_executor=command_executor,
                                           desired_capabilities=capabilities,
                                           options=options,
                                           **extra_params)

        else:
            self.logger.error("Invalid client: %s" % client)
        self.username = username
        self.wapi_functions = WapiJsWrapper(self.driver, self, wapi_version)

        self.driver.set_script_timeout(script_timeout)
        self.element_timeout = element_timeout

        if autoconnect:
            self.connect()
Example #32
0
    def __init__(self, client="firefox", username="******", proxy=None, command_executor=None, loadstyles=False,
                 profile=None, headless=False, autoconnect=True, logger=None, extra_params=None, chrome_options=None):
        """Initialises the webdriver"""

        self.logger = logger or self.logger
        extra_params = extra_params or {}

        if profile is not None:
            self._profile_path = profile
            self.logger.info("Checking for profile at %s" % self._profile_path)
            if not os.path.exists(self._profile_path):
                self.logger.critical("Could not find profile at %s" % profile)
                raise WhatsAPIException("Could not find profile at %s" % profile)
        else:
            self._profile_path = None

        self.client = client.lower()
        if self.client == "firefox":
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()
            if not loadstyles:
                # Disable CSS
                self._profile.set_preference('permissions.default.stylesheet', 2)
                # Disable images
                self._profile.set_preference('permissions.default.image', 2)
                # Disable Flash
                self._profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
                                             'false')
            if proxy is not None:
                self.set_proxy(proxy)

            options = Options()

            if headless:
                options.set_headless()

            options.profile = self._profile

            capabilities = DesiredCapabilities.FIREFOX.copy()
            capabilities['webStorageEnabled'] = True

            self.logger.info("Starting webdriver")
            self.driver = webdriver.Firefox(capabilities=capabilities, options=options, **extra_params)

        elif self.client == "chrome":
            self._profile = webdriver.ChromeOptions()
            if self._profile_path is not None:
                self._profile.add_argument("user-data-dir=%s" % self._profile_path)
            if proxy is not None:
                self._profile.add_argument('--proxy-server=%s' % proxy)
            if headless:
                self._profile.add_argument('headless')
            if chrome_options is not None:
                for option in chrome_options:
                    self._profile.add_argument(option)
            self.logger.info("Starting webdriver")
            self.driver = webdriver.Chrome(chrome_options=self._profile, **extra_params)

        elif client == 'remote':
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()
            capabilities = DesiredCapabilities.FIREFOX.copy()
            self.driver = webdriver.Remote(
                command_executor=command_executor,
                desired_capabilities=capabilities,
                **extra_params
            )

        else:
            self.logger.error("Invalid client: %s" % client)
        self.username = username
        self.wapi_functions = WapiJsWrapper(self.driver, self)

        self.driver.set_script_timeout(500)
        self.driver.implicitly_wait(10)

        if autoconnect:
            self.connect()