本文整理汇总了Python中twill.get_browser函数的典型用法代码示例。如果您正苦于以下问题:Python get_browser函数的具体用法?Python get_browser怎么用?Python get_browser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_browser函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle_exception
def handle_exception(msg, e):
maybe_print_stack()
log_error("Caught exception at %s" %
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
html = twill.get_browser().get_html()
if options.dump_file == '-':
print html
else:
dump_file_name = os.path.expanduser(options.dump_file)
try:
if html is not None:
if options.show_error_in_browser:
# If we are showing it in the browser, lets get the
# paths right (even if if means changing the HTML a
# little)
base_href = '\n<!-- added by flunc: --><base href="%s">' % twill.get_browser().get_url()
match = re.search('<head.*?>', html, re.I|re.S)
if match:
html = html[:match.end()] + base_href + html[match.end():]
else:
html = base_href + html
f = open(dump_file_name, 'wb')
f.write(html)
f.close()
log_info("saved error html to: %s" % dump_file_name)
except IOError, e:
log_warn("Unable to save error HTML to: %s" % dump_file_name)
开发者ID:SMFOSS,项目名称:flunc,代码行数:28,代码来源:flunc.py
示例2: test_middleware_composer
def test_middleware_composer():
"""Middleware stack should alter return in order.."""
def make_middleware(txt):
def middleware(app):
def wrappedapp(environ, start_response):
res = app(environ, start_response)
res.append(txt)
return res
return wrappedapp
return middleware
# Environ predicates
t = lambda x: True
f = lambda x: False
rules = [(t, make_middleware('a')),
(f, make_middleware('b')),
(t, make_middleware('c')),
(f, make_middleware('d')),
(t, make_middleware('e'))]
def app(environ, start_response):
start_response("200 OK", [('Content-type', 'text/plain')])
return ["ok "]
composed = selector.MiddlewareComposer(app, rules)
twill.add_wsgi_intercept('simple-host', 80, lambda: composed)
browser = twill.get_browser()
browser.go('http://simple-host/endpoint')
assert browser.result.page.startswith("ok eca")
assert browser.result.http_code == 200
开发者ID:cdent,项目名称:selector,代码行数:31,代码来源:test_middleware_composer.py
示例3: main
def main():
login, password = get_credentials()
# log-in to Django site
if login and password:
tw.go(LOGIN_URL)
tw.formvalue('1', 'username', login)
tw.formvalue('1', 'password', password)
tw.submit()
if isinstance(DATA_URL, basestring):
urls = [DATA_URL]
else:
urls = list(DATA_URL)
# retrieve URIs
for url in urls:
try:
tw.go(url)
tw.code('200')
tw.show()
except TwillAssertionError:
code = get_browser().get_code()
print (u"Unable to access %(url)s. "
u"Received HTTP #%(code)s."
% {'url': url, 'code': code})
tw.reset_browser()
开发者ID:yeleman,项目名称:red_nut,代码行数:28,代码来源:refresh_cache.py
示例4: fv_multi_match
def fv_multi_match(formname, regexp, *values):
"""
>> fv_multi_match <formname> <field regexp> <value> [<value> [<value>..]]
Set value of each consecutive matching form field with the next specified
value. If there are no more values, use the last for all remaining form
fields
"""
state = twill.get_browser()
form = state.get_form(formname)
if form is None:
print(('no such form', formname))
return
regexp = re.compile(regexp)
matches = [ ctl for ctl in form.inputs if regexp.search(str(ctl.get("name"))) ]
if matches:
print(('-- matches %d, values %d' % (len(matches), len(values))))
n = 0
for control in matches:
state.clicked(form, control)
if 'readonly' in list(control.attrib.keys()):
continue
try:
twill.utils.set_form_control_value(control, values[n])
except IndexError as e:
twill.utils.set_form_control_value(control, values[-1])
n += 1
print(('set %d values total' % (n,)))
开发者ID:alexandre,项目名称:twill,代码行数:34,代码来源:formfill.py
示例5: has_multiple_values
def has_multiple_values(formname, name):
browser = twill.get_browser()
form = browser.get_form(formname)
if not form:
raise TwillAssertionError("no matching forms!")
control = browser.get_form_field(form, name)
return hasattr(control, 'items') and len(control.items) > 1
开发者ID:SMFOSS,项目名称:flunc,代码行数:7,代码来源:checkbox.py
示例6: _formvalue_by_regexp_setall
def _formvalue_by_regexp_setall(formname, fieldname, value):
state = twill.get_browser()
form = state.get_form(formname)
if not form:
logger.error('no such form %s', formname)
return
regexp = re.compile(fieldname)
matches = [ ctl for ctl in form.controls if regexp.search(str(ctl.name)) ]
if matches:
logger.error('-- matches %d', len(matches))
n = 0
for control in matches:
state.clicked(form, control)
if control.readonly:
continue
n += 1
twill.utils.set_form_control_value(control, value)
logger.error('set %d values total', n)
开发者ID:brandizzi,项目名称:retwill,代码行数:25,代码来源:mailman_sf.py
示例7: __init__
def __init__(self):
Web2UnitTest.__init__(self)
self.b = get_browser()
self.b_data = StringIO()
set_output(self.b_data)
self.clearRecord()
# This string must exist in the URL for it to be followed
# Useful to avoid going to linked sites
self.homeURL = self.url
# Link used to identify a URL to a ticket
self.url_ticket = "/admin/default/ticket/"
# Tuple of strings that if in the URL will be ignored
# Useful to avoid dynamic URLs that trigger the same functionality
self.include_ignore = ("_language=",
"logout",
"appadmin",
"admin",
"delete",
)
# tuple of strings that should be removed from the URL before storing
# Typically this will be some variables passed in via the URL
self.strip_url = ("?_next=",
)
self.reportOnly = False
self.maxDepth = 16 # sanity check
self.setThreshold(10)
self.setUser("[email protected]/eden")
self.total_visited = 0
self.broken_links_count = 0
开发者ID:AyudaEcuador,项目名称:eden,代码行数:29,代码来源:broken_links.py
示例8: test_not_found
def test_not_found():
"""The "not found" handler return a 404."""
twill.add_wsgi_intercept('not-found-host', 80, lambda: not_found)
browser = twill.get_browser()
browser.go('http://not-found-host/')
assert browser.result.page.startswith("404 Not Found")
assert browser.result.http_code == 404
开发者ID:cdent,项目名称:selector,代码行数:7,代码来源:test_default_handlers.py
示例9: make_intranets
def make_intranets(intranets_name):
""" Make the offices root hierarchy, deleting if it exists"""
global_dict, local_dict = namespaces.get_twill_glocals()
global_dict['intranets_name'] = intranets_name
# Check to see if we have that community, if so, delete it.
commands.go('/' + intranets_name)
br = get_browser()
status = br.get_code()
if status != 404:
# The community shouldn't exist, and so we should get 404
# looking for it. If no 404, then it exists and we should
# delete it.
url = "/%s/delete.html?confirm=1" % intranets_name
commands.go(url)
# Now, make the community and make sure it exists
commands.go("/add_community.html")
commands.fv("save", "title", intranets_name)
desc = "Test intranets root created for Twill test case named '%s'"
commands.fv("save", "description", desc % test_name)
commands.submit()
commands.find("Add Existing")
开发者ID:Falmarri,项目名称:karl,代码行数:25,代码来源:twillcommands.py
示例10: main
def main():
joker = SpawnKillerThread()
try:
SpawnDistributedCluster()
print "Waiting for two JBoss instances to start up in cluster mode..."
time.sleep(10)
joker.start()
#commands.debug('http', 1)
#commands.debug('commands',1)
b = get_browser()
import socket
myip = "http://" + socket.gethostbyname(socket.gethostname())
b.go(myip + "/session-basket")
b.submit(5)
wordBatch = listOfRandomWords()
for idx, w in enumerate(wordBatch):
print "Adding word %d: '%s' to the list..." % (idx, w)
commands.formvalue("1", "newItem:j_idt11", w)
b.submit(4)
commands.code(200)
commands.find(w)
time.sleep(0.25)
print wordBatch, len(wordBatch)
b.submit(5)
commands.code(200)
commands.reload()
for w in wordBatch:
commands.find(w)
finally:
joker.stopKilling = True
joker.join()
KillJBoss(0)
KillJBoss(1)
开发者ID:mperdikeas,项目名称:tools,代码行数:33,代码来源:test-cluster-deployment-of-session-baskets.py
示例11: __init__
def __init__(self):
self.twill_browser = twill.get_browser()
if not settings.get('verbose', True):
twill.set_output(open(os.devnull, 'w'))
#twill.browser.OUT = open(os.devnull, 'w')
# Handle HTTP authentication
if settings.get('http_auth_username', None) and settings.get('http_auth_password', None):
base64string = base64.encodestring('%s:%s' % (settings['http_auth_username'], settings['http_auth_password'])).replace('\n', '')
twill.commands.add_auth("wiki", settings['mediawiki_url'], settings['http_auth_username'], settings['http_auth_password'])
#self.twill_browser._session.headers.update([("Authorization", "Basic %s" % base64string)])
twill.commands.add_extra_header("Authorization", "Basic %s" % base64string)
# Handle Mediawiki authentication
if settings.get('mediawiki_username', None) and settings.get('mediawiki_password', None):
login_url = urlparse.urljoin(settings['mediawiki_url'], '/index.php?title=Special:UserLogin')
self.openurl(login_url)
self._set_form_value('userlogin', 'wpName', settings.get('mediawiki_username'))
self._set_form_value('userlogin', 'wpPassword', settings.get('mediawiki_password'))
self.twill_browser.submit()
self.openurl(settings['mediawiki_url'])
开发者ID:sniku,项目名称:mediawiki_client,代码行数:25,代码来源:wiki_client.py
示例12: test_Mongodb
def test_Mongodb(self):
print "This is a test to check that the api endpoints are working properly."
# time.sleep(30)
browser = twill.get_browser()
browser.go("http://localhost:27017/")
self.assertTrue(browser.get_code() in (200, 201))
开发者ID:wd15,项目名称:corr,代码行数:7,代码来源:test_mongodb.py
示例13: fv_match
def fv_match(formname, regexp, value):
"""
>> fv_match <formname> <field regexp> <value>
Set value of *all* form fields with a name that matches the given
regular expression.
(Unlike 'formvalue' or 'fv', this will not complain about multiple
matches!)
"""
state = twill.get_browser()
form = state.get_form(formname)
if form is None:
print(('no such form', formname))
return
regexp = re.compile(regexp)
matches = [ ctl for ctl in form.inputs if regexp.search(str(ctl.get("name"))) ]
if matches:
print(('-- matches %d' % (len(matches),)))
n = 0
for control in matches:
state.clicked(form, control)
if 'readonly' in list(control.attrib.keys()):
continue
n += 1
twill.utils.set_form_control_value(control, value)
print(('set %d values total' % (n,)))
开发者ID:alexandre,项目名称:twill,代码行数:34,代码来源:formfill.py
示例14: setAgent
def setAgent(self, agentAcronym):
# Decide on the agent that will be used to power the smoke test
if agentAcronym == "g":
self.agent = "Ghost"
try:
from ghost import Ghost
self.ghost = Ghost(wait_timeout = 360)
except ImportError:
raise NameError("Ghost not installed")
from using_ghost import login, visit
else:
self.agent = "Twill"
try:
from twill import get_browser
from twill import set_output
except ImportError:
raise NameError("Twill not installed")
try:
import mechanize
except ImportError:
raise NameError("Mechanize not installed")
self.b = get_browser()
self.b_data = StringIO()
set_output(self.b_data)
from using_twill import login, visit
self.visit = MethodType(visit, self)
self.login = MethodType(login, self)
开发者ID:arnavsharma93,项目名称:eden,代码行数:33,代码来源:broken_links.py
示例15: fv_match
def fv_match(formname, regexp, value):
"""
>> fv_match <formname> <field regexp> <value>
Set value of *all* form fields with a name that matches the given
regular expression.
(Unlike 'formvalue' or 'fv', this will not complain about multiple
matches!)
"""
state = twill.get_browser()
form = state.get_form(formname)
if not form:
logger.error("no such form %s", formname)
return
regexp = re.compile(regexp)
matches = [ctl for ctl in form.controls if regexp.search(str(ctl.name))]
if matches:
logger.info("-- matches %d", len(matches))
n = 0
for control in matches:
state.clicked(form, control)
if control.readonly:
continue
n += 1
twill.utils.set_form_control_value(control, value)
logger.info("set %d values total", n)
开发者ID:brandizzi,项目名称:retwill,代码行数:34,代码来源:formfill.py
示例16: test_Api
def test_Api(self):
print "This is a test to check that the api endpoints are working properly."
# assert self.app.config['MONGODB_SETTINGS'] == {'db': 'corr-integrate', 'host': '127.0.0.1', 'port': 27017}
browser = twill.get_browser()
browser.go("http://0.0.0.0:%d/api/v1/project0/"%self.app.config['LIVESERVER_PORT'])
self.assertTrue(browser.get_code() in (401, 404))
开发者ID:gitter-badger,项目名称:corr,代码行数:7,代码来源:test_backend.py
示例17: fv_multi_match
def fv_multi_match(formname, regexp, *values):
"""
>> fv_multi_match <formname> <field regexp> <value> [<value> [<value>..]]
Set value of each consecutive matching form field with the next specified
value. If there are no more values, use the last for all remaining form
fields
"""
state = twill.get_browser()
form = state.get_form(formname)
if not form:
logger.error("no such form", formname)
return
regexp = re.compile(regexp)
matches = [ctl for ctl in form.controls if regexp.search(str(ctl.name))]
if matches:
logger.info("-- matches %d, values %d", len(matches), len(values))
n = 0
for control in matches:
state.clicked(form, control)
if control.readonly:
continue
try:
twill.utils.set_form_control_value(control, values[n])
except IndexError, e:
twill.utils.set_form_control_value(control, values[-1])
n += 1
logger.info("set %d values total", n)
开发者ID:brandizzi,项目名称:retwill,代码行数:34,代码来源:formfill.py
示例18: __init__
def __init__(self):
Web2UnitTest.__init__(self)
self.b = get_browser()
self.b_data = StringIO()
set_output(self.b_data)
# list of links that return a http_code other than 200
# with the key being the URL and the value the http code
self.brokenLinks = dict()
# List of links visited (key) with the depth
self.urlList = dict()
# List of urls for each model
self.model_url = dict()
# This string must exist in the URL for it to be followed
# Useful to avoid going to linked sites
self.homeURL = self.url
# Tuple of strings that if in the URL will be ignored
# Useful to avoid dynamic URLs that trigger the same functionality
self.include_ignore = ("_language=",
"/admin/default/",
)
# tuple of strings that should be removed from the URL before storing
# Typically this will be some variables passed in via the URL
self.strip_url = ("?_next=",
)
self.maxDepth = 2 # sanity check
开发者ID:msbongabong,项目名称:eden,代码行数:26,代码来源:broken_links.py
示例19: __init__
def __init__(self, app, host='127.0.0.1', port=5000, scheme='http'):
self.app = app
self.host = host
self.port = port
self.scheme = scheme
self.browser = twill.get_browser()
开发者ID:gperetin,项目名称:flask-testing,代码行数:7,代码来源:testing.py
示例20: catalog_find
def catalog_find(searchterm, urlfrag, notfind=False):
"""Just like Twill find, but issues a searchpage-search search"""
global_dict, local_dict = namespaces.get_twill_glocals()
# This will navigate us away from the place the Twill script is
# sitting. Thus, stash away to the current URL, then navigate
# back to that URL after searching.
br = get_browser()
start_url = br.get_url()
esc_searchterm = urllib.quote(searchterm)
url = "/searchresults.html?body=" + esc_searchterm
commands.go(url)
# Now do the test. With the fragment of the URL that was
# provided, we can do a double-check, to make sure the
# searchresults provide that.
if notfind:
commands.notfind(urlfrag)
else:
commands.find(urlfrag)
# Finally, send them back to the original URL.
commands.go(start_url)
开发者ID:Falmarri,项目名称:karl,代码行数:25,代码来源:twillcommands.py
注:本文中的twill.get_browser函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论