[Seaside] SmallHttpUnitTest
C. David Shaffer
cdshaffer at acm.org
Tue Oct 19 20:21:55 CEST 2004
Roger,
Looks interesting. I have also developed a testing framework
(SeasideTesting) but with a somewhat different philosophy...basically
tight integration with Seaside. Here's a sample unit test for WACounter:
testBack
self newApplicationWithRootClass: WACounter.
self establishSession.
self followAnchor: (self lastResponse anchorWithLabel: '++').
self followAnchor: (self lastResponse anchorWithLabel: '++').
self assert: self component count = 2.
self back.
self followAnchor: (self lastResponse anchorWithLabel: '++').
self assert: self component count = 2
Notice that the idea here is that I test the state of the component
directly (although I can also ask questions about the content of the web
page). This goes back to the thread we had on testing in this newsgroup
a while back. I'm not recommending it as a replacement for
SmallHttpUnit (or HttpUnit, for that mater) but if you're more
interested in state of components than in the display then it might be
of interest. My framework also includes a web-based test runner which
shows you the history of views encountered during the test run. I've
found it useful on occasion.
You can find the original release of SeasideTesting on SqueakMap. I
haven't ported it to VW due to differences in the XML processing
frameworks. The port is on my list but will take longer than I planned.
David
Roger Whitney wrote:
> A while back there was some discussion about a building a Smalltalk
> framework for testing web pages. At least for VW users one now exists:
> SmallHttpUnitTest. It is available at the Cincom Public Repository.
> You can read more about it at:
>
> http://www.blainebuxton.com/projects/smallhttpunittest.htm
>
> SmallHttpUnitTest was developed at Camp Smalltalk in Portland this
> summer by Blaine Buxton & myself. The goal was to produce a compact
> language to access and test web pages. It has been used both to test
> web pages and to extract date from web pages.
>
> Below is an example SUnit test, which tests Seaside's Counter. To
> access a page one opens an HttpBrowser on a url. To access elements of
> the page one can send the tag name as a message to the browser
> object, so browser h1 below returns all the h1 elements of the page.
> One can also access page elements via tag attributes. So browser foo:
> 'bar' will return all tags with attribute foo with value bar. One can
> nest messages so "(browser p foo: 'bar') a" will return all anchor
> tags in side paragraphs that have an attibute foo with value 'bar'.
> See the above URL and the tests that come with SmallHttpUnitTest for
> more examples of usage.
>
> testNavigation
> | browser |
> browser := HttpBrowser on:
> 'http://localhost:8008/seaside/go/counter'.
> self assert: (browser h1 allSatisfy: [:each | each text = '0']).
> self assert: (browser a text includesAllOf: #('++' '--')).
>
> browser click: [:a | a text = '++'].
> self assert: (browser h1 text includesExactly: #('1')).
>
> browser click: '++'.
> self assert: (browser h1 text includesExactly: #('2')).
>
> browser click: '--'.
> self assert: (browser h1 text includesExactly: #('1')).
>
>
> ----
> Roger Whitney Department of Computer Science
> whitney at cs.sdsu.edu San Diego State University
> http://www.eli.sdsu.edu/ San Diego, CA 92182-7720
> (619) 583-1978
> (619) 594-3535 (office)
> (619) 594-6746 (fax)
>
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside
--
C. David Shaffer
http://www.cs.westminster.edu/~shaffer
http://www.shaffer-consulting.com
More information about the Seaside
mailing list