예제 #1
0
def driver_factory(browser, executor_url, test_name):
    if browser == "chrome":
        logger = logging.getLogger('chrome_fixture')
        logger.setLevel(LOG_LEVEL)
        caps = {
            "browserName": browser,
            "version": "83.0",
            "enableVnc": True,
            "enableVideo": True,
            "enableLog": True,
            "screenResolution": "1280x720",
            "name": test_name
        }
        driver = EventFiringWebDriver(
            webdriver.Remote(command_executor=executor_url + "/wd/hub",
                             desired_capabilities=caps), MyListener())
        logger.info(f"Start session {driver.session_id}")
    elif browser == "firefox":
        profile = FirefoxProfile()
        profile.accept_untrusted_certs = True
        options = FirefoxOptions()
        options.headless = True
        driver = webdriver.Firefox(options=options, firefox_profile=profile)
    else:
        raise Exception("Driver not supported")
    return driver
예제 #2
0
def driver_factory(browser, executor):
    if browser == "chrome":
        logger = logging.getLogger('chrome_fixture')
        logger.setLevel(LOG_LEVEL)
        options = ChromeOptions()
        options.headless = True
        options.add_argument('--ignore-ssl-errors=yes')
        options.add_argument('--ignore-certificate-errors')
        logger.info("Подготовка среды для запуска тестов...")
        options.add_experimental_option('w3c', False)
        driver = EventFiringWebDriver(
            webdriver.Remote(command_executor=f"http://{executor}:4444/wd/hub",
                             desired_capabilities={
                                 "browserName": browser,
                                 "platform": "WIN10",
                                 "platformName": "WIN10"
                             },
                             options=options), MyListener())
        logger.debug(
            "Браузер Chrome запущен со следующими desired_capabilities:{}".
            format(driver.desired_capabilities))
    elif browser == "firefox":
        profile = FirefoxProfile()
        profile.accept_untrusted_certs = True
        options = FirefoxOptions()
        options.headless = True
        driver = webdriver.Firefox(options=options, firefox_profile=profile)
    else:
        raise Exception("Driver not supported")
    return driver
예제 #3
0
def driver_factory(browser):
    if browser == "chrome":
        logger = logging.getLogger('chrome_fixture')
        logger.setLevel(LOG_LEVEL)
        options = ChromeOptions()
        options.headless = True
        options.add_argument('--ignore-ssl-errors=yes')
        options.add_argument('--ignore-certificate-errors')
        logger.info("Подготовка среды для запуска тестов...")
        caps = DesiredCapabilities.CHROME
        caps['loggingPrefs'] = {'performance': 'ALL', 'browser': 'ALL'}
        options.add_experimental_option('w3c', False)
        driver = EventFiringWebDriver(
            webdriver.Chrome(desired_capabilities=caps, options=options),
            MyListener())
        logger.debug(
            "Браузер Chrome запущен со следующими desired_capabilities:{}".
            format(driver.desired_capabilities))
    elif browser == "firefox":
        profile = FirefoxProfile()
        profile.accept_untrusted_certs = True
        options = FirefoxOptions()
        options.headless = True
        driver = webdriver.Firefox(options=options, firefox_profile=profile)
    else:
        raise Exception("Driver not supported")
    return driver
예제 #4
0
def browser(request):
    """
    initialize the selenium test case
    """
    global driver

    profile = FirefoxProfile()
    profile.accept_untrusted_certs = True
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", DOWNLOAD_DIR)
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")

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

    driver = Firefox(firefox_profile=profile, capabilities=capabilities,
                     executable_path=os.getenv("FIREFOX_DRIVER_EXEC_PATH", "/usr/local/bin/geckodriver"))

    driver.implicitly_wait(10)
    driver.maximize_window()
    request.addfinalizer(lambda *args: driver.quit())

    yield driver

    time.sleep(5)
    def generate_firefox_profile(
        self: "SeleniumTestability",
        preferences: OptionalDictType = None,
        accept_untrusted_certs: bool = False,
        proxy: OptionalStrType = None,
    ) -> FirefoxProfile:
        """
        Generates a firefox profile that sets up few required preferences for SeleniumTestability to support all necessary features.
        Parameters:
        - ``preferences`` - firefox profile preferences in dictionary format.
        - ``accept_untrusted_certs`` should we accept untrusted/self-signed certificates.
        - ``proxy`` proxy options

        Note: If you opt out using this keyword, you are not able to get logs with ``Get Logs`` and Firefox.
        """
        profile = FirefoxProfile()
        if preferences:
            for key, value in preferences.items():  # type: ignore
                profile.set_preference(key, value)

        profile.set_preference("devtools.console.stdout.content", True)

        profile.accept_untrusted_certs = accept_untrusted_certs

        if proxy:
            profile.set_proxy(proxy)

        profile.update_preferences()
        return profile
예제 #6
0
    def __init__(self, url, usuario, senha):
        # Configurar o navegador
        profile = FirefoxProfile()
        profile.set_preference("browser.download.panel.shown", False)
        profile.set_preference("browser.download.folderList", 2)
        profile.set_preference("browser.download.manager.showWhenStarting", False)
        profile.set_preference("browser.download.dir", DIRETORIO)
        profile.set_preference(
            "browser.helperApps.neverAsk.saveToDisk",
            "text/plain, application/octet-stream, application/binary,\
                               text/csv, application/csv, application/excel, text/comma-separated-values,\
                                   text/xml, application/xml",
        )
        profile.accept_untrusted_certs = True

        # # Instanciar o navegar firefox e inserir as configurações
        browser = Remote(
            # command_executor= 'http://127.0.0.1:4444/wd/hub',
            desired_capabilities=DesiredCapabilities.FIREFOX,
            browser_profile=profile,
        )
        # browser = Firefox(profile)  # Utilizar para teste locais

        # Maximizar a tela do navegador
        browser.maximize_window()

        # Inserir os atributos para classe pai com uma instancia do navegador
        super().__init__(url, usuario, senha, browser)
예제 #7
0
 def launch_application(browser_name, app_url):
     global driver
     log.info("in init method of selenium base")
     try:
         if browser_name == "chrome":
             option = ChromeOptions()
             option.add_argument("start-maximized")
             option.add_argument("--ignore-certificate-errors")
             option.add_argument("--disable-extensions")
             option.add_argument("--disable-infobars")
             option.add_argument("disable-notifications")
             driver = Chrome(executable_path="./drivers/chromedriver.exe",
                             options=option)
             log.info("chrome browser is launch successfully")
         elif browser_name == "firefox":
             profile = FirefoxProfile()
             profile.accept_untrusted_certs = True
             options = FirefoxOptions()
             options.add_argument("start-maximized")
             driver = Firefox(executable_path="./drivers/geckodriver.exe")
             log.info("firefox browser is launch successfully")
         elif browser_name == "ie":
             driver = Ie(executable_path="./drivers/IEDriverServer.exe")
         else:
             log.error("browser name is incorrect", browser_name)
     except WebDriverException:
         log.critical("exception", WebDriverException)
     driver.implicitly_wait(5)
     driver.get(app_url)
예제 #8
0
def test_profiles_do_not_share_preferences():
    profile1 = FirefoxProfile()
    profile1.accept_untrusted_certs = False
    profile2 = FirefoxProfile()
    # Default is true. Should remain so.
    assert profile2.default_preferences[
        "webdriver_accept_untrusted_certs"] is True
    def create_options(self):
        super().debug_begin()

        options = FirefoxOptions()

        options.add_argument("--start-maximized")

        if super()._language is not None:
            options.add_argument("--lang=" + super()._language)

        if super()._headless:
            options.add_argument("-headless")
            options.add_argument("--disable-gpu")

        profile = FirefoxProfile()
        profile.accept_untrusted_certs = True

        for file_name in self.__plugin_files:
            if '\\.' not in file_name:
                file_name += '.xpi'
            profile.add_extension(os.getcwd() + '/' + file_name)

        options.profile = profile

        if super()._use_proxy:
            # options.add_argument('--ignore-certificate-errors')
            pass

        super().debug_end()

        return options
예제 #10
0
파일: krtest.py 프로젝트: untapt/kryptonic
 def _buildFirefoxDriver(self, headless=False):
     profile = FirefoxProfile()
     profile.accept_untrusted_certs = True
     profile.headless = headless
     profile.set_preference('security.fileuri.strict_origin_policy', False)
     o = Options()
     o.set_headless(self.config_options['headless'])
     return KrFirefox(firefox_profile=profile, options=o)
예제 #11
0
 def __call__(self, config, args):
     profile = FirefoxProfile()
     if config.user_agent:
         profile.set_preference("general.useragent.override",
                                config.user_agent)
     if config.ignore_ssl:
         profile.accept_untrusted_certs = True
     args["firefox_profile"] = profile
     args["capabilities"] = args["desired_capabilities"]
     args.pop("desired_capabilities")
     return args
예제 #12
0
 def setProxy(self, proxy):
     profile = FirefoxProfile()
     profile.accept_untrusted_certs = True
     profile.assume_untrusted_cert_issuer = True
     prefix = "network.proxy."
     profile.set_preference("%stype" % prefix, 1)
     for type in ["http", "ssl", "ftp", "socks"]:
         profile.set_preference("%s%s" % (prefix, type), proxy.getHost())
         profile.set_preference("%s%s_port" % (prefix, type),
                                int(proxy.getPort()))
     return profile
예제 #13
0
 def __call__(self, config, args):
     profile = FirefoxProfile()
     if config.user_agent:
         profile.set_preference("general.useragent.override",
                                config.user_agent)
     if config.ignore_ssl:
         profile.accept_untrusted_certs = True
     args["firefox_profile"] = profile
     args["capabilities"] = args["desired_capabilities"]
     args.pop("desired_capabilities")
     return args
예제 #14
0
def start_firefox(proxy=None, user_agent=None):
    p = FirefoxProfile("E://profiles")
    p.accept_untrusted_certs = True
    if user_agent:
        p.set_preference("general.useragent.override", user_agent)
    capabilities = DesiredCapabilities().FIREFOX.copy()
    capabilities['acceptInsecureCerts'] = True

    if proxy:
        p.set_proxy(proxy)
    browser = Firefox(firefox_profile=p, capabilities=capabilities)
    return browser
예제 #15
0
def browser(request):
    """
    initialize the selenium test case
    """
    global driver

    headless_testing = os.environ.get("HEADLESS_TESTING", False)

    profile = FirefoxProfile()
    profile.accept_untrusted_certs = True
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", DOWNLOAD_DIR)
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
                           "text/csv")

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

    opts = Options()
    opts.log.level = "trace"

    if headless_testing:
        display = Display(visible=0, size=(1920, 1080))
        display.start()
        time.sleep(3)

        driver = Firefox(firefox_profile=profile,
                         options=opts,
                         capabilities=capabilities,
                         executable_path=os.getenv(
                             "FIREFOX_DRIVER_EXEC_PATH",
                             "/usr/local/bin/geckodriver"))
        driver.set_window_size(1654, 859)

    else:
        driver = Firefox(firefox_profile=profile,
                         options=opts,
                         capabilities=capabilities,
                         executable_path=os.getenv(
                             "FIREFOX_DRIVER_EXEC_PATH",
                             "/usr/local/bin/geckodriver"))
        driver.maximize_window()

    driver.implicitly_wait(20)
    driver.maximize_window()
    request.addfinalizer(lambda *args: driver.quit())

    yield driver

    time.sleep(5)
예제 #16
0
def driver_factory(browser):
    if browser == "chrome":
        options = ChromeOptions()
        options.headless = True
        options.add_argument('--ignore-ssl-errors=yes')
        options.add_argument('--ignore-certificate-errors')
        driver = webdriver.Chrome(options=options)
    elif browser == "firefox":
        profile = FirefoxProfile()
        profile.accept_untrusted_certs = True
        options = FirefoxOptions()
        options.headless = True
        driver = webdriver.Firefox(options=options, firefox_profile=profile)
    else:
        raise Exception("Driver not supported")
    return driver
예제 #17
0
    def __init__(self, *args, **kwargs):
        super(DemoSpider, self).__init__(*args, **kwargs)

        profile = FirefoxProfile()
        profile.set_preference("network.proxy.type", 1)
        profile.set_preference("network.proxy.http", CRAWLERA_HEADLESS_PROXY)
        profile.set_preference("network.proxy.http_port", CRAWLERA_HEADLESS_PORT)
        profile.set_preference("network.proxy.ssl", CRAWLERA_HEADLESS_PROXY)
        profile.set_preference("network.proxy.ssl_port", CRAWLERA_HEADLESS_PORT)
        profile.accept_untrusted_certs = True

        options = webdriver.FirefoxOptions()
        options.add_argument("--window-size 1920,1080")
        options.add_argument("--headless")
        # Required to run the browser inside the docker (as root)
        options.add_argument("--no-sandbox")
        self.driver = webdriver.Firefox(options=options, firefox_profile=profile)
예제 #18
0
def test_profiles_do_not_share_preferences():
    profile1 = FirefoxProfile()
    profile1.accept_untrusted_certs = False
    profile2 = FirefoxProfile()
    # Default is true. Should remain so.
    assert profile2.default_preferences["webdriver_accept_untrusted_certs"] is True
예제 #19
0
import os
import time

from selenium import webdriver
from selenium.webdriver import Proxy, FirefoxProfile
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as firefox_options

p = Proxy()
p.http_proxy = "1.1.1.1"

fp = FirefoxProfile()
fp.accept_untrusted_certs = True
fp.assume_untrusted_cert_issuer = False
# fp.set_proxy(proxy)

chrome_options = Options()
firefox_options = firefox_options()
firefox_options.headless = True
chrome_options.headless = False

# driver = webdriver.firefox(executable_path=os.getcwd() + os.path.sep + "geckodriver_mac")
driver = webdriver.Chrome(options=chrome_options, executable_path=os.getcwd() + os.path.sep + "chromedriver_2.45")
driver.implicitly_wait(30)
driver.maximize_window()
driver.get("https://www.google.com")
print(driver.title)
driver.find_element_by_name("q").send_keys("ramnath gokul", Keys.SHIFT)
driver.find_element_by_name("q").send_keys(Keys.ENTER)
# driver.find_element_by_name("btnK").click()