Python Tests

jaycee edited this page Oct 24, 2010 · 9 revisions

Windmill provides an implementation of the controller that is used for windmill tests using functest.

# Generated by the windmill services transformer
from windmill.authoring import WindmillTestClient

def test():
    client = WindmillTestClient(__name__)'viewNavCenterRight')
    client.type(text=u'Properties Test', id=u'noteTitle')
    client.type(text=u'9:00', id=u'startTime')
    client.type(text=u'4:00', id=u'endTime')'startMeridianAM')'endMeridianPM')'eventStatus', option=u'Tentative')
    client.type(text=u'A description for the properties test', id=u'noteDescription')
    if client.execJS(js='1 == 0')['output']:
    if client.execJS(js=''lookupNode({id: 'a_node_id'}).innerHTML")['output'] == "some test":
    client.keyPress(id=u'some_id', options='a,true,false,false,false,false')

By default WindmillTestClient will throw an assertion whenever a test has a failed result. This triggers a failure for that test method in functest.

You can turn off these assertions and do the assertion yourself. This is useful if you want to assert that a test failed.

from windmill.authoring import WindmillTestClient

def test():
    client = WindmillTestClient(__name__, assertions=False)

    client.waits.forElement(xpath=u'html/body/center/p/font', timeout=u'3000')
    assert not client.asserts.assertValue(validator=u'Google Search', name=u'btnG')['result']

Notice that the object returned from client.waits.forElement is not a simple boolean, it’s actually the entire result object returned from the windmill IDE. It includes the starttime, endtime, and other debugging information about the test call.

Passing Variables from the command line

Anything passed to windmill that isn’t a used argument is stuck into the functest registry, which you can then access from within Python inside your tests.

from windmill.authoring import WindmillTestClient
import functest

def setup_module(module):
    client = WindmillTestClient(__name__)'email')
    client.type(text=functest.registry['email'], id=u'email')
    client.type(text=functest.registry['password'], id=u'pass')"Login")

functest.registry['email'] corresponds to the command line parameter you are passing in and will be substituted for the value when the test is run.

Example test run of the above:
windmill firefox password=something