[twill] Twill and JavaScript

Do, Uy N Uy_Do at reyrey.com
Thu Apr 13 15:01:38 PDT 2006

Hi Stephen,
Thanks for your response, though I'm not quite sure how to implement the
Jason_submit function. I think Titus will handle it?
Actually, I have a test scenario like this:
Given on a page that has <a href="__doPostBack(...);">text that need
postback event</a>. 
Can I use Jason_submit to perform the call to __doPostBack? 


-----Original Message-----
From: Stephen Thorne [mailto:stephen at netboxblue.com] 
Sent: Thursday, April 13, 2006 12:03 AM
To: titus at idyll.org
Cc: Do, Uy N; twill at lists.idyll.org
Subject: Re: [twill] Twill and JavaScript

Titus Brown wrote:
> On Wed, Apr 12, 2006 at 01:59:11PM -0400, Do, Uy N wrote:
> -> I know Twill doesn't support JavaScript for now. 
> -> However, is there any way to overcome that? Like integrate Twill
> -> some other tools, etc so that we still can write twill test with
> -> javascript enabled websites?
> -> I checked IanBlocking's Twill with Javascript demo but it seemed
> -> do much.
> I don't have any good ideas on this front ;(.   I do have ideas on how
> to explicitly test the functionality *behind* AJAX-y sites, but I
> haven't had a chance to play around with any such sites yet
> Does anyone else have any thoughts?

Most of my AJAXy stuff is stuff like:

function doStuff() {
var d = loadJSONDoc('/some/explicit/path?' + 
d.addCallback(function (response) {
   replaceChildNodes('message', response.message);
   replaceChildNodes('sometable', map(show_row, response.some_data));

If you don't know mochikit, that code basically does

- Browser asks for /some/explicit/path?all=form&fields=here
- Server responds with "{mesasge:'foo'}"
- Browser does some variant of: response = eval("{message:'foo'}"); and 
passes that to the anonymous function.
- Browser puts response.message into the DOM

What it should be possible to do is grab json.py[1] and use that as a 
JSON parser, and that would allow us to do some form of test in twill 
along the lines of:

follow "Some Link"
formvalue myform myfield myvalue
json_submit myform "/some/explicit/path"

but how to inspect the return value, I have no idea, if I were writing 
this in python (as I've documented how to use twill and py.test recently

[2]), I would write:

def test_ajaxy_stuff():
   web.follow('Some Link')
   web.formvalue('myform', 'myfield', 'myvalue')
   web.json_submit('myform', '/some/explicit/path')
   respones = web.get_browser().parse_json()
   assert 'foo' in response.message
   for line in response.some_data:
     assert len(line) == 6
     assert ininstance(line[2], int)
     assert line[3] in ('success', 'failure')

As a datapoint, we don't have any expicit twill scripts in our test 
suite anymore. We just have some legacy pbpscript ones that are going

[1] http://divmod.org/trac/browser/trunk/Nevow/nevow/json.py?rev=5554
[2] http://shiny.thorne.id.au/shiny/2006/04/twill-and-pytest.html
Stephen Thorne
Development Engineer

Scanned by the NetBox from NetBox Blue

More information about the twill mailing list