Usage
The testgen-convert script takes three parameters passed on the command line:
testgen-convert [test type] [test method] [TestGen4Web session XML file]
The currently supported test types are the following:
- twill-shell [test method] - Use the twill mechanize wrapper
- zope-testbrowser [test method] - Use the zope.testbrowser mechanize wrapper (zope.testbrowser can be used from standalone, downloadable package or from a Zope 2.9.X, or higher, Zope install)
- mechanize [test method] - Use mechanize
The currently supported test methods are the following:
- [test type] code - Print to stdout the executable code for the given test type
- [test type] doctest - Print to stdout doctests suitable for inclusion in a python docstring
- [test type] run - Run a unittest for the given test type
Some notes about support:
- code mode only works for twill and zope.testbrowser right now
- doctest only works for zope.testbrowser
- run only works for mechanize and zope.testbrowser
Examples
Here is an example usage of using the parser to generate twill commands (executed from the testgen sandbox directory):
$ testgen-convert twill-shell code ZenUITests/tests/TestGen4Web/testLoginLogout.xml
debug commands 1
go http://localhost:8080/zport/dmd/
title "Zenoss Login"
formvalue loginform __ac_name "admin"
formvalue loginform __ac_password "admin"
formvalue loginform None "Submit"
submit
title "Zenoss: dmd"
follow "Logout"
title "Zenoss Login"
Entering the output twill commands into a running twill-sh will result in a login, page check and then a log out, just as expected.
Similarly, you can produce zope.testbrowser output suitable for running in a script or python interpreter:
$ testgen-convert zope-testbrowser code ZenUITests/tests/TestGen4Web/testLoginLogout.xml
from zope.testbrowser.browser import Browser
browser = Browser()
browser.open("http://localhost:8080/zport/dmd/")
browser.title == "Zenoss Login"
form = browser.getForm(name="loginform")
field = form.getControl(name="__ac_name")
field.value = "admin"
form = browser.getForm(name="loginform")
field = form.getControl(name="__ac_password")
field.value = "admin"
form = browser.getForm(name="loginform")
form.submit("Submit")
browser.title == "Zenoss: dmd"
link = browser.getLink("Logout")
link.click()
browser.title == "Zenoss Login"
as well as output for use in docttest:
$ testgen-convert zope-testbrowser doctest ZenUITests/tests/TestGen4Web/testLoginLogout.xml doctest
>>> from zope.testbrowser.browser import Browser
>>> browser = Browser()
>>> browser.open("http://localhost:8080/zport/dmd/")
>>> browser.title == "Zenoss Login"
True
>>> form = browser.getForm(name="loginform")
>>> field = form.getControl(name="__ac_name")
>>> field.value = "admin"
>>> form = browser.getForm(name="loginform")
>>> field = form.getControl(name="__ac_password")
>>> field.value = "admin"
>>> form = browser.getForm(name="loginform")
>>> form.submit("Submit")
>>> browser.title == "Zenoss: dmd"
True
>>> link = browser.getLink("Logout")
>>> link.click()
>>> browser.title == "Zenoss Login"
True
So far, these examples don't actually test anything; they are simply parsing TestGen4Web XML data and rendering it in various formats.
To run as a unit test, you can do the following:
$ testgen-convert zope-testbrowser run ZenUITests/tests/TestGen4Web/testLoginLogout.xml
Step 1: opening URL http://localhost:8080/zport/dmd/ ...
Step 2: verifying title as 'Zenoss Login' ...
Step 3: filling form 'loginform' with __ac_name=admin ...
Step 4: filling form 'loginform' with __ac_password=admin ...
Step 5: clicking 'Submit' on form 'loginform' ...
Step 6: verifying title as 'Zenoss: dmd' ...
Step 7: clicking link 'Logout' ...
Step 8: verifying title as 'Zenoss Login' ...
.
----------------------------------------------------------------------
Ran 1 test in 1.718s
OK