def opera_path(self):
        opera_binary_file_path = path.abspath(
            "C:\\Users\\User\\AppData\\Local\\Programs\\Opera\\77.0.4054.203\\opera.exe"
        )
        webdriver_opera_path = OperaDriverManager().install()

        return opera_binary_file_path, webdriver_opera_path
Example #2
0
def get_driver(browser):
    """Get the webdriver specified in configuration"""

    # Browser name aliases
    chrome = ('chrome', 'google', 'google chrome', 'googlechrome',
              'google-chrome', 'google_chrome')
    firefox = ('firefox', 'ff', 'mozilla', 'gecko', 'geckodriver', 'fire fox',
               'fire_fox', 'fire-fox')
    opera = ('opera', 'opera gx', 'operagx', 'opera_gx', 'opera-gx')
    explorer = ('explorer', 'ie', 'internet explorer', 'internet-explorer',
                'internet_explorer')
    edge = ('edge', 'microsoft edge', 'microsoft_edge', 'microsoft-edge')

    # Download browser binaries according to settings.json
    if browser.lower() in chrome:
        return webdriver.Chrome(ChromeDriverManager().install())

    elif browser.lower() in firefox:
        return webdriver.Firefox(
            executable_path=GeckoDriverManager().install())

    elif browser.lower() in opera:
        return webdriver.Opera(OperaDriverManager().install())

    elif browser.lower() in explorer:
        return webdriver.Ie(IEDriverManager().install())

    elif browser.lower() in edge:
        return webdriver.Edge(
            executable_path=EdgeChromiumDriverManager().install())

    else:
        raise RuntimeError('Browser not found {}'.format(browser.lower()))
def browser(request):
    browser = request.config.getoption("--browser")

    if browser.lower() == 'chrome':
        driver = webdriver.Chrome(ChromeDriverManager().install())

    elif browser.lower() == 'firefox':
        driver = webdriver.Firefox(executable_path=GeckoDriverManager(
            cache_valid_range=0).install())
    elif browser.lower() == 'internet explorer':
        driver = webdriver.Ie(IEDriverManager().install())
    elif browser.lower() == 'edge':
        driver = webdriver.Edge(EdgeChromiumDriverManager().install())
    elif browser.lower() == 'opera':
        driver = webdriver.Opera(
            executable_path=OperaDriverManager().install())
    else:
        print("Browser Error. Please select a correct browser type")
        sys.exit(0)
    driver.implicitly_wait(10)
    driver.maximize_window()

    def kill_browser():
        print(">>> conftest fixture teardown: chrome (scope:module)")
        driver.save_screenshot("report/last_screenshot.png")
        print("closing")
        driver.close()
        print("<<< conftest fixture teardown: chrome (scope:module)")

    request.addfinalizer(kill_browser)
    return driver
Example #4
0
    def launch_browser(self):
        '''Launch browser and create a session'''
        if self.browser == 'firefox':
            options = FirefoxOptions()
        else:
            options = ChromeOptions()

        if self.headless:
            options.add_argument('--headless')

        if self.options:
            for option in self.options:
                options.add_argument(option)

        window_size = '--window-size={},{}'.format(self.window_width,
                                                   self.window_height)
        options.add_argument(window_size)

        if self.browser == 'firefox':
            self.session = webdriver.Firefox(
                executable_path=GeckoDriverManager().install(),
                firefox_options=options)
        elif self.browser == 'opera':
            self.session = webdriver.Opera(
                executable_path=OperaDriverManager().install(),
                options=options)
        else:
            self.session = webdriver.Chrome(ChromeDriverManager().install(),
                                            chrome_options=options)
    def get_driver():
        driver = None
        operation_system = platform.system()
        arch = platform.architecture()
        if BROWSER == 'chrome':
            options = Options()
            if os.getenv('HEADLESS', 'false').lower() == 'true':
                options.headless = True
            options.add_argument("--window-size=1920,1080")
            options.add_experimental_option('w3c', False)
            driver = webdriver.Chrome(ChromeDriverManager().install())
        if BROWSER == 'chromium':
            driver = webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
        if BROWSER == 'opera':
            driver = webdriver.Opera(executable_path=OperaDriverManager().install())

        elif BROWSER == 'firefox':
            if operation_system == "Darwin" or "Linux":
                driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
            else:
                if arch[0] == "32bit":
                    driver = webdriver.Firefox(executable_path=GeckoDriverManager(os_type="win32").install())
                elif arch[0] == "64bit":
                    driver = webdriver.Firefox(executable_path=GeckoDriverManager(os_type="win64").install())
        elif BROWSER == 'safari':
            driver = webdriver.Safari(executable_path='/usr/bin/safaridriver')
        elif BROWSER == 'ie':
            if arch[0] == "32bit":
                driver = webdriver.Ie(executable_path=IEDriverManager(os_type="Win32").install())
            elif arch[0] == "64bit":
                driver = webdriver.Ie(executable_path=IEDriverManager(os_type="x64").install())
        return Driver.add_driver_settings(driver)
Example #6
0
def get_webdriver():
    """Get whatever webdriver is availiable in the system.
    webdriver_manager and selenium are currently being used for this.
    Supported browsers:[Firefox, Chrome, Opera, Microsoft Edge, Internet Expolorer]
    Returns:
            a webdriver that can be used for scraping. Returns None if we don't find a supported webdriver.

    """
    try:
        driver = webdriver.Firefox(
            executable_path=GeckoDriverManager().install())
    except Exception:
        try:
            driver = webdriver.Chrome(ChromeDriverManager().install())
        except Exception:
            try:
                driver = webdriver.Ie(IEDriverManager().install())
            except Exception:
                try:
                    driver = webdriver.Opera(
                        executable_path=OperaDriverManager().install())
                except Exception:
                    try:
                        driver = webdriver.Edge(
                            EdgeChromiumDriverManager().install())
                    except Exception:
                        driver = None
                        logging.error(
                            "Your browser is not supported. Must have one of the following installed to scrape: [Firefox, Chrome, Opera, Microsoft Edge, Internet Expolorer]"
                        )

    return driver
    def _init_driver(self):
        """
        Initialize the correct web driver based on the users requested browser

        :return: None
        """

        if self.browser.lower() in VALID_CHROME_STRINGS:
            if self.is_ci_build:
                self.options = self._build_ci_options_chrome()
            self.driver = webdriver.Chrome(ChromeDriverManager().install(),
                                           options=self.options)
        elif self.browser.lower() in VALID_CHROMIUM_STRINGS:
            self.driver = webdriver.Chrome(
                ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
        elif self.browser.lower() in VALID_EDGE_STRINGS:
            self.driver = webdriver.Edge(EdgeChromiumDriverManager().install())
        elif self.browser.lower() in VALID_FIREFOX_STRINGS:
            self.driver = webdriver.Firefox(
                executable_path=GeckoDriverManager().install())
        elif self.browser.lower() in VALID_OPERA_STRINGS:
            self.driver = webdriver.Opera(
                executable_path=OperaDriverManager().install())
        elif self.browser.lower() in VALID_INTERNET_EXPLORER_STRINGS:
            self.driver = webdriver.Ie(IEDriverManager().install())
        else:
            raise ValueError("No matching browser found")

        # Maximize the browser
        self.driver.maximize_window()
def setup(browser):
    if browser == 'chrome':
        driver = webdriver.Chrome()
        print("Launching Chrome Browser")
        driver.implicitly_wait(5)
        driver.maximize_window()
    elif browser == 'firefox':
        driver = webdriver.Firefox(
            executable_path=GeckoDriverManager().install())
        # driver = webdriver.Firefox()
        print("Launching Firefox Browser")
    elif browser == 'opera':
        driver = webdriver.Opera(
            executable_path=OperaDriverManager().install())
        # driver = webdriver.Firefox()
        print("Launching Opera Browser")
    elif browser == 'edge':
        driver = webdriver.Edge(EdgeChromiumDriverManager().install())
        # driver = webdriver.Firefox()
        print("Launching Edge Browser")
    elif browser == 'ie':
        driver = webdriver.Ie(IEDriverManager().install())
        # driver = webdriver.Firefox()
        print("Launching IE Browser")
    else:
        driver = webdriver.Chrome()
        print("Launching Chrome Browser")
        driver.implicitly_wait(5)
        driver.maximize_window()

    return driver
Example #9
0
def test_opera_driver_manager_with_wrong_version():
    with pytest.raises(ValueError) as ex:
        driver_path = OperaDriverManager("0.2").install()
        ff = webdriver.Opera(executable_path=driver_path)
        ff.quit()
    assert "There is no such driver by url " \
           "https://api.github.com/repos/operasoftware/operachromiumdriver/" \
           "releases/tags/0.2" in ex.value.args[0]
Example #10
0
 def opera():
     if OperaConfig.command_executor != "" and OperaConfig.command_executor[:
                                                                            4] == "http":
         return webdriver.Remote(
             command_executor=OperaConfig.command_executor,
             desired_capabilities=DesiredCapabilities.OPERA.copy())
     ep = OperaConfig.command_executor if OperaConfig.command_executor != "" else OperaDriverManager(
     ).install()
     return webdriver.Opera(executable_path=ep)
 def get_engine(self, browser):
     engine = None
     if browser == "chrome" or browser == "yandex":
         engine = webdriver.Chrome(ChromeDriverManager().install())
     if browser == "opera":
         engine = webdriver.Opera(OperaDriverManager().install())
     if browser == "firefox":
         engine = webdriver.Firefox(executable_path='geckodriver.exe')
     #engine.set_window_size(1080, 720)
     return engine
Example #12
0
def get_driver(browser=Browser.CHROME):

    if browser == 'chrome':
        return webdriver.Chrome(ChromeDriverManager().install())
    if browser == 'chromium':
        return webdriver.Chrome(
            ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
    if browser == 'firefox':
        return webdriver.Firefox(
            executable_path=GeckoDriverManager().install())
    if browser == 'opera':
        return webdriver.Edge(EdgeChromiumDriverManager().install())
    if browser == 'edge':
        return webdriver.Opera(executable_path=OperaDriverManager().install())
Example #13
0
    def create_driver(self, **kwargs):
        """Create Opera webdriver

        :type kwargs: dict
        :param kwargs: Optional arguments
        :rtype: selenium.webdriver.Opera
        :returns: Opera webdriver instance
        """

        cache_timeout = kwargs.get("cache_valid_range", 7)

        driver_path = OperaDriverManager(
            cache_valid_range=cache_timeout).install()

        return webdriver.Opera(executable_path=driver_path, **kwargs)
Example #14
0
def setUp(context, browser):
    global driver
    global main_page
    if 'ie' in browser.lower():
        driver = webdriver.Ie(IEDriverManager().install())
    elif 'firefox' in browser.lower():
        driver = webdriver.Firefox(
            executable_path=GeckoDriverManager().install())
    elif 'opera' in browser.lower():
        driver = webdriver.Opera(
            executable_path=OperaDriverManager().install())
    else:
        driver = webdriver.Chrome(ChromeDriverManager().install())
    driver.implicitly_wait(5)
    driver.get("https://stonepayments.typeform.com/to/yl5PKW")
    main_page = page.MainPage(driver)
    pass
Example #15
0
 def open_app(self):
     if self.target is Browser.CHROME:
         self.driver = webdriver.Chrome(ChromeDriverManager().install())
     elif self.target is Browser.FIREFOX:
         self.driver = webdriver.Firefox(
             executable_path=GeckoDriverManager().install())
     elif self.target is Browser.INTERNET_EXPLORER:
         self.driver = webdriver.Ie(IEDriverManager().install())
     elif self.target is Browser.EDGE:
         self.driver = webdriver.Edge(EdgeChromiumDriverManager().install())
     elif self.target is Browser.OPERA:
         self.driver = webdriver.Opera(
             executable_path=OperaDriverManager().install())
     elif self.target is Browser.SAFARI:
         self.driver = webdriver.Safari()
     self.url(self.capabilities['url'])
     self._resize_screen()
Example #16
0
 def launch_url(self, browser):
     driver = None
     browser_lower = browser.lower()  #lower() is a methodwhch
     if browser_lower == "chrome":
         driver = webdriver.Chrome(ChromeDriverManager().install())
     elif browser_lower == "firefox":
         driver = webdriver.Firefox(
             executable_path=GeckoDriverManager().install())
     elif browser_lower == "ie":
         driver = webdriver.Ie(IEDriverManager().install())
     elif browser_lower == "opera":
         driver = webdriver.Opera(
             executable_path=OperaDriverManager().install())
     elif browser_lower == "edge":
         driver = webdriver.Edge(EdgeChromiumDriverManager().install())
     driver.get(config.url)
     driver.maximize_window()
     return driver
Example #17
0
def build_opera(version: str, browser_options: List[str],
                experimental_options: Optional[List[dict]],
                extension_paths: Optional[List[str]]) -> WebDriver:
    """ Build an OperaDriver.

    Args:
        version: The desired version of Opera.
        browser_options: The list of options/arguments to include.
        experimental_options: The list of experimental options to include.
        extension_paths: The list of extensions to add to the browser.

    Examples:
        driver = WebDriverFactory().build_opera('latest', ['--start-maximized'], None)
    """
    options = build_options(Browser.OPERA, browser_options,
                            experimental_options, extension_paths)
    return webdriver.Opera(
        executable_path=OperaDriverManager(version=version).install(),
        options=options)
Example #18
0
    def _init_driver(self):
        """
        Initialize the correct web driver based on the users requested browser

        :return: None
        """

        if self.browser.lower() in VALID_CHROME_STRINGS:
            if self.is_ci_build:
                self.options = self._build_ci_options_chrome()

            self.driver = webdriver.Chrome(ChromeDriverManager().install(),
                                           options=self.options)
        elif self.browser.lower() in VALID_CHROMIUM_STRINGS:
            self.driver = webdriver.Chrome(
                ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
        elif self.browser.lower() in VALID_EDGE_STRINGS:
            self.driver = webdriver.Edge(EdgeChromiumDriverManager().install())
        elif self.browser.lower() in VALID_FIREFOX_STRINGS:
            self.driver = webdriver.Firefox(
                executable_path=GeckoDriverManager().install())
        elif self.browser.lower() in VALID_OPERA_STRINGS:
            self.driver = webdriver.Opera(
                executable_path=OperaDriverManager().install())
        elif self.browser.lower() in VALID_INTERNET_EXPLORER_STRINGS:
            self.driver = webdriver.Ie(IEDriverManager().install())
        else:
            raise ValueError("No matching browser found")

        # Get around captcha
        self.driver.execute_cdp_cmd(
            "Page.addScriptToEvaluateOnNewDocument",
            {
                "source":
                "const newProto = navigator.__proto__;"
                "delete newProto.webdriver;"
                "navigator.__proto__ = newProto;"
            },
        )
        # Maximize the browser
        self.driver.maximize_window()
Example #19
0
def test_operadriver_manager_with_selenium():
    driver_path = OperaDriverManager().install()
    options = webdriver.ChromeOptions()
    options.add_argument('allow-elevated-browser')

    if get_os_type() in ["win64", "win32"]:
        paths = [f for f in glob.glob(f"C:/Users/{os.getlogin()}/AppData/" \
                                      "Local/Programs/Opera/**",
                                      recursive=True)]
        for path in paths:
            if os.path.isfile(path) and path.endswith("opera.exe"):
                options.binary_location = path
    elif ((get_os_type() in ["linux64", "linux32"])
          and not os.path.exists('/usr/bin/opera')):
        options.binary_location = "/usr/bin/opera"
    elif get_os_type() in "mac64":
        options.binary_location = "/Applications/Opera.app/Contents/MacOS/Opera"

    ff = webdriver.Opera(executable_path=driver_path, options=options)
    ff.get("http://automation-remarks.com")
    ff.quit()
def update():
    try:
        path = ChromeDriverManager().install()
        print("Downloaded Chrome driver into:", path)
        ConfigModule.add_config_value("Selenium_driver_paths", "chrome_path",
                                      path, location)
    except:
        print(sys.exc_info())

    try:
        path = GeckoDriverManager().install()
        print("Downloaded Firefox driver into:", path)
        ConfigModule.add_config_value("Selenium_driver_paths", "firefox_path",
                                      path, location)
    except:
        print(sys.exc_info())

    try:
        path = EdgeChromiumDriverManager().install()
        print("Downloaded Edge driver into:", path)
        ConfigModule.add_config_value("Selenium_driver_paths", "edge_path",
                                      path, location)
    except:
        print(sys.exc_info())

    try:
        path = OperaDriverManager().install()
        print("Downloaded Opera driver into:", path)
        ConfigModule.add_config_value("Selenium_driver_paths", "opera_path",
                                      path, location)
    except:
        print(sys.exc_info())

    try:
        path = IEDriverManager().install()
        print("Downloaded Internet Explorer driver into:", path)
        ConfigModule.add_config_value("Selenium_driver_paths", "ie_path", path,
                                      location)
    except:
        print(sys.exc_info())
def test_operadriver_manager_with_selenium():
    driver_path = OperaDriverManager().install()
    options = webdriver.ChromeOptions()
    options.add_argument('allow-elevated-browser')

    if get_os_type() == "win64" or "win32":
        paths = [
            f for f in glob.glob("C:\\Users\\{0}\\AppData\\Local"
                                 "\\Programs\\Opera\\".format(os.getlogin()) +
                                 "/**",
                                 recursive=True)
        ]
        for path in paths:
            if os.path.isfile(path) and path.endswith("opera.exe"):
                options.binary_location = path
    elif ((get_os_type() == "linux64" or "linux32" or "mac64")
          and not os.path.exists('/usr/bin/opera')):
        options.binary_location = "/usr/bin/opera"

    ff = webdriver.Opera(executable_path=driver_path, options=options)
    ff.get("http://automation-remarks.com")
    ff.quit()
def opera():
    """
    Return the latest instance of Opera Web Driver object.

    :return: Latest Opera webdriver instance
    """
    options = webdriver.ChromeOptions()
    options.add_argument('allow-elevated-browser')
    if get_os_type() == "win64" or "win32":
        paths = [f for f in glob.glob("C:\\Users\\{0}\\AppData\\Local"
                                      "\\Programs\\Opera\\"
                                      .format(os.getlogin()) + "/**",
                                      recursive=True)]
        for path in paths:
            if os.path.isfile(path) and path.endswith("opera.exe"):
                options.binary_location = path
                break
    elif ((get_os_type() == "linux64" or "linux32" or "mac64") and not
    os.path.exists('/usr/bin/opera')):
        options.binary_location = "/usr/bin/opera"
    return webdriver.Opera(executable_path=OperaDriverManager(
        DRIVER_VERSIONS.get('edge', 'latest')).install(), options=options)
Example #23
0
def install_driver(browser=None):
    """
    Download and install the browser driver

    :param browser: The Driver to download. Pass as `chrome/firefox/ie/edge/opera`. Default Chrome.
    :return:
    """

    if browser is None:
        browser = "chrome"

    if browser == "chrome":
        ChromeDriverManager().install()
    elif browser == "firefox":
        GeckoDriverManager().install()
    elif browser == "ie":
        IEDriverManager().install()
    elif browser == "edge":
        EdgeChromiumDriverManager().install()
    elif browser == "opera":
        OperaDriverManager().install()
    else:
        raise NameError(f"Not found '{browser}' browser driver.")
Example #24
0
    def load_driver(self, capabilities):
        ''' This method will load and return the driver. It depends on the capability of the test, for example it references the browser name
            in the capability file. '''
        if capabilities['browserName'] == Browsers.CHROME:
            driver = webdriver.Chrome(ChromeDriverManager().install())
        elif capabilities['browserName'] == Browsers.CHROMIUM:
            driver = webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
        elif capabilities['browserName'] == Browsers.FIREFOX:
            driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
        elif capabilities['browserName'] == Browsers.IE:
            driver = webdriver.Ie(IEDriverManager().install())
        elif capabilities['browserName'] == Browsers.EDGE:
            driver = webdriver.Edge(EdgeChromiumDriverManager().install())
        elif capabilities['browserName'] == Browsers.OPERA:
            # If opera is not installed in its default directory, this may throw an exception, workaround is on the pip site.
            driver = webdriver.Opera(executable_path=OperaDriverManager().install())
        else:
            raise Exception('Unable to identify browser to load driver, check your capability file contains the correct value for browser name.')

        # If we set the max window to default we will automatically set the browser window to maximise on driver load
        if self.max_window_default is True:
            driver.maximize_window()

        return driver
Example #25
0
        lambda opts: webdriver.Chrome(
            ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install(),
            options=opts,
        ),
        supported.firefox:
        lambda opts: webdriver.Firefox(
            executable_path=GeckoDriverManager().install(),
            options=opts,
        ),
        supported.ie:
        lambda opts: webdriver.Ie(
            IEDriverManager().install(),
            options=opts,
        ),
        supported.edge:
        lambda ____: webdriver.Edge(EdgeChromiumDriverManager().install(), ),
        supported.opera:
        lambda opts: webdriver.Opera(
            executable_path=OperaDriverManager().install(),
            options=opts,
        ),
    }


def local(
    name: supported.
    BrowserName = 'chrome',  # todo: consider change default to ... and then get it from options if passed
    options: WebDriverOptions = None
) -> WebDriver:
    return installers[name](options)
def test_can_get_driver_from_cache(os_type):
    OperaDriverManager(os_type=os_type).install()
    driver_path = OperaDriverManager(os_type=os_type).install()
    assert os.path.exists(driver_path)
def test_opera_driver_manager_with_correct_version_and_token(path):
    driver_path = OperaDriverManager(version="v.2.45", path=path).install()
    assert os.path.exists(driver_path)
def test_opera_driver_manager_with_correct_version():
    driver_path = OperaDriverManager("v.2.45").install()
    assert os.path.exists(driver_path)
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.firefox import GeckoDriverManager
from webdriver_manager.opera import OperaDriverManager

browserName = "chrome"

if browserName == "chrome":
    driver = webdriver.Chrome(ChromeDriverManager().install())
elif browserName == "firefox":
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
elif browserName == "safari":
    driver = webdriver.Safari()
elif browserName == "opera":
    driver = webdriver.Opera(executable_path=OperaDriverManager().install())
else:
    print("Please pass the corect browser name:" + browserName)

driver.implicitly_wait(5)
driver.get("https://app.hubspot.com/login")
driver.find_element_by_id('username').send_keys("*****@*****.**")
driver.find_element_by_id('password').send_keys("Test@123")
driver.find_element_by_id('loginBtn').click()

print(driver.title)

time.sleep(4)
driver.quit()
def __get_opera():
    opera_driver = webdriver.Opera(
        executable_path=OperaDriverManager().install())
    return opera_driver