Exemplo n.º 1
0
 def _create_IE_options(api_obj):
     options = IEOptions()
     args = set()
     #not recommended, ensure correct security settings in IE
     args.add(IEOptions.IGNORE_PROTECTED_MODE_SETTINGS)
     args.add(IEOptions.ENSURE_CLEAN_SESSION)
     args.add(IEOptions.IGNORE_ZOOM_LEVEL)
     args.add(IEOptions.REQUIRE_WINDOW_FOCUS)
     args.add(IEOptions.PERSISTENT_HOVER)
     if api_obj.browser_options_args:
         args.update(api_obj.browser_options_args)
     for arg in args:
         if arg:
             options.add_argument(arg)
     if api_obj.http_proxy:
         proxy = {
             'proxyType': "manual",
             'httpProxy': str(api_obj.http_proxy)
         }
         options.set_capability("proxy", proxy)
     options.set_capability(IEOptions.NATIVE_EVENTS, False)
     if api_obj.browser_options_dict:
         for k, v in api_obj.browser_options_dict.items():
             options.set_capability(k, v)
     return options
def test_ie_compatibility_session():
    options = IEOptions()
    options.attach_to_edge_chrome = True
    options.edge_executable_path = "/path/to/edge/browser"
    driver = webdriver.Ie(options=options)

    driver.quit()
Exemplo n.º 3
0
    def get_webdriver_instance(self):
        """
        返回webdriver实例
        """
        if self.browser == 'chrome':
            if self.headless is True:
                chrome_option = ChromeOptions()
                chrome_option.add_argument('--headless')
                driver = webdriver.Chrome(executable_path=chrome_driver_path,
                                          chrome_options=chrome_option)
            else:
                driver = webdriver.Chrome(executable_path=chrome_driver_path)

        elif self.browser == 'firefox':
            if self.headless is True:
                firefox_options = FirefoxOptions()
                firefox_options.set_headless()
                driver = webdriver.Firefox(options=firefox_options,
                                           executable_path=firfox_driver_path)
            else:
                driver = webdriver.Firefox(executable_path=firfox_driver_path)

        elif self.browser == 'remote_firefox':
            driver = webdriver.Remote(command_executor='http://' + '1' +
                                      ':4444/wd/hub',
                                      desired_capabilities={
                                          'browserName': 'firefox',
                                          'javascriptEnabled': True,
                                      })

        elif self.browser == 'remote_chrome':
            driver = webdriver.Remote(command_executor='http://' + '2' +
                                      ':4444/wd/hub',
                                      desired_capabilities={
                                          'browserName': 'chrome',
                                          'javascriptEnabled': True,
                                      })
        elif self.browser == 'ie':
            ie_options = IEOptions()
            driver = webdriver.Ie(ie_options=ie_options,
                                  executable_path=ie_driver_path)
        elif self.browser == 'edge':
            driver = webdriver.Edge()
        elif self.browser == 'safari':
            driver = webdriver.Safari()
        else:
            driver = None

        if self.browser not in [
                'chrome', 'firefox', 'remote_firefox', 'remote_chrome', 'ie',
                'edge', 'safari'
        ]:
            log.info('Driver "%s" is not defined' % self.browser)
        else:
            log.info('Driver is set as for browser "%s". Headless is %s' %
                     (self.browser, self.headless))
        driver.maximize_window()
        driver.implicitly_wait(5)
        driver.set_page_load_timeout(load_page_timeout)
        return driver
Exemplo n.º 4
0
def x_driver_options_config():
    # determine driver preference in Core Preferences and set headless option accordingly, then return option object
    # here then fetch returned option object in the class function 'fetch_headless_config' that returns options for
    # use in x_driver init_x_driver
    if selena_preferences['x_driver'] == "chrome":
        options = ChromeOptions()
        options.add_argument('--headless')
        options.headless = True
        options.add_argument("window-size=1200x600")
        options.add_argument('--disable-gpu')
        return options
    elif selena_preferences['x_driver'] == "gecko":
        options = FirefoxOptions()
        options.headless = True
        return options
    elif selena_preferences['x_driver'] == "opera":
        options = OperaOptions()
        options.headless = True
        options.add_argument("window-size=1200x600")
        options.add_argument('--disable-gpu')
        return options
    elif selena_preferences['x_driver'] == "msedge":
        options = EdgeOptions()
        options.headless = True
        options.use_chromium = True
        return options
    elif selena_preferences['x_driver'] == "ie":
        options = IEOptions()
        return options
Exemplo n.º 5
0
def driver(request):
    browser = request.config.getoption("--browser")
    if browser == "firefox":
        firefox_options = FirefoxOptions()
        firefox_options.add_argument("-headless")
        execute_path = DRIVER_PATH + "geckodriver.exe"
        wd = webdriver.Firefox(options=firefox_options, executable_path=execute_path)
    elif browser == "chrome":
        chrome_options = ChromeOptions()
        chrome_options.add_argument("--headless")
        execute_path = DRIVER_PATH + "chromedriver.exe"
        wd = webdriver.Chrome(options=chrome_options, executable_path=execute_path)
    else:
        ie_options = IEOptions()
        wd = webdriver.Ie()
    wd.maximize_window()
    yield wd
    wd.quit()
Exemplo n.º 6
0
def ie(context):
    # -- FIXTURE SETUP
    try:
        ie_options = IEOptions()

        if should_use_headless(context):
            print("WARNING: Headless execution is NOT supported by IE!")
            print("Ignoring headless flag and continuing execution with IE in full UI mode.")

        # Launch IE browser with Selenium.
        driver = webdriver.Ie(ie_options=ie_options)

        # Store reference to Selenium wrapper in Scenario Context so all step definitions & page objects can use it.
        context.selenium = SeleniumWrapper(context, driver)
        yield context.selenium
    except WebDriverException as e:
        print("Selenium WebDriverException raised when initializing IE!")
        raise e
    # -- FIXTURE CLEANUP
    context.selenium.driver.quit()
def test_ie_session():
    options = IEOptions()
    driver = webdriver.Ie(options=options)

    driver.quit()