see whatever…

jump to menu

March 15, 2006

RelaxNG Test with Selenium (a bit contrived I know ;)

Filed under: Programming,Python,RelaxNG,Web,XML — see @ 12:09 am

Maybe it is easier to validate an XML file with RelaxNG with a simple program. But as I wanted to try something with Selenium anyway (and other tests – UI tests – need Selenium) I build something a bit around.

I built a servlet which did a RelaxNG validation on a given XML file and prints out a “Validates: True” message with a log of errors and the XML source. The XML file to validate itself can be given via an URI in a request parameter so that the validation servlet would fetch the XML via HTTP itself. Selenium than could test the output of the validation servlet.

So the first step is the XML server which is just used as a kind of webservice to access files on a machine. This server is a very simple Python server based on BaseHTTPServer. Could have been (as the following one) a Java servlet but I just found this approach much easier than working around servlet limitations. I used port 8081 but that could have been any other of course.

The second step is the validation servlet which runs in a standard tomcat just because Jing is a Java lib and therefore easiest to use with Java. Actually the servlet is written in Jython but only because I am much more comfortable with Jython than with raw Java. I use the standard Tomcat 8080 port.

The third step – Selenium – actually runs in a Twisted server which enables the Selenium tests to work with any given server as no cross site scripting issues arise. The setup for this is very nicely explained in Web app testing with Python part 2: Selenium and Twisted. I used port 8082 here as Tomcat already uses 8080.

The test itself just does 2 Selenium commands:

1. open the test URL on the validation server, e.g. (not escaped)
- Twisted URL: http://localhost:8082/AUT/00000A/…
- followed by path: …/http/validationserver:8080?…
- followed by query param: …?xmlURI=http://xmlserver:8081/example.xml

2. verifyTextPresent “Validates: True”

So quite an effort just to do a XML validation but on the other hand nice to do all tests in just one tool.

Only annoying thing is that the Twisted Selenium server needs Twisted 1.3.0 and does not work with the current 2.2.0 version. Maybe that was the reason that running tests on about 300 files do fail after about 25, seems to stress Twisted (or my laptop ;) too much. I guess I am not skilled enough to bring Selenium to work on Twisted 2.2.0 but maybe I try. If anybody has a solution already, let me know

Alltogether quite fun doing admittedly a bit contrived but working setup and at least I did even some more practive setting up simple but effective servers. I find working in such a way more comfortable than writing a standalone program which in the end cannot be split into components which the described setup actually is. Fact is that I only wrote the XML server from scratch but even that is used for other stuff, so perfectly separated components but working together quite nicely…

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress