Date: Thu, 13 Apr 2006 15:02:55 +1000
From: Stephen Thorne <ste...@netboxblue.com>
To: ti...@idyll.org
Cc: "Do, Uy N" <Uy...@reyrey.com>, tw...@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 with
>-> 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 didn't
>-> 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 personally.
>
>Does anyone else have any thoughts?
Most of my AJAXy stuff is stuff like:
function doStuff() {
var d = loadJSONDoc('/some/explicit/path?' +
queryString(getElement('myform')));
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 away.
[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
--
Regards,
Stephen Thorne
Development Engineer
Scanned by the NetBox from NetBox Blue
(http://netboxblue.com/)
----- End forwarded message -----
--
C. Titus Brown, c...@msu.edu
Subject: RE: [twill] Twill and JavaScript
Date: Thu, 13 Apr 2006 18:01:38 -0400
From: "Do, Uy N" <Uy...@reyrey.com>
To: Stephen Thorne <ste...@netboxblue.com>, ti...@idyll.org
Cc: tw...@lists.idyll.org
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?
Uy
X-Original-To: ti...@caltech.edu
From: Stephen Thorne <ste...@thorne.id.au>
To: D...@its.caltech.edu, Uy N <uy...@reyrey.com>,
Stephen Thorne <ste...@netboxblue.com>, ti...@idyll.org
Date: Fri, 14 Apr 2006 18:04:49 +1000
X-Mailer: Divmod-Quotient/0.9.2+build 184
Cc: tw...@lists.idyll.org
Subject: Re: [twill] Twill and JavaScript
On Thu, 13 Apr 2006 18:01:38 -0400, "Do, Uy N" <uy...@reyrey.com> wrote:
>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?
No, all I'm proposing is a way of submitting a form to an arbitary url.
You would be implementing the functionality done in __doPostBack() yourself, not running javascript code.
It's a sub-optimal solution, but this would enable me to sit down and write tests for much of the dynamic content I have, leaving the javascript as the only untested portion - I can quite easily sit down and do that manually.
I may implement some of this after easter.
Stephen.
_______________________________________________
twill mailing list
tw...@lists.idyll.org
http://lists.idyll.org/listinfo/twill