Exemple #1
0
def driver_headlessed(request):
    '''
    фикстура для запуска браузера в режиме headless
    для домашки по запуску браузеров
    :param request:
    :return wd: возвращает вебдрайвер
    '''
    browser = request.config.getoption("--browser")
    if browser == 'firefox':
        firefox_opts = webdriver.FirefoxOptions()
        firefox_opts.add_argument("--headless")
        wd = webdriver.Firefox()
    elif browser == 'chrome':
        chrome_opts = options_chr()
        chrome_opts.add_argument("--headless")
        chrome_opts.add_argument("--disable-gpu")
        chrome_opts.add_argument("--no-sandbox")
        wd = webdriver.Chrome(options=chrome_opts)
    elif browser == 'opera':
        opera_driver_loc = os.path.abspath('/usr/bin/operadriver')
        opera_exe_loc = os.path.abspath('/usr/bin/opera')
        opera_caps = desired_capabilities.DesiredCapabilities.OPERA.copy()
        opera_opts = options_oper.ChromeOptions()
        opera_opts.add_argument("--headless")
        opera_opts._binary_location = opera_exe_loc
        wd = webdriver.Chrome(executable_path=opera_driver_loc,
                              options=opera_opts,
                              desired_capabilities=opera_caps)
    else:
        print('Unsupported browser!')
        sys.exit(1)
    request.addfinalizer(wd.close)
    return wd
Exemple #2
0
def main():
    browser_inited=False
    try:
        if args.browser is None or args.browser=="firefox":
            if len(tp_names)>=1:
                if args.verbose:
                    print("Using profile: " + tp_names[0])
                browser = webdriver.Firefox(tp_names[0])
            else:
                browser = webdriver.Firefox()
        elif args.browser=="opera":
            opopts=op_options.ChromeOptions()
            opcaps=desired_capabilities.DesiredCapabilities.OPERA.copy()
            browser=webdriver.Opera(desired_capabilities=opcaps,options=opopts)
        elif args.browser=="chrome":
            browser=webdriver.Chrome('/usr/local/bin/chromedriver')
        else:
            print(sys.argv[0]+": Unsupported browser - " + args.browser + " - exiting")
            sys.exit(1)
    
        #browser shall call the URL
        browser_inited=True
        browser.get(args.url)
        time.sleep(10)
        browser.quit()
    except Exception as s:
        print("Excepton: " + str(s))
        if browser_inited:
            browser.quit()
Exemple #3
0
def parametrized_browser(request):
    """
    Фикстура автоматом подхватывающая УРЛ из парсера.. и позволяющая одним тестом запускать 3 браузера
    :param request:
    :return:
    """
    browser_param = request.param
    if browser_param == "chrome":
        driver = webdriver.Chrome()
    elif browser_param == "firefox":
        driver = webdriver.Firefox()
    elif browser_param == "opera":
        opera_driver_loc = os.path.abspath('/usr/bin/operadriver')
        opera_exe_loc = os.path.abspath('/usr/bin/opera')
        opera_caps = desired_capabilities.DesiredCapabilities.OPERA.copy()
        opera_opts = options_oper.ChromeOptions()
        opera_opts._binary_location = opera_exe_loc
        wd = webdriver.Chrome(executable_path=opera_driver_loc,
                              options=opera_opts,
                              desired_capabilities=opera_caps)
    else:
        raise Exception(f"{request.param} is not supported!")

    request.addfinalizer(driver.quit)
    driver.get(request.config.getoption("--url"))
    return driver
Exemple #4
0
 def opera(self):
     __operaCaps = desired_capabilities.DesiredCapabilities.OPERA.copy()
     __operaOpts = options.ChromeOptions()
     __operaOpts._binary_location = self.__operaExeLoc
     self.driver = webdriver.Chrome(executable_path=self.__operaDriverLoc,
                                    chrome_options=__operaOpts,
                                    desired_capabilities=__operaCaps)
     self.driver.get(self.url)
Exemple #5
0
def browser(request):
    '''
     фикстура для запуска браузера
     для домашки по поиску элементов
     :param request:
     :return wd: возвращает вебдрайвер
     '''
    browser_param = request.config.getoption("--browser")
    wait_time = request.config.getoption("--wait")
    if browser_param == "chrome":
        chrome_driver_loc = os.path.abspath('/usr/bin/chromedriver')
        chrome_exe_loc = os.path.abspath('/usr/bin/google-chrome-stable')
        chrome_caps = desired_capabilities.DesiredCapabilities.CHROME.copy()
        chrome_opts = options_oper.ChromeOptions()
        chrome_opts._binary_location = chrome_exe_loc
        driver = webdriver.Chrome(executable_path=chrome_driver_loc,
                                  options=chrome_opts,
                                  desired_capabilities=chrome_caps)
    elif browser_param == "firefox":
        driver = webdriver.Firefox()
    elif browser_param == "opera":
        opera_driver_loc = os.path.abspath('/usr/bin/operadriver')
        opera_exe_loc = os.path.abspath('/usr/bin/opera')
        opera_caps = desired_capabilities.DesiredCapabilities.OPERA.copy()
        opera_opts = options_oper.ChromeOptions()
        opera_opts._binary_location = opera_exe_loc
        driver = webdriver.Chrome(executable_path=opera_driver_loc,
                                  options=opera_opts,
                                  desired_capabilities=opera_caps)
    else:
        raise Exception(f"{request.param} is not supported!")

    request.addfinalizer(driver.close)
    driver.implicitly_wait(wait_time)
    driver.get(request.config.getoption("--url"))
    return driver
def download_pages():
    # Replace this path with the actual path on your machine.
    current_dir = os.path.dirname(__file__)
    opera_driver_filename = os.path.join(current_dir, 'operadriver.exe')
    opera_driver_location = os.path.abspath(opera_driver_filename)

    # Replace this path with the actual path on your machine.
    oper_exe_file_location = os.path.abspath(
        'D:\\Program Files\\Opera\\58.0.3135.127\\opera.exe')

    opera_capabilities = desired_capabilities.DesiredCapabilities.OPERA.copy()

    opera_options = options.ChromeOptions()
    opera_options.binary_location = oper_exe_file_location

    # Use the below argument if you want the Opera browser to be in the max. state when launching.
    opera_options.add_argument('--start-maximized')

    driver = webdriver.Chrome(executable_path=opera_driver_location,
                              chrome_options=opera_options,
                              desired_capabilities=opera_capabilities)
    driver.get("https://www.jbhifi.com.au/")
    while True:
        if 'JB Hi-Fi | JB Hi-Fi - Australia' in driver.page_source:
            break

    new_elems = driver.find_elements_by_class_name("info-wrapper")
    print(len(new_elems))
    for x in range(0, len(new_elems)):
        new_elems = driver.find_elements_by_class_name("info-wrapper")

        time.sleep(3)
        if new_elems[x].is_displayed():
            print('Parse elem ', x)
            print(new_elems[x].text)
            link_elem = new_elems[x].find_element_by_xpath('..')

            link_elem.click()
            time.sleep(3)
            page = driver.page_source
            current_dir = os.path.dirname(__file__)
            html_filename = 'htmls\\page_' + '_' + str(x) + '.html'
            filemame = os.path.join(current_dir, html_filename)
            with open(filemame, "w", encoding="utf-8") as f:
                f.write(page)
            driver.back()
            time.sleep(1)
Exemple #7
0
def download_pages():
    """
    Download necessary pages from http://medsalltheworld.com
    :return:
    """
    # Replace this path with the actual path on your machine.
    current_dir = os.path.dirname(__file__)
    opera_driver_filename = os.path.join(current_dir, 'operadriver.exe')
    opera_driver_location = os.path.abspath(opera_driver_filename)

    # Replace this path with the actual path on your machine.
    oper_exe_file_location = os.path.abspath('D:\\Program Files\\Opera\\58.0.3135.127\\opera.exe')

    opera_capabilities = desired_capabilities.DesiredCapabilities.OPERA.copy()

    opera_options = options.ChromeOptions()
    opera_options.binary_location = oper_exe_file_location

    # Use the below argument if you want the Opera browser to be in the max. state when launching.
    opera_options.add_argument('--start-maximized')

    driver = webdriver.Chrome(executable_path=opera_driver_location, chrome_options=opera_options,
                              desired_capabilities=opera_capabilities)
    # Some sites don't open from Russia. So, you have 5 seconds to enable Opera VPN.
    vpn_settings_url = 'opera://settings/vpn'
    driver.get(vpn_settings_url)
    time.sleep(5)
    # You can use multithreading here but I don't like enable VPN some times:)
    for symbol in string.ascii_lowercase:
        letter_part = 'letter-' + symbol + '-eu.html'
        url = 'http://medsalltheworld.com/' + letter_part
        driver.get(url)

        time.sleep(2)
        page = driver.page_source
        current_dir = os.path.dirname(__file__)
        html_filename = 'htmls\\page_' + '_' + letter_part
        full_filename = os.path.join(current_dir, html_filename)
        with open(full_filename, "w", encoding="utf-8") as file:
            file.write(page)
def download_pages():
    """
    Download necessary pages from https://www.riai.ie/practice_directory/search-results/search&pCity=Dublin/
    :return:
    """
    # Replace this path with the actual path on your machine.
    current_dir = os.path.dirname(__file__)
    opera_driver_filename = os.path.join(current_dir, 'operadriver.exe')
    opera_driver_location = os.path.abspath(opera_driver_filename)

    # Replace this path with the actual path on your machine.
    oper_exe_file_location = os.path.abspath(
        'D:\\Program Files\\Opera\\60.0.3255.170\\opera.exe')

    opera_capabilities = desired_capabilities.DesiredCapabilities.OPERA.copy()

    opera_options = options.ChromeOptions()
    opera_options.binary_location = oper_exe_file_location

    # Use the below argument if you want the Opera browser to be in the max. state when launching.
    opera_options.add_argument('--start-maximized')

    driver = webdriver.Chrome(executable_path=opera_driver_location,
                              chrome_options=opera_options,
                              desired_capabilities=opera_capabilities)
    driver.get(
        "https://www.riai.ie/practice_directory/search-results/search&pCity=Dublin/"
    )
    select = Select(driver.find_element_by_name('sortable_length'))
    select.select_by_value('100')
    time.sleep(2)
    # return

    # next_elem = driver.find_element_by_class_name('paginate_enabled_next')
    counter = 0
    while True:
        # Parse
        new_elems = driver.find_elements_by_link_text('More Info')
        print(len(new_elems))
        for x in range(0, len(new_elems)):
            newest_elems = driver.find_elements_by_link_text('More Info')

            # time.sleep(3)
            if newest_elems[x].is_displayed():
                print('Parse elem ', x)

                newest_elems[x].click()
                time.sleep(1)
                page = driver.page_source
                current_dir = os.path.dirname(__file__)
                html_filename = 'htmls\\page_' + '_' + str(x) + '_' + str(
                    counter) + '.html'
                filemame = os.path.join(current_dir, html_filename)
                with open(filemame, "w", encoding="utf-8") as f:
                    f.write(page)
                driver.back()

                select = Select(driver.find_element_by_name('sortable_length'))
                select.select_by_value('100')
                time.sleep(1)

                for ind in range(1, counter + 1):
                    next_elem = driver.find_element_by_class_name(
                        'paginate_enabled_next')
                    print('1 skip ', next_elem)
                    if not next_elem:
                        break
                    next_elem.click()
                    select = Select(
                        driver.find_element_by_name('sortable_length'))
                    select.select_by_value('100')
                    time.sleep(2)

        counter += 1
        next_elem = driver.find_element_by_class_name('paginate_enabled_next')
        print('2 skip ', next_elem)
        if not next_elem:
            break
        next_elem.click()
        select = Select(driver.find_element_by_name('sortable_length'))
        select.select_by_value('100')
        time.sleep(2)
    return
Exemple #9
0
    def getWebDriverInstance(self):
        """
        Get WebDriver Instance based on the browser configuration
        Returns:
            'WebDriver Instance'
        """

        strver = 'version'
        if self.browser == "iexplorer" or self.browser == "ie" or self.browser == "IE":
            # Set IE driver
            iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x64_2.42.0.exe'
            # iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x64_3.12.0.exe' ## not working
            # iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x32_3.4.0.exe'  ## work but 32bit
            driver = webdriver.Ie(iedriverserver)
        elif self.browser == 'safari':  ### Safari not working on Windows - need Safari 10 on OSX El Capitan
            safaridriver = r'C:\tools\Python36\Scripts\SafariDriver.exe'
            driver = webdriver.Safari(safaridriver)
        elif self.browser == 'opera':
            # OperaDriver - win64 2.36 - https://github.com/operasoftware/operachromiumdriver/releases
            _operaDriverLoc = r'C:\tools\Python36\Scripts\operadriver_win64_2.36.exe'
            # Opera browser # Version:	53.0.2907.68  # System:	Windows 7 64-bit
            _operaExeLoc = r'C:\Program Files\Opera\53.0.2907.68\opera.exe'
            from selenium.webdriver.common import desired_capabilities as operacapabilities
            from selenium.webdriver.opera import options as operaoptions
            _operaCaps = operacapabilities.DesiredCapabilities.OPERA.copy()
            _operaOpts = operaoptions.ChromeOptions()
            _operaOpts._binary_location = _operaExeLoc
            # driver = webdriver.Chrome(executable_path = _operaDriverLoc, chrome_options = _operaOpts, desired_capabilities = _operaCaps)
            driver = webdriver.Opera(executable_path=_operaDriverLoc,
                                     options=_operaOpts,
                                     desired_capabilities=_operaCaps)
        elif self.browser == "firefox" or self.browser == "ff":
            driver = webdriver.Firefox()
            strver = 'browserVersion'
        elif self.browser == "chrome":
            # Set chrome driver
            chromedriver = r'C:\tools\Python36\Scripts\chromedriver.exe'
            #os.environ["webdriver.chrome.driver"] = chromedriver
            chrome_options = webdriver.ChromeOptions()
            # chrome_options.add_argument('--disable-extensions')
            #chrome_options.add_argument('--profile-directory=Default')
            chrome_options.add_argument("--incognito")
            # chrome_options.add_argument("--disable-plugins-discovery")
            # chrome_options.add_argument("--start-maximized")
            driver = webdriver.Chrome(chromedriver,
                                      chrome_options=chrome_options)
            #driver.set_window_size(1440, 900)
        elif self.browser == "headless" or self.browser == "nobrowser" or self.browser == "virtual":
            # This is for running without open Browser UI display - good for Jenkins
            chromedriver = r'C:\tools\Python36\Scripts\chromedriver.exe'
            chrome_options = webdriver.ChromeOptions()
            # chrome_options.add_argument('--disable-extensions')
            chrome_options.add_argument("--incognito")
            # chrome_options.add_argument("--disable-plugins-discovery")
            # chrome_options.add_argument("--start-maximized")
            chrome_options.add_argument('--headless')
            chrome_options.add_argument("--proxy-server='direct://'")
            chrome_options.add_argument("--proxy-bypass-list=*")
            driver = webdriver.Chrome(chromedriver,
                                      chrome_options=chrome_options)
        else:
            driver = webdriver.Firefox()
            strver = 'browserVersion'

        # Setting Driver Implicit Time out for An Element
        driver.implicitly_wait(3)

        # Maximize the window
        # driver.maximize_window()
        print('Browser version ( ' + driver.name + ' ) = ' +
              driver.capabilities[strver])

        return driver
Exemple #10
0
    def getWebDriverInstance(self, baseURL):
        """
        Get WebDriver Instance based on the browser configuration
        Returns:
            'WebDriver Instance'
        """
        # strver = 'version'
        strver = 'browserVersion'
        driver_name = 'unknown'
        driver_version = 'unknown'
        if self.browser == "iexplorer" or self.browser == "ie" or self.browser == "IE":
            # Set IE driver
            iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x64_2.42.0.exe'
            # iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x64_3.12.0.exe' ## not working
            # iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x32_3.4.0.exe'  ## work but 32bit
            driver = webdriver.Ie(iedriverserver)
        elif self.browser == 'safari':  ### Safari not working on Windows - need Safari 10 on OSX El Capitan
            safaridriver = r'C:\tools\Python36\Scripts\SafariDriver.exe'
            driver = webdriver.Safari(safaridriver)
        elif self.browser == 'opera':
            # OperaDriver - win64 2.36 - https://github.com/operasoftware/operachromiumdriver/releases
            from os import listdir
            from selenium.webdriver.common import desired_capabilities as operacapabilities
            from selenium.webdriver.opera import options as operaoptions
            # OperaDriver - win64 2.36 - https://github.com/operasoftware/operachromiumdriver/releases
            _operaDriverLoc = r'C:\tools\Python36\Scripts\operadriver_win64_2.36.exe'
            # Opera browser
            _operaInstDir = r'C:\Program Files\Opera\\'
            listOperaDir = listdir(_operaInstDir)
            listOperaVer = [
                char for char in listOperaDir
                if char[0].isdigit() and char[-1].isdigit()
            ]
            # listOperaVer.sort(key=lambda version: [int(ver) for ver in version.split('.')])
            listOperaVer.sort()
            _operacurrentversion = listOperaVer[-1]
            _operaExeLoc = _operaInstDir + _operacurrentversion + r'\opera.exe'
            _operaCaps = operacapabilities.DesiredCapabilities.OPERA.copy()
            _operaOpts = operaoptions.ChromeOptions()
            _operaOpts._binary_location = _operaExeLoc
            # driver = webdriver.Chrome(executable_path = _operaDriverLoc, chrome_options = _operaOpts, desired_capabilities = _operaCaps)
            driver = webdriver.Opera(executable_path=_operaDriverLoc,
                                     options=_operaOpts,
                                     desired_capabilities=_operaCaps)
            driver_name = 'opera'
            driver_version = _operacurrentversion
        elif self.browser == "firefox" or self.browser == "ff":
            driver = webdriver.Firefox()
            # strver = 'browserVersion'
        elif self.browser == "headless" or self.browser == "nobrowser" or self.browser == "virtual":
            # This is for running without open Browser UI display - good for Jenkins
            chromedriverpath = r'C:\tools\python3\Scripts\chromedriver.exe'
            chrome_options = webdriver.ChromeOptions()
            # chrome_options.add_argument('--disable-extensions')
            chrome_options.add_argument("--incognito")
            # chrome_options.add_argument("--disable-plugins-discovery")
            # chrome_options.add_argument("--start-maximized")
            chrome_options.add_argument('--headless')
            chrome_options.add_argument("--proxy-server='direct://'")
            chrome_options.add_argument("--proxy-bypass-list=*")
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)
        else:
            # Set chrome driver
            # self.browser == "chrome":
            chromedriverpath = r'C:\tools\python3\Scripts\chromedriver.exe'
            #os.environ["webdriver.chrome.driver"] = chromedriverpath
            chrome_options = webdriver.ChromeOptions()
            # chrome_options.add_argument('--disable-extensions')
            #chrome_options.add_argument('--profile-directory=Default')
            chrome_options.add_argument("--incognito")
            # chrome_options.add_argument("--disable-plugins-discovery")
            # chrome_options.add_argument("--start-maximized")
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)
            #driver.set_window_size(1440, 900)

        # dah jadikan default browser = chrome
        # else:
        #    driver = webdriver.Firefox()
        #    strver = 'browserVersion'

        # Setting Driver Implicit Time out for An Element
        driver.implicitly_wait(10)

        # Maximize the window
        if driver.name == 'chrome' and driver_name == 'unknown':
            driver.maximize_window()

        # Loading browser with App URL
        driver.get(baseURL)

        if driver_name != 'unknown':
            print('Browser version ( ' + str(driver_name) + ' ) = ' +
                  str(driver_version))
        else:
            print('Browser version ( ' + driver.name + ' ) = ' +
                  driver.capabilities[strver])

        return driver
Exemple #11
0
    def browserDriverExe(self, name):
        driver_version = 'unknown'
        driver_name = 'unknown'
        if name == 'safari':  ### Safari not working on Windows - need Safari 10 on OSX El Capitan
            safaridriver = self.driver_path
            driver = webdriver.Safari(safaridriver)
        elif name == "iexplorer" or name == "ie" or name == "IE":
            iedriverserver = self.driver_path
            driver = webdriver.Ie(iedriverserver)
        elif name == "firefox" or name == "ff":
            driver = webdriver.Firefox()
        elif name == 'brave':
            brave_exe = self.browser_exe
            chromedriverpath = self.driver_path
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument("--disable-web-security")
            chrome_options.add_argument("--incognito")
            chrome_options.add_argument("--allow-running-insecure-content")
            chrome_options.add_argument("--allow-cross-origin-auth-prompt")
            chrome_options.add_argument("--disable-cookie-encryption")
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument("--test-type")
            chrome_options.binary_location = brave_exe
            ## webdriver section
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)
            driver_name = 'brave'
        elif name == 'opera':
            from os import listdir
            from selenium.webdriver.common import desired_capabilities as operacapabilities
            from selenium.webdriver.opera import options as operaoptions
            _operaDriverLoc = self.driver_path
            # Opera browser
            _operaInstDir = self.browser_inst_dir
            listOperaDir = listdir(_operaInstDir)
            listOperaVer = [
                char for char in listOperaDir
                if char[0].isdigit() and char[-1].isdigit()
            ]
            # listOperaVer.sort(key=lambda version: [int(ver) for ver in version.split('.')])
            listOperaVer.sort()
            _operacurrentversion = listOperaVer[-1]
            _operaExeLoc = _operaInstDir + _operacurrentversion + r'\opera.exe'
            _operaCaps = operacapabilities.DesiredCapabilities.OPERA.copy()
            _operaOpts = operaoptions.ChromeOptions()
            _operaOpts._binary_location = _operaExeLoc
            driver = webdriver.Opera(executable_path=_operaDriverLoc,
                                     options=_operaOpts,
                                     desired_capabilities=_operaCaps)
            driver_name = 'opera'
            driver_version = _operacurrentversion
        elif name == "headless" or name == "nobrowser" or name == "virtual":
            # This is for running without open Browser UI display - good for Jenkins
            # # chrome_options.add_argument('--disable-extensions')
            # # chrome_options.add_argument("--disable-plugins-discovery")
            chromedriverpath = self.driver_path
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument("--disable-web-security")
            chrome_options.add_argument("--incognito")
            chrome_options.add_argument("--allow-running-insecure-content")
            chrome_options.add_argument("--allow-cross-origin-auth-prompt")
            chrome_options.add_argument("--disable-cookie-encryption")
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument("--test-type")
            chrome_options.add_argument('--disable-default-apps')
            chrome_options.add_argument('--disable-prompt-on-repost')
            chrome_options.add_argument(
                "--disable-zero-browsers-open-for-tests")
            chrome_options.add_argument("--no-default-browser-check")
            chrome_options.add_argument("--proxy-server='direct://'")
            chrome_options.add_argument("--proxy-bypass-list=*")
            prefs = {"profile.default_content_setting_values.notifications": 2}
            chrome_options.add_experimental_option("prefs", prefs)
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)
        else:
            # Set chrome driver
            # name == "chrome":
            chromedriverpath = self.driver_path
            # for timebeing ONLY -- to ease OLD CODE
            if chromedriverpath == None:
                chromedriverpath = r'C:\tools\chromedriver\chromedriver.exe'
            #os.environ["webdriver.chrome.driver"] = chromedriverpath
            chrome_options = webdriver.ChromeOptions()
            #### headless - but not working at the moment
            # chrome_options.add_argument('--headless')
            # chrome_options.add_argument('--disable-gpu')
            # chrome_options.headless = True
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument("--disable-web-security")
            chrome_options.add_argument("--incognito")
            chrome_options.add_argument("--allow-running-insecure-content")
            chrome_options.add_argument("--allow-cross-origin-auth-prompt")
            chrome_options.add_argument("--disable-cookie-encryption")
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument("--test-type")
            chrome_options.add_argument('--disable-default-apps')
            chrome_options.add_argument('--disable-prompt-on-repost')
            chrome_options.add_argument(
                "--disable-zero-browsers-open-for-tests")
            chrome_options.add_argument("--no-default-browser-check")
            prefs = {"profile.default_content_setting_values.notifications": 2}
            chrome_options.add_experimental_option("prefs", prefs)
            ## webdriver section
            driver = webdriver.Chrome(chromedriverpath, options=chrome_options)

        return driver, driver_name, driver_version
Exemple #12
0
    def getWebDriverInstance(self):
        """
        Get WebDriver Instance based on the browser configuration
        Returns:
            'WebDriver Instance'
        """

        ## strver = 'version'
        strver = 'browserVersion'

        if self.browser == "iexplorer" or self.browser == "ie" or self.browser == "IE":
            # Set IE driver
            iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x64_2.42.0.exe'
            # iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x64_3.12.0.exe' ## not working
            # iedriverserver = r'C:\tools\Python36\Scripts\IEDriverServer_x32_3.4.0.exe'  ## work but 32bit
            driver = webdriver.Ie(iedriverserver)
        elif self.browser == 'safari':   ### Safari not working at the moment
            safaridriver = r'C:\tools\Python36\Scripts\SafariDriver.exe'
            driver = webdriver.Safari(safaridriver)
        elif self.browser == 'opera':
            # OperaDriver - win64 2.36 - https://github.com/operasoftware/operachromiumdriver/releases
            _operaDriverLoc = r'C:\tools\Python36\Scripts\operadriver_win64_2.36.exe'
            # Opera browser # Version:	53.0.2907.68  # System:	Windows 7 64-bit
            _operaExeLoc = r'C:\Program Files\Opera\53.0.2907.68\opera.exe'
            from selenium.webdriver.common import desired_capabilities as operacapabilities
            from selenium.webdriver.opera import options as operaoptions
            _operaCaps = operacapabilities.DesiredCapabilities.OPERA.copy()
            _operaOpts = operaoptions.ChromeOptions()
            _operaOpts._binary_location = _operaExeLoc
            # driver = webdriver.Chrome(executable_path = _operaDriverLoc, chrome_options = _operaOpts, desired_capabilities = _operaCaps)
            driver = webdriver.Opera(executable_path = _operaDriverLoc, options = _operaOpts, desired_capabilities = _operaCaps)
        elif self.browser == "firefox" or self.browser == "ff":
            driver = webdriver.Firefox()
            #strver = 'browserVersion'
        elif self.browser == "chrome":
            # Set chrome driver
            chromedriverpath = r'C:\tools\python3\Scripts\chromedriver.exe'
            #os.environ["webdriver.chrome.driver"] = chromedriverpath
            chrome_options = webdriver.ChromeOptions()
            # chrome_options.add_argument('--disable-extensions')
            #chrome_options.add_argument('--profile-directory=Default')
            chrome_options.add_argument("--incognito")
            # chrome_options.add_argument("--disable-plugins-discovery")
            # chrome_options.add_argument("--start-maximized")
            driver = webdriver.Chrome(chromedriverpath, chrome_options=chrome_options)
            #driver.set_window_size(1440, 900)
        elif self.browser == 'phantomjs' or self.browser == 'phantom':
            ## Virtual browser 1 -- ERROR -- response = 'status': 500
            # _phantomJsLoc = r'C:\tools\phantomJS\phantomjs-2.5.0-beta2-windows\bin\phantomjs.exe'
            _phantomJsLoc = r'C:\tools\phantomJS\phantomjs-2.1.1-windows\bin\phantomjs.exe'
            driver = webdriver.PhantomJS(executable_path=_phantomJsLoc)
            # strver = 'browserVersion'
        elif self.browser == "headless":
            ## Virtual browser 2 -- OK - but have problem to login page (if page need login) - e.g. gmail
            chromedriverpath = r'C:\tools\python3\Scripts\chromedriver.exe'
            chrome_options = webdriver.ChromeOptions()
            # chrome_options.add_argument('--disable-extensions')
            chrome_options.add_argument("--incognito")
            # chrome_options.add_argument("--disable-plugins-discovery")
            # chrome_options.add_argument("--start-maximized")
            chrome_options.add_argument('--headless')
            chrome_options.add_argument("--mute-audio")
            chrome_options.add_argument("--proxy-server='direct://'")
            chrome_options.add_argument("--proxy-bypass-list=*")
            driver = webdriver.Chrome(chromedriverpath, chrome_options=chrome_options)
        elif self.browser == "nobrowser":
            ## Virtual browser 3 -- NOT OK - still open Firefox browser
            from selenium.webdriver.firefox.options import Options
            opts = Options()
            opts.set_headless()
            driver = webdriver.Firefox(options=opts)
            #strver = 'browserVersion'
        elif self.browser == 'virtual':
            ## Virtual browser 4 -- NOT OK - still open Opera browser
            # OperaDriver - win64 2.36 - https://github.com/operasoftware/operachromiumdriver/releases
            _operaDriverLoc = r'C:\tools\Python36\Scripts\operadriver_win64_2.36.exe'
            # Opera browser # Version:	53.0.2907.68  # System:	Windows 7 64-bit
            _operaExeLoc = r'C:\Program Files\Opera\53.0.2907.68\opera.exe'
            from selenium.webdriver.common import desired_capabilities as operacapabilities
            from selenium.webdriver.opera import options as operaoptions
            _operaOpts = operaoptions.ChromeOptions()
            _operaOpts.add_argument('--headless')
            _operaOpts.add_argument("--mute-audio")
            _operaOpts.add_argument("--proxy-server='direct://'")
            _operaOpts.add_argument("--proxy-bypass-list=*")
            _operaOpts._binary_location = _operaExeLoc
            _operaCaps = operacapabilities.DesiredCapabilities.OPERA.copy()
            driver = webdriver.Opera(executable_path = _operaDriverLoc, options = _operaOpts, desired_capabilities = _operaCaps)
            # driver = webdriver.Chrome(executable_path = _operaDriverLoc, chrome_options = _operaOpts, desired_capabilities = _operaCaps)
        else:
            driver = webdriver.Firefox()
            #strver = 'browserVersion'

        # Setting Driver Implicit Time out for An Element
        driver.implicitly_wait(3)

        # Maximize the window
        # driver.maximize_window()
        print('Browser version ( ' + driver.name + ' ) = ' + driver.capabilities[strver])

        return driver