本文整理汇总了Python中selenium.webdriver.chrome.options.Options.to_capabilities方法的典型用法代码示例。如果您正苦于以下问题:Python Options.to_capabilities方法的具体用法?Python Options.to_capabilities怎么用?Python Options.to_capabilities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.chrome.options.Options
的用法示例。
在下文中一共展示了Options.to_capabilities方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def setUp(self):
try:
self.log = logger.Logger.get_logger()
self.input = TestInputSingleton.input
self.servers = self.input.servers
self.browser = self.input.ui_conf['browser']
self.replica = self.input.param("replica", 1)
self.case_number = self.input.param("case_number", 0)
self.machine = self.input.ui_conf['server']
self.driver = None
self.shell = RemoteMachineShellConnection(self.machine)
#avoid clean up if the previous test has been tear down
if not self.input.param("skip_cleanup", True) \
or self.case_number == 1:
self.tearDown()
self._log_start(self)
self._kill_old_drivers()
#thread for selenium server
if not self._is_selenium_running():
self.log.info('start selenium')
self._start_selenium_thread()
self._wait_for_selenium_is_started()
self.log.info('start selenium session')
if self.browser == 'firefox':
self.log.info("firefox")
# self.driver = webdriver.Remote(desired_capabilities={
# "browserName": "firefox",
# "platform": "MAC",
# })
self.driver = webdriver.Remote(command_executor='http://{0}:{1}/wd/hub'
.format(self.machine.ip,
self.machine.port),
desired_capabilities=DesiredCapabilities.FIREFOX)
elif self.browser == 'chrome':
self.log.info("chrome")
local_capabilities = DesiredCapabilities.CHROME
chrome_options = Options()
chrome_options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
local_capabilities.update(chrome_options.to_capabilities())
self.log.info(self.machine.ip)
self.log.info(self.machine.port)
self.driver = webdriver.Remote(desired_capabilities={
"browserName": "chrome",
"platform": "MAC",
})
self.log.info('start selenium started')
self.driver.get("http://127.0.0.1:8091")
self.username = "Administrator"
self.password = "password"
self.driver.maximize_window()
except Exception as ex:
self.input.test_params["stop-on-failure"] = True
self.log.error("SETUP WAS FAILED. ALL TESTS WILL BE SKIPPED")
self.fail(ex)
示例2: add_chrome
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def add_chrome(self, key, remote=True, **desired_capabilities):
if key in self.drivers_container:
raise ValueError('Key "{}" already in {}'.format(key, self.__class__))
chrome_options = ChromeOptions()
chrome_options.add_argument('--disable-extensions')
capabilities = chrome_options.to_capabilities()
capabilities.update(desired_capabilities)
if remote:
driver = webdriver.Remote(desired_capabilities=capabilities, command_executor=self.grid_url)
else:
driver = webdriver.Chrome(desired_capabilities=capabilities)
self.drivers_container[key] = driver
示例3: create_chrome_driver
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def create_chrome_driver(host=None, port=None):
co = Options()
if host is not None and port is not None:
manifest_json = read_script('./proxy_ext/manifest.json')
background_js = read_script('./proxy_ext/background.js', host=host, port=port, user=username, password=password)
with zipfile.ZipFile(plugin_file, 'w') as zp:
zp.writestr("manifest.json", manifest_json)
zp.writestr("background.js", background_js)
co.add_extension(plugin_file)
driver = webdriver.Remote(
command_executor=diver_executable_path,
desired_capabilities=co.to_capabilities()
)
return driver
示例4: to_capabilities
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def to_capabilities(self):
"""
Creates a capabilities with all the options that have been set and
returns a dictionary with everything
"""
capabilities = ChromeOptions.to_capabilities(self)
capabilities.update(DesiredCapabilities.OPERA)
opera_options = capabilities["operaOptions"] = capabilities.pop("chromeOptions")
if self.android_package_name:
opera_options["androidPackage"] = self.android_package_name
if self.android_device_socket:
opera_options["androidDeviceSocket"] = self.android_device_socket
if self.android_command_line_file:
opera_options["androidCommandLineFile"] = self.android_command_line_file
return capabilities
示例5: add_options
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def add_options(self, chromiumlike, cache_state):
''' Sets a bunch of cmd switches and options passed to selenium'''
mode = "chromiumlike" if chromiumlike else "sparrow"
driver_options = Options()
# Field Trial
if chromiumlike:
driver_options.add_argument('--sparrow-force-fieldtrial=chromiumlike')
driver_options.add_argument('--user-agent=%s' % self.user_agent)
driver_options.add_argument('--user-data-dir=%s' % self.chromiumlike_user_data_dir)
else:
driver_options.add_argument('--sparrow-force-fieldtrial')
driver_options.add_argument('--user-data-dir=%s' % self.sparrow_user_data_dir)
for switch in self.sparrow_only_switches:
driver_options.add_argument(switch)
logging.debug("Adding switch to sparrow only: %s" % switch)
# Passed from config file
for switch in self.common_switches:
driver_options.add_argument(switch)
logging.debug("Adding switch: %s" % switch)
if self.ublock_path:
if not os.path.exists(self.ublock_path):
print("Error, ublock crx file not found.")
sys.exit(1)
driver_options.add_extension(self.ublock_path)
# Test label
test_label_entry = "--beer-test-label=%s-%s-%s-%s-%s-%s" % (self.test_label_prefix, self.chromium_version,
sys.platform, mode, cache_state, self.test_start_time)
driver_options.add_argument(test_label_entry)
logging.info(test_label_entry)
driver_options.binary_location = self.binary_location
driver_options.to_capabilities()['loggingPrefs'] = { 'browser':'ALL' }
return driver_options
示例6: decide_chrome_startup_options
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def decide_chrome_startup_options(self):
opts = Options()
opts.add_argument('--disable-extensions')
if self.protocol == 'http':
# server should be 'SpdyEnabled off'
pass
elif self.protocol == 'spdy':
# server should be 'SpdyEnabled off' and
# Chrome supports SPDY by default
if self.args.ssl is False:
# server: SpdyDebugUseSpdyForNonSslConnections 2
opts.add_argument('--use-spdy=no-ssl')
elif self.protocol == 'http-pipelining':
# server should be 'SpdyEnabled off'
opts.add_argument('--enable-http-pipelining')
else:
print "Won't reach here."
return opts.to_capabilities()
示例7: __init__
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def __init__(self, manager):
self.manager = manager
# brow2 = self.config['selenium']['browser']
browser = manager.get_property("selenium")['browser']
remote_selenium = manager.get_property("selenium")['remote_server'].encode("utf-8")
if remote_selenium == "none":
if browser == "IE":
self.driver = webdriver.Ie()
self.driver.maximize_window()
elif browser == "chrome":
options = Options();
options.add_argument("--start-maximized");
self.driver = webdriver.Chrome(chrome_options = options)
else:
self.driver = webdriver.Firefox()
self.driver.maximize_window()
else:
if browser == "IE":
caps = DesiredCapabilities.INTERNETEXPLORER
self.driver = webdriver.Remote(remote_selenium, caps)
self.driver.maximize_window()
elif browser == "chrome":
options = Options();
options.add_argument("--start-maximized");
caps = options.to_capabilities()
self.driver = webdriver.Remote(remote_selenium, caps)
else:
fp = webdriver.FirefoxProfile('ui_tests/firefox_profile_for_selenium')
caps = DesiredCapabilities.FIREFOX
self.driver = webdriver.Remote(remote_selenium, caps, browser_profile = fp)
self.driver.maximize_window()
self.driver.implicitly_wait(manager.get_property("selenium")['implicit_wait'])
if manager.get_property("test_object") == 'local_ui':
self.driver.get(manager.get_property("ui")['local_ui_url'])
elif manager.get_property("test_object") == 'lom':
self.driver.get(manager.get_property("ui")['lom_ui_url'])
else:
raise Exception ('UI under test is not specified')
示例8: test_fac
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def test_fac():
cwd = os.getcwd()
chrome_logpath = os.path.join(cwd, "browser.log")
print("CWD: %s log: %s"%(cwd, chrome_logpath))
prefs = {
"profile.default_content_settings.popups":0,
"download.prompt_for_download": "false",
"download.default_directory": cwd,
}
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
#chrome_options.add_argument("--headless")
#chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_experimental_option("prefs", prefs)
PROXY = "bbpproxy.epfl.ch:80"
webdriver.DesiredCapabilities.CHROME['proxy'] = {
"httpProxy":PROXY,
"ftpProxy":PROXY,
"sslProxy":PROXY,
"noProxy":None,
"proxyType":"MANUAL",
"class":"org.openqa.selenium.Proxy",
"autodetect":False
}
if True:
driver = webdriver.Chrome(chrome_options=chrome_options, service_args=["--verbose", "--log-path=%s"%chrome_logpath])
else:
driver = webdriver.Remote(
command_executor='http://bbpsrvc22.bbp.epfl.ch:4444/wd/hub',
#desired_capabilities=webdriver.DesiredCapabilities.CHROME)
desired_capabilities=chrome_options.to_capabilities())
driver.get("https://www.google.com/ncr")
elem = driver.find_element_by_xpath("//input[@id='lst-ib']")
elem.send_keys("blue brain project")
elem.submit()
text = driver.find_element_by_xpath("//div[@id='resultStats']").text
print(text)
driver.get("https://ufile.io/yo4y6")
time.sleep(10)
elem = driver.find_element_by_xpath("//a[@class='free-download btn btn-default btn-lg standard-button free-download-button']")
driver.execute_script("arguments[0].click();", elem)
time.sleep(10)
# Open the downloaded zip file
import glob
import zipfile
created_files = glob.glob(os.path.join(cwd, "result.zip"))
print(created_files)
assert_equal(len(created_files), 1)
created_file = created_files[0]
z = zipfile.ZipFile(created_file)
for f in z.namelist():
print(f)
示例9: get_chrome_caps
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def get_chrome_caps(browser_args):
chrome_options = Options()
if browser_args:
for arg in browser_args:
chrome_options.add_argument("--" + arg)
return chrome_options.to_capabilities()
示例10: setup_browser
# 需要导入模块: from selenium.webdriver.chrome.options import Options [as 别名]
# 或者: from selenium.webdriver.chrome.options.Options import to_capabilities [as 别名]
def setup_browser():
options = Options()
options.add_argument('--kiosk')
driver = webdriver.Chrome(desired_capabilities=options.to_capabilities())
return driver