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__)

    client.click(id=u'viewNavCenterRight')
    client.waits.sleep(milliseconds=2000)
    client.doubleClick(id=u'hourDiv1-1200')
    client.waits.sleep(milliseconds=2000)
    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')
    client.radio(id=u'startMeridianAM')
    client.radio(id=u'endMeridianPM')
    client.select(id=u'eventStatus', option=u'Tentative')
    client.type(text=u'A description for the properties test', id=u'noteDescription')
    if client.execJS(js='1 == 0')['output']:
        pass
    if client.execJS(js=''lookupNode({id: 'a_node_id'}).innerHTML")['output'] == "some test":
       pass
    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__)

    client.click(id=u'email')
    client.type(text=functest.registry['email'], id=u'email')
    client.type(text=functest.registry['password'], id=u'pass')
    client.click(value=u"Login")
    client.waits.forPageLoad(timeout=u'60000')

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 http://www.facebook.com email=abc123@slide.com password=something