Posted by Charlie
Wed, 02 Aug 2006 06:09:00 GMT
Last month I blogged about
Selenium, which is an open source project that let's you test web applications
running in a variety of browser. Unfortunately, Selenium doesn't
work out of the box with
XHTML - any XPath expressions you use stop working.
I fixed this last
month in my local copy, but I've noticed other people are starting to have
the same issue. The problem is that Selenium does not implement a namespace
resolver as described in
the Mozilla XPath documentation. For html documents, XPath expressions look like
this:
div/p[@id="foo"]
For XHTML documents, they must include a namespace prefix like this:
x:div/x:p[@id="foo"]
The choice of "x" is random, however, its what XPath
Checker (a Firefox extension) uses.
Luckily, Selenium is easily extensible
since JavaScript is a language that gets
out of your way. The fix is to add the following code into your
user-extensions.js file:
PageBot.prototype.namespaceResolver =
function(prefix)
{
if (prefix == 'html' ||
prefix == 'xhtml' ||
prefix == 'x')
{
return 'http://www.w3.org/1999/xhtml';
}
else if (prefix == 'mathml')
{
return 'http://www.w3.org/1998/Math/MathML'
}
else
{
throw new Error("Unknown namespace: " + prefix + ".")
}
}
PageBot.prototype.findElementUsingFullXPath =
function(xpath, inDocument) {
if (browserVersion.isIE && !inDocument.evaluate) {
addXPathSupport(inDocument);
}
if (browserVersion.isIE)
xpath = xpath.replace(/x:/g,'')
if (inDocument.evaluate) {
return inDocument.evaluate(xpath,
inDocument, this.namespaceResolver, 0, null).iterateNext();
}
var context = new XPathContext();
context.expressionContextNode = inDocument;
var xpathResult = new XPathParser().parse(xpath).evaluate(context);
if (xpathResult && xpathResult.toArray) {
return xpathResult.toArray()[0];
}
return null;
};
There are two big hacks. First, the hard-coded "x" prefix. And second, Internet
Explorer does not support XHTML so the code strips out any namespace prefixes.
Last, if you are using the Firefox Selenium
IDE, make sure to point it at your updated user-extensions.js file (do
this using the options menu).
Posted in Firefox, Tools, Web | no comments | no trackbacks
Posted by Charlie
Wed, 02 Aug 2006 06:09:00 GMT
Last month I blogged about
Selenium, which is an open source project that let's you test web applications
running in a variety of browser. Unfortunately, Selenium doesn't
work out of the box with
XHTML - any XPath expressions you use stop working.
I fixed this last
month in my local copy, but I've noticed other people are starting to have
the same issue. The problem is that Selenium does not implement a namespace
resolver as described in
the Mozilla XPath documentation. For html documents, XPath expressions look like
this:
div/p[@id="foo"]
For XHTML documents, they must include a namespace prefix like this:
x:div/x:p[@id="foo"]
The choice of "x" is random, however, its what XPath
Checker (a Firefox extension) uses.
Luckily, Selenium is easily extensible
since JavaScript is a language that gets
out of your way. The fix is to add the following code into your
user-extensions.js file:
PageBot.prototype.namespaceResolver =
function(prefix)
{
if (prefix == 'html' ||
prefix == 'xhtml' ||
prefix == 'x')
{
return 'http://www.w3.org/1999/xhtml';
}
else if (prefix == 'mathml')
{
return 'http://www.w3.org/1998/Math/MathML'
}
else
{
throw new Error("Unknown namespace: " + prefix + ".")
}
}
PageBot.prototype.findElementUsingFullXPath =
function(xpath, inDocument) {
if (browserVersion.isIE && !inDocument.evaluate) {
addXPathSupport(inDocument);
}
if (browserVersion.isIE)
xpath = xpath.replace(/x:/g,'')
if (inDocument.evaluate) {
return inDocument.evaluate(xpath,
inDocument, this.namespaceResolver, 0, null).iterateNext();
}
var context = new XPathContext();
context.expressionContextNode = inDocument;
var xpathResult = new XPathParser().parse(xpath).evaluate(context);
if (xpathResult && xpathResult.toArray) {
return xpathResult.toArray()[0];
}
return null;
};
There are two big hacks. First, the hard-coded "x" prefix. And second, Internet
Explorer does not support XHTML so the code strips out any namespace prefixes.
Last, if you are using the Firefox Selenium
IDE, make sure to point it at your updated user-extensions.js file (do
this using the options menu).
Posted in Firefox, Tools, Web | no comments | no trackbacks
Posted by Charlie
Tue, 11 Jul 2006 20:26:00 GMT
There are good tools for testing most parts of web applications. At the base level, almost every language has a unit testing framework. Above that, some web frameworks, like Rails, add functional tests.
Further out, there all sorts of tools you can use to send requests to your application and analyze the results. Some are quite sophisticated, and can identify the smallest changes (just one byte for example) in your application’s responses over time. Its great for regression tests and take almost no time once you’ve set up all your tests.
And of course there are lots of performance testing frameworks that try to stress your application to see how it performs under load.
One thing that has been difficult though is testing code that runs in a browser. Since what runs in the browser _is_ the application to users, you have to get it right. Complicating the effort are the myriad of differences between browsers, not to mention the differences in a single browser running on different operating systems.
Last time I was involved with a major web application, there really weren’t any tools, either open source or commercial, to test the client. Mercury hadn’t yet launched its web testing tools, and the rest of the commercial ones were only good at sending and recieving responses to a web application.
Happily, this has changed. My favorite is Selenium, which supports all major browser. There is even a Firefox extension that helps you quickly write tests by recording what you are doing in the browser. Tests are saved as HTML tables - which sounds weird, but works quite well.
Selenium will load your tests and then run them inside a browser. Its quite entertaining watching your browser do things without you typing or clicking any buttons.
One of the nice things about Selenium is how easy it is to extend. For example, we needed to have precise control over where mouse events happened on the screen (i.e., the x and y locations). Selenium doesn’t support this, but an hour later I had hacked together everything I needed.
If your interested, I’ve submitted the code back to the selenium project. Simply download it and paste it into your user-extensions.js file and you’re ready to go.
And if you’re using Rails, check out the selenium on rails project which nicely integrates selenium into your application (it also needed a couple of patches to suport Mongrel and to record test results, I’ll submit those also).
Posted in Firefox, Web | no comments | no trackbacks
Posted by Charlie
Tue, 11 Jul 2006 20:26:00 GMT
There are good tools for testing most parts of web applications. At the base level, almost every language has a unit testing framework. Above that, some web frameworks, like Rails, add functional tests.
Further out, there all sorts of tools you can use to send requests to your application and analyze the results. Some are quite sophisticated, and can identify the smallest changes (just one byte for example) in your application’s responses over time. Its great for regression tests and take almost no time once you’ve set up all your tests.
And of course there are lots of performance testing frameworks that try to stress your application to see how it performs under load.
One thing that has been difficult though is testing code that runs in a browser. Since what runs in the browser _is_ the application to users, you have to get it right. Complicating the effort are the myriad of differences between browsers, not to mention the differences in a single browser running on different operating systems.
Last time I was involved with a major web application, there really weren’t any tools, either open source or commercial, to test the client. Mercury hadn’t yet launched its web testing tools, and the rest of the commercial ones were only good at sending and recieving responses to a web application.
Happily, this has changed. My favorite is Selenium, which supports all major browser. There is even a Firefox extension that helps you quickly write tests by recording what you are doing in the browser. Tests are saved as HTML tables - which sounds weird, but works quite well.
Selenium will load your tests and then run them inside a browser. Its quite entertaining watching your browser do things without you typing or clicking any buttons.
One of the nice things about Selenium is how easy it is to extend. For example, we needed to have precise control over where mouse events happened on the screen (i.e., the x and y locations). Selenium doesn’t support this, but an hour later I had hacked together everything I needed.
If your interested, I’ve submitted the code back to the selenium project. Simply download it and paste it into your user-extensions.js file and you’re ready to go.
And if you’re using Rails, check out the selenium on rails project which nicely integrates selenium into your application (it also needed a couple of patches to suport Mongrel and to record test results, I’ll submit those also).
Posted in Firefox, Web | no comments | no trackbacks
Posted by Charlie
Thu, 13 Apr 2006 23:17:00 GMT
I have to join the ranks of those unhappy with Firefox 1.5. I've been using Mozilla browsers forever - long, long before Firefox. I switched over to Firefox right around the time it was called Firebird.
At Smallworld/GE we put great focus on making sure our clients would run in IE 5/5.5/6.0 and Mozilla 0.8/0.9. Most people at the time thought we were nuts - why bother with a browser that no one used. But Mozilla was much more standards compliant and offered good debugging tools (Venkman). It was the right thing to do, and since I was in charge of the development group, I made sure it happened.
Fast forward four years - I was quite excited by the release of Firefox 1.5. It was great to finally see SVG make it into a mainline browser and the canvas functionality also looked intriguing.
However, when I upgraded I was met with disappointment. First, Venkman didn't work and it took a non-Mozilla employee to fix it. Talk about a marketing blunder - it sends totally the wrong message to the large numbers of developers who love to work with Mozilla/Firefox because of its openess.
And of course there is the obnoxious memory usage, which is explained away using the tried-and-trued trick of as designed. I’ve used that one once or twice before :)
I suppose you could consider the above nitpicks, but the most damming bit is that Firefox just doesn’t work well on Windows. I tend to open a large number of browser windows with a large number of embedded tabs – so at any given time I’ll have 15 or 20 pages open. This has always worked in previous versions of Firefox and Mozilla. With 1.5, within half an hour I’ll try to load a page and Firefox will spike the CPU at 100% and hang. As far as I can tell this is random, but it always happens, and some websites are worse than others. If you wait about 20 seconds, the CPU usage may drop and Firefox will once again become responsive. But every page you load after that will have the excruciating CPU spike and wait. And more often than not, Firefox will never return and the CPU usage will remain at 100%. Thus I find myself killing off Firefox with Ctrl+Alt+Del multiple times a day.
Remembering that I've used Firefox for 3 plus years now, I thought maybe the problem was caused by cruft in my profile. So I backed it up, wiped it clean, and started with a fresh slate. I even uninstalled Firefox, cleaned everything out, and reinstalled. No difference.
From talking to people, and from my observations, these problems don't seem to happen on Linux (no idea about the Mac). But that’s still no excuse for not delivering a quality product on the most widely deployed operating system.
I fear that 2.0 will be no better, since it is based on the same underlying 1.8 Gecko rendering engine. I hope I’m wrong.
Posted in Firefox | 9 comments | no trackbacks
Posted by Charlie
Thu, 13 Apr 2006 23:17:00 GMT
I have to join the ranks of those unhappy with Firefox 1.5. I've been using Mozilla browsers forever - long, long before Firefox. I switched over to Firefox right around the time it was called Firebird.
At Smallworld/GE we put great focus on making sure our clients would run in IE 5/5.5/6.0 and Mozilla 0.8/0.9. Most people at the time thought we were nuts - why bother with a browser that no one used. But Mozilla was much more standards compliant and offered good debugging tools (Venkman). It was the right thing to do, and since I was in charge of the development group, I made sure it happened.
Fast forward four years - I was quite excited by the release of Firefox 1.5. It was great to finally see SVG make it into a mainline browser and the canvas functionality also looked intriguing.
However, when I upgraded I was met with disappointment. First, Venkman didn't work and it took a non-Mozilla employee to fix it. Talk about a marketing blunder - it sends totally the wrong message to the large numbers of developers who love to work with Mozilla/Firefox because of its openess.
And of course there is the obnoxious memory usage, which is explained away using the tried-and-trued trick of as designed. I’ve used that one once or twice before :)
I suppose you could consider the above nitpicks, but the most damming bit is that Firefox just doesn’t work well on Windows. I tend to open a large number of browser windows with a large number of embedded tabs – so at any given time I’ll have 15 or 20 pages open. This has always worked in previous versions of Firefox and Mozilla. With 1.5, within half an hour I’ll try to load a page and Firefox will spike the CPU at 100% and hang. As far as I can tell this is random, but it always happens, and some websites are worse than others. If you wait about 20 seconds, the CPU usage may drop and Firefox will once again become responsive. But every page you load after that will have the excruciating CPU spike and wait. And more often than not, Firefox will never return and the CPU usage will remain at 100%. Thus I find myself killing off Firefox with Ctrl+Alt+Del multiple times a day.
Remembering that I've used Firefox for 3 plus years now, I thought maybe the problem was caused by cruft in my profile. So I backed it up, wiped it clean, and started with a fresh slate. I even uninstalled Firefox, cleaned everything out, and reinstalled. No difference.
From talking to people, and from my observations, these problems don't seem to happen on Linux (no idea about the Mac). But that’s still no excuse for not delivering a quality product on the most widely deployed operating system.
I fear that 2.0 will be no better, since it is based on the same underlying 1.8 Gecko rendering engine. I hope I’m wrong.
Posted in Firefox | 9 comments | no trackbacks
Posted by Charlie
Fri, 31 Mar 2006 20:12:00 GMT
Just noticed that
Joe Hewitt has posted an updated version of
Firebug. He's taken a great extension and turned it into the best Firefox extension by far. Its an absolutely invaluable development tool. If you develop web apps, you should go
download it now.
Posted in Firefox, Tools | no comments | no trackbacks
Posted by Charlie
Fri, 31 Mar 2006 20:12:00 GMT
Just noticed that
Joe Hewitt has posted an updated version of
Firebug. He's taken a great extension and turned it into the best Firefox extension by far. Its an absolutely invaluable development tool. If you develop web apps, you should go
download it now.
Posted in Firefox, Tools | no comments | no trackbacks