Package: zc.wsgidriver
WSGI+Webdriver for testing Javascript (and optionally WSGI) UIsThis package provides some helpers for testing Javascript (and
optionally WSGI) applications using Python, Selenium Webdriver,
Manuel, and WSGI.The package provides the following functions:setUp(test, app)a doctestsetUpfunction that:Sets up a webdriver, available as abrowservariable.By default, a Chrome browser driver is used.  You can override this
in two ways:Define a driver in aSELENIUM_DRIVERenvironment variable,
orIn your test script, call the functionget_factory_argumentto parse arguments for a-boption, typically before
calling whatever logic normally parses arguments.The value of this option is a driver definition.The function definition:get_factory_argument(argv=sys.argv,option='-b')Parse arguments for a browser definition.A driver definition can be one of the driver names,chromefirefox,ie,opera, orphantomjs.  It can also be
a remote driver specification.  A remote driver specification is
of the form:browserName,version,platform,command_executorFor example:internet explorer,10,Windows 8Items on the right can be omitted.  In the example above, we’ve
left off the command executor.  If the command executor isn’t
provided as part of the option, it must be provided via theSELENIUM_REMOTE_COMMAND_EXECUTORenvironment variable.Note that to use firefox as a remote browser without specifying
anything else, you’ll need to supply a trailing comma to prevent
it from being treated as a name.Sets up a server to serve a WSGI application.Sets up 2 flavors of Javascript doctest examples:js>examplesfor evaluating Javascript expressions in the browser.IMPORTANT NOTEThis should only be used with expressions.  Using with
multiple statements is likely to produce errors or strange
results. This works by simply taking the source provides,
jamming areturnon the front of it and calling the
Webdriverexecute_scriptmethod.js!examplesfor executing Javascript code in the browser without returning
anything.  This works find with blocks of code.  The source
given is passed to the Webdriverexecute_scriptmethod.IMPORTANT NOTEFunctions defined in the source usingfunctionstatements
aren’t in the Javascript global scope.  To define global
functions, use something like:global_name = function () {...}You can also execute Javascript code from Python examples using
the Webdriver (browser)execute_scriptmethod.  When
invoking Javascript this way, be aware of the following oddities:Functions defined viafunctionstatements can be used within
the block of code, but aren’t global.  To define a global
function, assign an anonymous function to a global variable.No value is returned unless the block of code includes a return
statement.Includes thewaitfunctionfrom zope.testing.waitthat
waits for a condition.The function takes an additional argument (after the test argument),
namedappthat provides a WSGI application object.start_server(app, port=0, daemon=True)A function that can be used to run the test server without running tests.Arguments:appA WSGI application objectportThe port to listen on. If 0, the default, then the port is
allocated dynamically and returned.daemonThe daemon mode.  This can beTrue,False, orNone.IfNone, then the server is run in the foreground and blocks
the caller.IfTrueorFalse, the server is run in a thread, whose
daemon mode is set to the value of this parameter.html(css=(),scripts=(),title="test",body="<body></body>")Return an HTML page with CSS links, script tags, and the given
title and body tags.This is handy when you want a mostly empty HTML page that loads
Javascript to be tested.cssAn iterable of CSS URLs.scriptsAn iterable of script definitions.Each definition is one of:script URLscript tag (starting wth ‘<’)script Javascript source (containing at least one newline
character)titleThe contents of the page titlebodyThe body of the document.manuels(optionflags=0, checker=None)Return amanuelparser for Python, Javascript and capture.TestSuite(*tests,**options)A function that takes one or more doctest/manuel file names
and Test flags, such assetUp,tearDown,optionflags,
andchecker, and returns a doctest test suite.You can pass anappkeyword argument, rather than passingsetUpandtearDown.See the example test included with the package.Changes0.1.0 (2013-08-31)Initial release