1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
import twilltestlib
import twill
from twill import namespaces, commands
from twill.errors import TwillAssertionError
from _mechanize_dist import BrowserStateError, ClientForm
def test():
url = twilltestlib.get_url()
# test empty page get_title
namespaces.new_local_dict()
twill.commands.reset_browser()
browser = twill.get_browser()
try:
browser.get_title()
assert 0, "should never get here"
except BrowserStateError:
pass
### now test a few special cases
commands.go(url)
commands.go('/login')
commands.showforms()
# test no matching forms
try:
commands.fv('2', 'submit', '1')
assert 0
except TwillAssertionError:
pass
# test regexp match
commands.fv('1', '.*you', '1')
# test ambiguous match to value
commands.go('/testform')
commands.fv('1', 'selecttest', 'val')
commands.fv('1', 'selecttest', 'value1')
commands.fv('1', 'selecttest', 'selvalue1')
commands.formclear('1')
try:
commands.fv('1', 'selecttest', 'value')
assert 0
except ClientForm.ItemNotFoundError:
pass
# test ambiguous match to name
commands.go('/testform')
try:
commands.fv('1', 'item_', 'value')
assert 0
except Exception:
pass
try:
commands.formfile('1', 'selecttest', 'null')
assert 0
except Exception:
pass
commands.go('http://www.google.com/')
browser.get_title()
# test the twill script.
twilltestlib.execute_twill_script('test-form.twill', initial_url=url)
|