Creating an org.apache.tapestry5.dom.Document from client-side page source

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Creating an org.apache.tapestry5.dom.Document from client-side page source

Davide Vecchi
Hi everybody

I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in that test I retrieved the whole client-side page source into a String. It's a regular HTML page generated by Tapestry. Nothing special about it, it starts with

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....

and it ends with

...... </body></html>

I need to create an org.apache.tapestry5.dom.Document instance from that page source, manipulate its DOM, turn the resulting Document back into a string, and make assertions about this string.

My problem is only that I can't seem to be able to do the first step, that is create the Document instance from my String containing the page source.

I tried MarkupWriter (its write() and writeRaw() methods):

       MarkupWriter writer = new MarkupWriterImpl();

       writer.write(htmlText); // writer.writeRaw(htmlText);

       Document document = writer.getDocument();

but then document does not contain the DOM elements that were in htmlText (which is the String containing the page source), and document.getDocumentElement() returns null.

I have tried other variations still with MarkupWriter, Document and all their methods that seemed related, but I got nothing.

I'm sure I'm just missing something trivial. Does anyone know ?

If possible I'd prefer a Tapestry solution, where the created object is an org.apache.tapestry5.dom.Document, but if it's necessary to get a org.w3c.dom.Document instead, or to use something else outside Tapestry, I would still go for it.

Thanks in advance.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating an org.apache.tapestry5.dom.Document from client-side page source

Lance Java
Why on earth would you do that?

On 6 Apr 2017 16:20, "Davide Vecchi" <[hidden email]> wrote:

Hi everybody

I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in that
test I retrieved the whole client-side page source into a String. It's a
regular HTML page generated by Tapestry. Nothing special about it, it
starts with

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....

and it ends with

...... </body></html>

I need to create an org.apache.tapestry5.dom.Document instance from that
page source, manipulate its DOM, turn the resulting Document back into a
string, and make assertions about this string.

My problem is only that I can't seem to be able to do the first step, that
is create the Document instance from my String containing the page source.

I tried MarkupWriter (its write() and writeRaw() methods):

       MarkupWriter writer = new MarkupWriterImpl();

       writer.write(htmlText); // writer.writeRaw(htmlText);

       Document document = writer.getDocument();

but then document does not contain the DOM elements that were in htmlText
(which is the String containing the page source), and
document.getDocumentElement() returns null.

I have tried other variations still with MarkupWriter, Document and all
their methods that seemed related, but I got nothing.

I'm sure I'm just missing something trivial. Does anyone know ?

If possible I'd prefer a Tapestry solution, where the created object is an
org.apache.tapestry5.dom.Document, but if it's necessary to get a
org.w3c.dom.Document instead, or to use something else outside Tapestry, I
would still go for it.

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Creating an org.apache.tapestry5.dom.Document from client-side page source

Davide Vecchi
I'm not sure what exactly is so surprising, anyway if you mean why I want to test in that way, it's because the test must fail if certain texts are present anywhere in the page except for a certain div where their possible presence must be ignored. So I thought removing that div from the DOM and inspecting the rest was the easiest way (and apparently I was wrong).

If you were talking about something else just let me know.


-----Original Message-----
From: Lance Java [mailto:[hidden email]]
Sent: Thursday, April 6, 2017 17:32
To: Tapestry users <[hidden email]>
Subject: Re: Creating an org.apache.tapestry5.dom.Document from client-side page source

Why on earth would you do that?

On 6 Apr 2017 16:20, "Davide Vecchi" <[hidden email]> wrote:

Hi everybody

I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in that test I retrieved the whole client-side page source into a String. It's a regular HTML page generated by Tapestry. Nothing special about it, it starts with

<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....

and it ends with

...... </body></html>

I need to create an org.apache.tapestry5.dom.Document instance from that page source, manipulate its DOM, turn the resulting Document back into a string, and make assertions about this string.

My problem is only that I can't seem to be able to do the first step, that is create the Document instance from my String containing the page source.

I tried MarkupWriter (its write() and writeRaw() methods):

       MarkupWriter writer = new MarkupWriterImpl();

       writer.write(htmlText); // writer.writeRaw(htmlText);

       Document document = writer.getDocument();

but then document does not contain the DOM elements that were in htmlText (which is the String containing the page source), and
document.getDocumentElement() returns null.

I have tried other variations still with MarkupWriter, Document and all their methods that seemed related, but I got nothing.

I'm sure I'm just missing something trivial. Does anyone know ?

If possible I'd prefer a Tapestry solution, where the created object is an org.apache.tapestry5.dom.Document, but if it's necessary to get a org.w3c.dom.Document instead, or to use something else outside Tapestry, I would still go for it.

Thanks in advance.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating an org.apache.tapestry5.dom.Document from client-side page source

Thiago H de Paula Figueiredo
In reply to this post by Davide Vecchi
Isn't this scenario better suited for a web testing tool like Selenium or
WebDriver?

If you really, really want to parse HTML into Tapestry DOM elements, you
can use the nu.validator.htmlparser library, which parses HTML using HTML5
rules and presents itself as a SAX parser. You'll need to subclass
org.xml.sax.helpers.DefaultHandler and build the Tapestry DOM elements
inside its methods. Then you can do whatever you want with it, including
using XPath through tapestry-xpath, which I cannot recommend enough.

On Thu, Apr 6, 2017 at 12:20 PM, Davide Vecchi <[hidden email]> wrote:

> Hi everybody
>
> I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in that
> test I retrieved the whole client-side page source into a String. It's a
> regular HTML page generated by Tapestry. Nothing special about it, it
> starts with
>
> <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....
>
> and it ends with
>
> ...... </body></html>
>
> I need to create an org.apache.tapestry5.dom.Document instance from that
> page source, manipulate its DOM, turn the resulting Document back into a
> string, and make assertions about this string.
>
> My problem is only that I can't seem to be able to do the first step, that
> is create the Document instance from my String containing the page source.
>
> I tried MarkupWriter (its write() and writeRaw() methods):
>
>        MarkupWriter writer = new MarkupWriterImpl();
>
>        writer.write(htmlText); // writer.writeRaw(htmlText);
>
>        Document document = writer.getDocument();
>
> but then document does not contain the DOM elements that were in htmlText
> (which is the String containing the page source), and
> document.getDocumentElement() returns null.
>
> I have tried other variations still with MarkupWriter, Document and all
> their methods that seemed related, but I got nothing.
>
> I'm sure I'm just missing something trivial. Does anyone know ?
>
> If possible I'd prefer a Tapestry solution, where the created object is an
> org.apache.tapestry5.dom.Document, but if it's necessary to get a
> org.w3c.dom.Document instead, or to use something else outside Tapestry, I
> would still go for it.
>
> Thanks in advance.
>
>


--
Thiago
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Creating an org.apache.tapestry5.dom.Document from client-side page source

Davide Vecchi
Thanks Thiago, I will look into your suggestion, I actually think htmlparser is even already used somewhere else in the application.
I'm actually using Selenium WebDriver, and it's true, it's beautifullly suited for this.


-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:[hidden email]]
Sent: Thursday, April 6, 2017 18:09
To: Tapestry users <[hidden email]>
Subject: Re: Creating an org.apache.tapestry5.dom.Document from client-side page source

Isn't this scenario better suited for a web testing tool like Selenium or WebDriver?

If you really, really want to parse HTML into Tapestry DOM elements, you can use the nu.validator.htmlparser library, which parses HTML using HTML5 rules and presents itself as a SAX parser. You'll need to subclass org.xml.sax.helpers.DefaultHandler and build the Tapestry DOM elements inside its methods. Then you can do whatever you want with it, including using XPath through tapestry-xpath, which I cannot recommend enough.

On Thu, Apr 6, 2017 at 12:20 PM, Davide Vecchi <[hidden email]> wrote:

> Hi everybody
>
> I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in
> that test I retrieved the whole client-side page source into a String.
> It's a regular HTML page generated by Tapestry. Nothing special about
> it, it starts with
>
> <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....
>
> and it ends with
>
> ...... </body></html>
>
> I need to create an org.apache.tapestry5.dom.Document instance from
> that page source, manipulate its DOM, turn the resulting Document back
> into a string, and make assertions about this string.
>
> My problem is only that I can't seem to be able to do the first step,
> that is create the Document instance from my String containing the page source.
>
> I tried MarkupWriter (its write() and writeRaw() methods):
>
>        MarkupWriter writer = new MarkupWriterImpl();
>
>        writer.write(htmlText); // writer.writeRaw(htmlText);
>
>        Document document = writer.getDocument();
>
> but then document does not contain the DOM elements that were in
> htmlText (which is the String containing the page source), and
> document.getDocumentElement() returns null.
>
> I have tried other variations still with MarkupWriter, Document and
> all their methods that seemed related, but I got nothing.
>
> I'm sure I'm just missing something trivial. Does anyone know ?
>
> If possible I'd prefer a Tapestry solution, where the created object
> is an org.apache.tapestry5.dom.Document, but if it's necessary to get
> a org.w3c.dom.Document instead, or to use something else outside
> Tapestry, I would still go for it.
>
> Thanks in advance.
>
>


--
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Creating an org.apache.tapestry5.dom.Document from client-side page source

Lance Java
Typically you'd use the tapestry dom only in production code (pages,
components, mixins etc)

For verifying html in selenium tests you'd usually use Jsoup or geb or
something or maybe even the java xml libraries. But not the tapestry dom
libraries.


On 6 Apr 2017 17:16, "Davide Vecchi" <[hidden email]> wrote:

> Thanks Thiago, I will look into your suggestion, I actually think
> htmlparser is even already used somewhere else in the application.
> I'm actually using Selenium WebDriver, and it's true, it's beautifullly
> suited for this.
>
>
> -----Original Message-----
> From: Thiago H. de Paula Figueiredo [mailto:[hidden email]]
> Sent: Thursday, April 6, 2017 18:09
> To: Tapestry users <[hidden email]>
> Subject: Re: Creating an org.apache.tapestry5.dom.Document from
> client-side page source
>
> Isn't this scenario better suited for a web testing tool like Selenium or
> WebDriver?
>
> If you really, really want to parse HTML into Tapestry DOM elements, you
> can use the nu.validator.htmlparser library, which parses HTML using HTML5
> rules and presents itself as a SAX parser. You'll need to subclass
> org.xml.sax.helpers.DefaultHandler and build the Tapestry DOM elements
> inside its methods. Then you can do whatever you want with it, including
> using XPath through tapestry-xpath, which I cannot recommend enough.
>
> On Thu, Apr 6, 2017 at 12:20 PM, Davide Vecchi <[hidden email]> wrote:
>
> > Hi everybody
> >
> > I am writing a Selenium test to test a Tapestry 5.3.8 web app, and in
> > that test I retrieved the whole client-side page source into a String.
> > It's a regular HTML page generated by Tapestry. Nothing special about
> > it, it starts with
> >
> > <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....
> >
> > and it ends with
> >
> > ...... </body></html>
> >
> > I need to create an org.apache.tapestry5.dom.Document instance from
> > that page source, manipulate its DOM, turn the resulting Document back
> > into a string, and make assertions about this string.
> >
> > My problem is only that I can't seem to be able to do the first step,
> > that is create the Document instance from my String containing the page
> source.
> >
> > I tried MarkupWriter (its write() and writeRaw() methods):
> >
> >        MarkupWriter writer = new MarkupWriterImpl();
> >
> >        writer.write(htmlText); // writer.writeRaw(htmlText);
> >
> >        Document document = writer.getDocument();
> >
> > but then document does not contain the DOM elements that were in
> > htmlText (which is the String containing the page source), and
> > document.getDocumentElement() returns null.
> >
> > I have tried other variations still with MarkupWriter, Document and
> > all their methods that seemed related, but I got nothing.
> >
> > I'm sure I'm just missing something trivial. Does anyone know ?
> >
> > If possible I'd prefer a Tapestry solution, where the created object
> > is an org.apache.tapestry5.dom.Document, but if it's necessary to get
> > a org.w3c.dom.Document instead, or to use something else outside
> > Tapestry, I would still go for it.
> >
> > Thanks in advance.
> >
> >
>
>
> --
> Thiago
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Creating an org.apache.tapestry5.dom.Document from client-side page source

Davide Vecchi
OK, I did not know that about the Tapestry DOM libraries. That explains a few things, and it settles this, I will use something else.

Thanks for the help.


-----Original Message-----
From: Lance Java [mailto:[hidden email]]
Sent: Thursday, April 6, 2017 18:21
To: Tapestry users <[hidden email]>
Subject: RE: Creating an org.apache.tapestry5.dom.Document from client-side page source

Typically you'd use the tapestry dom only in production code (pages, components, mixins etc)

For verifying html in selenium tests you'd usually use Jsoup or geb or something or maybe even the java xml libraries. But not the tapestry dom libraries.


On 6 Apr 2017 17:16, "Davide Vecchi" <[hidden email]> wrote:

> Thanks Thiago, I will look into your suggestion, I actually think
> htmlparser is even already used somewhere else in the application.
> I'm actually using Selenium WebDriver, and it's true, it's
> beautifullly suited for this.
>
>
> -----Original Message-----
> From: Thiago H. de Paula Figueiredo [mailto:[hidden email]]
> Sent: Thursday, April 6, 2017 18:09
> To: Tapestry users <[hidden email]>
> Subject: Re: Creating an org.apache.tapestry5.dom.Document from
> client-side page source
>
> Isn't this scenario better suited for a web testing tool like Selenium
> or WebDriver?
>
> If you really, really want to parse HTML into Tapestry DOM elements,
> you can use the nu.validator.htmlparser library, which parses HTML
> using HTML5 rules and presents itself as a SAX parser. You'll need to
> subclass org.xml.sax.helpers.DefaultHandler and build the Tapestry DOM
> elements inside its methods. Then you can do whatever you want with
> it, including using XPath through tapestry-xpath, which I cannot recommend enough.
>
> On Thu, Apr 6, 2017 at 12:20 PM, Davide Vecchi <[hidden email]> wrote:
>
> > Hi everybody
> >
> > I am writing a Selenium test to test a Tapestry 5.3.8 web app, and
> > in that test I retrieved the whole client-side page source into a String.
> > It's a regular HTML page generated by Tapestry. Nothing special
> > about it, it starts with
> >
> > <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....
> >
> > and it ends with
> >
> > ...... </body></html>
> >
> > I need to create an org.apache.tapestry5.dom.Document instance from
> > that page source, manipulate its DOM, turn the resulting Document
> > back into a string, and make assertions about this string.
> >
> > My problem is only that I can't seem to be able to do the first
> > step, that is create the Document instance from my String containing
> > the page
> source.
> >
> > I tried MarkupWriter (its write() and writeRaw() methods):
> >
> >        MarkupWriter writer = new MarkupWriterImpl();
> >
> >        writer.write(htmlText); // writer.writeRaw(htmlText);
> >
> >        Document document = writer.getDocument();
> >
> > but then document does not contain the DOM elements that were in
> > htmlText (which is the String containing the page source), and
> > document.getDocumentElement() returns null.
> >
> > I have tried other variations still with MarkupWriter, Document and
> > all their methods that seemed related, but I got nothing.
> >
> > I'm sure I'm just missing something trivial. Does anyone know ?
> >
> > If possible I'd prefer a Tapestry solution, where the created object
> > is an org.apache.tapestry5.dom.Document, but if it's necessary to
> > get a org.w3c.dom.Document instead, or to use something else outside
> > Tapestry, I would still go for it.
> >
> > Thanks in advance.
> >
> >
>
>
> --
> Thiago
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Creating an org.apache.tapestry5.dom.Document from client-side page source

Lance Java
Selenium has many features for verifying values in the clientside DOM by
xpath and other selectors. Best to look at some selenium tutorials first

On 6 Apr 2017 17:26, "Davide Vecchi" <[hidden email]> wrote:

> OK, I did not know that about the Tapestry DOM libraries. That explains a
> few things, and it settles this, I will use something else.
>
> Thanks for the help.
>
>
> -----Original Message-----
> From: Lance Java [mailto:[hidden email]]
> Sent: Thursday, April 6, 2017 18:21
> To: Tapestry users <[hidden email]>
> Subject: RE: Creating an org.apache.tapestry5.dom.Document from
> client-side page source
>
> Typically you'd use the tapestry dom only in production code (pages,
> components, mixins etc)
>
> For verifying html in selenium tests you'd usually use Jsoup or geb or
> something or maybe even the java xml libraries. But not the tapestry dom
> libraries.
>
>
> On 6 Apr 2017 17:16, "Davide Vecchi" <[hidden email]> wrote:
>
> > Thanks Thiago, I will look into your suggestion, I actually think
> > htmlparser is even already used somewhere else in the application.
> > I'm actually using Selenium WebDriver, and it's true, it's
> > beautifullly suited for this.
> >
> >
> > -----Original Message-----
> > From: Thiago H. de Paula Figueiredo [mailto:[hidden email]]
> > Sent: Thursday, April 6, 2017 18:09
> > To: Tapestry users <[hidden email]>
> > Subject: Re: Creating an org.apache.tapestry5.dom.Document from
> > client-side page source
> >
> > Isn't this scenario better suited for a web testing tool like Selenium
> > or WebDriver?
> >
> > If you really, really want to parse HTML into Tapestry DOM elements,
> > you can use the nu.validator.htmlparser library, which parses HTML
> > using HTML5 rules and presents itself as a SAX parser. You'll need to
> > subclass org.xml.sax.helpers.DefaultHandler and build the Tapestry DOM
> > elements inside its methods. Then you can do whatever you want with
> > it, including using XPath through tapestry-xpath, which I cannot
> recommend enough.
> >
> > On Thu, Apr 6, 2017 at 12:20 PM, Davide Vecchi <[hidden email]> wrote:
> >
> > > Hi everybody
> > >
> > > I am writing a Selenium test to test a Tapestry 5.3.8 web app, and
> > > in that test I retrieved the whole client-side page source into a
> String.
> > > It's a regular HTML page generated by Tapestry. Nothing special
> > > about it, it starts with
> > >
> > > <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> ....
> > >
> > > and it ends with
> > >
> > > ...... </body></html>
> > >
> > > I need to create an org.apache.tapestry5.dom.Document instance from
> > > that page source, manipulate its DOM, turn the resulting Document
> > > back into a string, and make assertions about this string.
> > >
> > > My problem is only that I can't seem to be able to do the first
> > > step, that is create the Document instance from my String containing
> > > the page
> > source.
> > >
> > > I tried MarkupWriter (its write() and writeRaw() methods):
> > >
> > >        MarkupWriter writer = new MarkupWriterImpl();
> > >
> > >        writer.write(htmlText); // writer.writeRaw(htmlText);
> > >
> > >        Document document = writer.getDocument();
> > >
> > > but then document does not contain the DOM elements that were in
> > > htmlText (which is the String containing the page source), and
> > > document.getDocumentElement() returns null.
> > >
> > > I have tried other variations still with MarkupWriter, Document and
> > > all their methods that seemed related, but I got nothing.
> > >
> > > I'm sure I'm just missing something trivial. Does anyone know ?
> > >
> > > If possible I'd prefer a Tapestry solution, where the created object
> > > is an org.apache.tapestry5.dom.Document, but if it's necessary to
> > > get a org.w3c.dom.Document instead, or to use something else outside
> > > Tapestry, I would still go for it.
> > >
> > > Thanks in advance.
> > >
> > >
> >
> >
> > --
> > Thiago
> >
>
Loading...