You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Simone Gianni <s....@thebug.it> on 2006/04/05 12:49:10 UTC
AJAX and web testing
Hi All,
we recently moved to ajax in our latest project. We use Selenium for web
tests. After the move we had a lot of problems with Selenium. This is
what happens :
- Selenium executes a SelectAndWait (or clickAndWait)
- It then waits for a page reload
- It detects a page reload using an onload on the test iframe.
- Obviously, ajax does not reload the page, so Selenium waits for ever.
The only relevant document i've found about this matter on the internet
(
http://www-128.ibm.com/developerworks/java/library/wa-selenium-ajax/index.html
) uses the worse solution : pauses 500 ms after a click.
We currently modified selenium to achieve a different behaviour : the
cocoon forms _handleBrowserUpdate and _continue are overridden at run
time with two custom functions that triggers Selenium page reloaded
event after a _handleBrowserUpdate unless a continue has been received.
This solution works correctly, but it's a hack. IMMO we should find a
better solution for executing webtests on a cocoon ajax enabled site ...
just some random thoughts :
- Support and document how to use Dojo AOP to wrap a method around
cocoon ajax calls (I tried this one but didn't managed to make it work).
- Provide some "classic" javascript hooks inside the cocoon ajax code,
so that implementing some jsavascript functions a web test suite can be
notified when an ajax transaction is started and ended.
- If there is a way of doing this not touching the cocoon ajax code (i
was thinking about instrumenting/intercepting the
dojo.hostenv.getXmlhttpObject()) we should document it somewhere.
I've already opened a bug for this problem on Selenium Jira, and could
probably submit a solution if we find a way to make it "dojo based" and
not that cocoon specific as the one I used.
Simone
P.S. FYI this is the code I added to selenium-browserbot.js if anybody
need it; it's an untidy solution, but works until we find a better one.
in selenium-browserbot.js, method BrowserBot.prototype.getCurrentPage =
function(), added :
if (this.frame.contentWindow.dojo) {
var contentWindow = this.frame.contentWindow;
var cocoonProto =
contentWindow..cocoon.forms.CFormsForm.prototype;
if (cocoonProto._oldHandleBrowserUpdate == undefined) {
cocoonProto._oldHandleBrowserUpdate =
cocoonProto._handleBrowserUpdate;
cocoonProto._oldContinue = cocoonProto._continue;
}
var widget =
contentWindow.dojo.widget.getWidgetById('CFormsForm_0');
if (widget != null) {
widget.bot = this;
widget._handleBrowserUpdate = function (request) {
this.bot.continued = false;
this._oldHandleBrowserUpdate(request);
this.bot._handleDojoBrowserUpdate();
}
widget._continue = function () {
this._oldContinue();
this.bot.continued = true;
}
}
}
and soon after a new function :
BrowserBot.prototype._handleDojoBrowserUpdate = function() {
if (!this.continued) this.recordPageLoad();
}
--
Simone Gianni
Re: AJAX and web testing
Posted by Sylvain Wallez <sy...@apache.org>.
Simone Gianni wrote:
> Hi All,
> we recently moved to ajax in our latest project. We use Selenium for
> web tests. After the move we had a lot of problems with Selenium. This
> is what happens :
> - Selenium executes a SelectAndWait (or clickAndWait)
> - It then waits for a page reload
> - It detects a page reload using an onload on the test iframe.
> - Obviously, ajax does not reload the page, so Selenium waits for ever.
>
> The only relevant document i've found about this matter on the
> internet (
> http://www-128.ibm.com/developerworks/java/library/wa-selenium-ajax/index.html
> ) uses the worse solution : pauses 500 ms after a click.
>
> We currently modified selenium to achieve a different behaviour : the
> cocoon forms _handleBrowserUpdate and _continue are overridden at run
> time with two custom functions that triggers Selenium page reloaded
> event after a _handleBrowserUpdate unless a continue has been received.
>
> This solution works correctly, but it's a hack. IMMO we should find a
> better solution for executing webtests on a cocoon ajax enabled site
> ... just some random thoughts :
>
> - Support and document how to use Dojo AOP to wrap a method around
> cocoon ajax calls (I tried this one but didn't managed to make it work).
> - Provide some "classic" javascript hooks inside the cocoon ajax code,
> so that implementing some jsavascript functions a web test suite can
> be notified when an ajax transaction is started and ended.
> - If there is a way of doing this not touching the cocoon ajax code (i
> was thinking about instrumenting/intercepting the
> dojo.hostenv.getXmlhttpObject()) we should document it somewhere.
>
> I've already opened a bug for this problem on Selenium Jira, and could
> probably submit a solution if we find a way to make it "dojo based"
> and not that cocoon specific as the one I used.
You can do it using Dojo's nice AOP features to intercept the method
that handles the browser update sent by Cocoon:
<script>
dojo.addOnLoad(function() {
dojo.require("cocoon.ajax.BUHandler");
dojo.event.connect(cocoon.ajax.BUHandler.prototype,
"processResponse", function() {
alert("Page has been updated!")
})
});
</script>
Sylvain
--
Sylvain Wallez
http://bluxte.net
Apache Software Foundation Member