More on web testing

I’m fairly convinced that it should be possible to set up something that “records” you testing a web page. In a world without security restrictions, it’d work. Basically, you have a bookmarklet which creates a sidebar, and then the sidebar watches what you do in the main frame and stores a script.
In a bit more detail:
The bookmarklet would be called something like “Record a macro on this page“. When you click it, it creates a link in the body of the page, which looks something like this:

<a href="" onclick="if (window.sidebar.addPanel) { window.sidebar.addPanel(this.href);" rel="sidebar" target="_search">test</a>
(The very useful sidebars in firebird, mozilla, opera and IE details at unescaped beta helped immeasurably here.) The rel="sidebar" creates a sidebar in Opera. The target="_search" creates a sidebar in IE. The JavaScript addPanel stuff creates a sidebar in Mozilla and Mozilla Firebird. Then the code clicks on the link. Pow, sidebar.
The sidebar then, when it loads, attaches a shedload of handlers to the code in the main page—an onclick to everything, onchange to form elements, all that sort of thing. So when you do anything on the page, it gets told about it. When it gets told about something, it stores that away in a script. You should then be able to save that script and replay it, and the automated system will mimic all your clicks and form typing.

Why this won’t work

Well, there are three reasons. The first is that the sidebar won’t be able to read the contents of your page, because it comes from a different domain, and the security model (which exists for good reasons) won’t let it. I think you could get around this by having the bookmarklet construct your whole sidebar page with document.write statements, but firstly this would make it a very, very complex bookmarklet indeed, and secondly there are limitations on the size of a bookmarklet, especially in IE.
The second reason is that the sidebar won’t be able to access the local filesystem to save the script, again because of the security model. You might be able to fix this with signed scripts, but then I suspect what you will get is ugly confusing security dialogs. It’s possible that pages loaded from the local filesystem can save back to it, but that doesn’t appear to always be the case—Mozilla will, I think, need chrome URLs, and that then means that the test environment has to be installed and then it’s not an easy-to-use cross-browser thing, it’s a Moz XUL application.
The third reason is that when you submit a form, or follow a link, you stop tracking what’s happening in the page. That’s silly in a test environment; you need some way of saying “this thing here on page 2, that has to be there” so that you have some conditions for knowing whether your test has passed. I can’t think of a way around this, either—there’s no way that the security model will ever let you put a page in the sidebar that can watch what’s in the main content window, since that sidebar page could then tell someone nasty on the internet what you were browsing all the time. I’ve seen proxy applications, where the proxy seamlessly inserts stuff into your page—the ones designed for web testing, though, don’t do any JavaScript stuff, so they can only test form submissions and so on. I don’t want that—I want to be able to track what a user does the whole time they’re testing, including whether any interactive stuff on the page works.
Perhaps someone has already solved this. Is there anything that is cross-browser (it’s allowed to demand a modern browser, but at a flat minimum it must work in IE and Mozilla on Windows and Linux) and lets me do this sort of testing?

I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)