SeasideTesting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

SeasideTesting

Liliana-2

Hi.

 

I’d like to write a test to check the content of a file I produce in my application , which is made available to the user via a download file link.

I’ve written two short classes that simulate what I want to do.

 

1.       a  WAComponent subclass: #HelloSeaside – which displays a file download anchor

renderContentOn: html

      html heading: 'Tests' level: 1.

      html break.

      html anchor

            document: 'some text that may be read from somewhere'

            mimeType: 'text/plain'

            fileName: 'myfilename.txt';

             with: 'Download file'! !

 

2.       a SCComponentTestCase subclass: #TestHelloSeaside – which attempts to follow the anchor and get to the file content; in order to test that the generated file is OK:

testDownloadFileLink

|file|

      self newApplicationWithRootClass: HelloSeaside.

      self establishSession.

      self

      followAnchor: (self lastResponse anchorWithLabel: 'Download file').

      file := self lastResponse entitiesWithClass: 'file'.

      self assert: file contents = ''! !

 

The file out is attached.

When running the test I get a SAXParseException: XML expected ‘Character expected.’ – generated by the call:

SCSeasideResponseParser parseDocumentFromResponse: response

in SCBrowserSimulator>>issueRequestUntilNotMoved: anHttpRequest.

The response is an HTTPResponse with the following properties:

-    contents = a RWBinaryOrTextStream 'some text that may be read from somewhere'

-    contentType = 'text/plain'.

 

Can somebody, please give me an idea on how to proceed from here?

Thank you

 

Liliana Ivan

[hidden email]

012 663 3140

Finworks

 


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

LiliTest.st (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SeasideTesting

cdavidshaffer
Liliana,

Sorry, right now SeasideTesting doesn't support "attachments" (documents
which the browser downloads, as opposed to displays) or any response
type which isn't Seaside-generated XHTML.  I think I can make some
changes that would give you a simple way to do this though.  If its OK,
I'll hold on to your code and include it as a test case once I've
implemented this support.  I won't be able to look at it until this
evening (EST).

In case you're interested the problem is that SeasideTesting (ST) needs
to know what document the browser is current displaying which it refers
to as the lastResponse but attachments (content-disposition:
attachment), while they are delivered via HTTP responses, aren't
typically displayed by browsers.  If I load this content into the
lastResponse then you'll have to simulate a "back" button press to get
back to the page with the anchor.  This is inconsistent with actual
browser behavior...so, what I guess I need is to properly distinguish
between the #lastResponse and the #currentPage.  Finally, I really need
to check the content-type before I go about treating it as XHML :-)

David

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: SeasideTesting

Liliana-2
In reply to this post by Liliana-2

Hi David

 

I did read your code and figured kind of what you said J but I only started working in Smalltalk three month ago and I’m still a bit scared to hack other people’s code! I would be more that happy just with a quick fix that returns the HTTPResponse as received by the browser simulator. I would then “establishSession” again if I need to do something else.

 

Thank you so much for your quick response.

Kind regards,

Liliana Ivan

[hidden email]

+(27) 12 663 3140

Finworks

 


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: SeasideTesting

Liliana-2
In reply to this post by cdavidshaffer
Hi David.

Sorry to bug you, but I was wondering if you were still doing anything about
this?
Thanks and regards,
Liliana

-----Original Message-----
From: Liliana [mailto:[hidden email]]
Sent: 21 June 2007 08:27 AM
To: '[hidden email]'
Subject: Re: [Seaside] SeasideTesting

Hi David

I did read your code and figured kind of what you said :)  but I only
started working in Smalltalk three month ago and I'm still a bit scared to
hack other people's code! I would be more that happy just with a quick fix
that returns the HTTPResponse as received by the browser simulator. I would
then "establishSession" again if I need to do something else.

Thank you so much for your quick response.
Kind regards,
Liliana

-----Original Message-----
From: David Shaffer [mailto:[hidden email]]
Sent: 20 June 2007 04:33 PM
To: Seaside - general discussion
Subject: Re: [Seaside] SeasideTesting

Liliana,

Sorry, right now SeasideTesting doesn't support "attachments" (documents
which the browser downloads, as opposed to displays) or any response
type which isn't Seaside-generated XHTML.  I think I can make some
changes that would give you a simple way to do this though.  If its OK,
I'll hold on to your code and include it as a test case once I've
implemented this support.  I won't be able to look at it until this
evening (EST).

In case you're interested the problem is that SeasideTesting (ST) needs
to know what document the browser is current displaying which it refers
to as the lastResponse but attachments (content-disposition:
attachment), while they are delivered via HTTP responses, aren't
typically displayed by browsers.  If I load this content into the
lastResponse then you'll have to simulate a "back" button press to get
back to the page with the anchor.  This is inconsistent with actual
browser behavior...so, what I guess I need is to properly distinguish
between the #lastResponse and the #currentPage.  Finally, I really need
to check the content-type before I go about treating it as XHML :-)

David

-----Original Message-----
From: Liliana [mailto:[hidden email]]
Sent: 20 June 2007 03:03 PM
To: '[hidden email]'
Subject: SeasideTesting

Hi.

I'd like to write a test to check the content of a file I produce in my
application , which is made available to the user via a download file link.
I've written two short classes that simulate what I want to do.

1. a  WAComponent subclass: #HelloSeaside - which displays a file
download anchor
renderContentOn: html
      html heading: 'Tests' level: 1.
      html break.
      html anchor
            document: 'some text that may be read from somewhere'
            mimeType: 'text/plain'
            fileName: 'myfilename.txt';
             with: 'Download file'! !

2. a SCComponentTestCase subclass: #TestHelloSeaside - which attempts
to follow the anchor and get to the file content; in order to test that the
generated file is OK:
testDownloadFileLink
|file|
      self newApplicationWithRootClass: HelloSeaside.
      self establishSession.
      self
      followAnchor: (self lastResponse anchorWithLabel: 'Download file').
      file := self lastResponse entitiesWithClass: 'file'.
      self assert: file contents = ''! !

The file out is attached.
When running the test I get a SAXParseException: XML expected 'Character
expected.' - generated by the call:
SCSeasideResponseParser parseDocumentFromResponse: response
in SCBrowserSimulator>>issueRequestUntilNotMoved: anHttpRequest.
The response is an HTTPResponse with the following properties:
- contents = a RWBinaryOrTextStream 'some text that may be read from
somewhere'
- contentType = 'text/plain'.

Can somebody, please give me an idea on how to proceed from here?
Thank you

Liliana

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: SeasideTesting

cdavidshaffer
In reply to this post by Liliana-2
Liliana wrote:

>
> Hi David
>
> I did read your code and figured kind of what you said J but I only
> started working in Smalltalk three month ago and I’m still a bit
> scared to hack other people’s code! I would be more that happy just
> with a quick fix that returns the HTTPResponse as received by the
> browser simulator. I would then “establishSession” again if I need to
> do something else.
>

Thanks for providing such a simple and useful test. I have a version
which I think will do the trick. I will publish this work on SqueakMap
as soon as I can log in. For now, please install it from SqueakSource.


MCHttpRepository
    location: 'http://www.squeaksource.com/SeasideTesting'
    user: 'cds'
    password: ''


I modified your test case and renamed it to
SCFileDownloadComponentTest...so have a look there to see how things
work. Keep in mind that if the server responds with text/html or
text/xhtml content then the parser will still try to parse it as Seaside
content. Let me know if you have any problems.

David

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: SeasideTesting

cdavidshaffer
FYI the most recent version is available on SqueakMap now as well.

David

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: SeasideTesting

Liliana-2
In reply to this post by cdavidshaffer
Hi David!

Thank you so very much. It works beautifully and for the moment we only
export csv's; so there is no danger of getting html soon (at least not for
this application!)

Cheers
Liliana

-----Original Message-----
From: David Shaffer [mailto:[hidden email]]
Sent: 25 June 2007 10:40 PM
To: Seaside - general discussion
Subject: Re: [Seaside] SeasideTesting
>>I modified your test case and renamed it to
SCFileDownloadComponentTest...so have a look there to see how things
work. Keep in mind that if the server responds with text/html or
text/xhtml content then the parser will still try to parse it as Seaside
content. Let me know if you have any problems.

David



_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside